@notion-headless-cms/core 0.3.7 → 0.3.9
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 -47
- package/dist/cache/memory.mjs +78 -38
- package/dist/cache/memory.mjs.map +1 -1
- package/dist/{content-WydAfQtk.d.mts → content-BIcYVt2y.d.mts} +28 -13
- package/dist/{hooks-D8Lgf-Co.d.mts → hooks-C0Pv0WYd.d.mts} +16 -8
- package/dist/hooks.d.mts +1 -1
- package/dist/hooks.mjs +18 -7
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +172 -281
- package/dist/index.mjs +340 -324
- package/dist/index.mjs.map +1 -1
- package/dist/memory-V04Q09jC.d.mts +146 -0
- package/package.json +4 -8
- package/dist/cache/noop.d.mts +0 -11
- package/dist/cache/noop.mjs +0 -44
- package/dist/cache/noop.mjs.map +0 -1
- package/dist/cache-D051BP4G.d.mts +0 -148
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { a 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-BIcYVt2y.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-V04Q09jC.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-C0Pv0WYd.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,106 +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
|
-
* `getList` の戻り値。アイテム配列とバージョン文字列を含む。
|
|
41
|
-
* version は DataSource.getListVersion() が生成するフィルタ済みアイテムの識別子。
|
|
42
|
-
*/
|
|
43
|
-
interface GetListResult<T extends BaseContentItem = BaseContentItem> {
|
|
44
|
-
items: T[];
|
|
45
|
-
/** フィルタ適用後のアイテム群を識別するバージョン文字列。 */
|
|
46
|
-
version: string;
|
|
33
|
+
/** `get()` のオプション。 */
|
|
34
|
+
interface GetOptions {
|
|
35
|
+
/** true なら TTL に関わらずブロッキングで再取得し、本文 cache を破棄する。 */
|
|
36
|
+
fresh?: boolean;
|
|
47
37
|
}
|
|
48
38
|
/**
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
39
|
+
* `get()` の戻り値。アイテム本体に `render()` が生える。
|
|
40
|
+
* `render()` を呼んだ時点で初めて本文をロードする lazy 設計。
|
|
51
41
|
*/
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* changed: true の場合は最新のアイテム配列とバージョンを含む。
|
|
61
|
-
*/
|
|
62
|
-
type CheckListForUpdateResult<T extends BaseContentItem = BaseContentItem> = {
|
|
63
|
-
changed: false;
|
|
64
|
-
} | {
|
|
65
|
-
changed: true;
|
|
66
|
-
items: T[];
|
|
67
|
-
version: string;
|
|
42
|
+
type ItemWithRender<T extends BaseContentItem> = T & {
|
|
43
|
+
/**
|
|
44
|
+
* 本文を文字列で返す。デフォルトは HTML。
|
|
45
|
+
* `format: "markdown"` で Markdown を返す。
|
|
46
|
+
*/
|
|
47
|
+
render(opts?: {
|
|
48
|
+
format?: "html" | "markdown";
|
|
49
|
+
}): Promise<string>;
|
|
68
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> {
|
|
60
|
+
/**
|
|
61
|
+
* 指定 slug、または slug 省略時はコレクション全体のキャッシュを失効させる。
|
|
62
|
+
* 次回 `get` / `list` で source から再取得される。
|
|
63
|
+
*/
|
|
64
|
+
invalidate(slug?: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* 全アイテムを並列に事前取得・レンダリングしてキャッシュに格納する。
|
|
67
|
+
* SSG ビルド前のウォームアップに利用する。
|
|
68
|
+
*/
|
|
69
|
+
warm(opts?: WarmOptions): Promise<{
|
|
70
|
+
ok: number;
|
|
71
|
+
failed: number;
|
|
72
|
+
}>;
|
|
73
|
+
/** 前後アイテムのナビゲーション (リスト順序ベース)。 */
|
|
74
|
+
adjacent(slug: string, opts?: AdjacencyOptions<T>): Promise<{
|
|
75
|
+
prev: T | null;
|
|
76
|
+
next: T | null;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
69
79
|
/**
|
|
70
80
|
* コレクション別の CMS クライアント。
|
|
71
|
-
* `cms.posts.
|
|
81
|
+
* `cms.posts.get(slug)` / `cms.posts.list()` のようにアクセスする。
|
|
72
82
|
*/
|
|
73
83
|
interface CollectionClient<T extends BaseContentItem = BaseContentItem> {
|
|
74
84
|
/**
|
|
75
|
-
*
|
|
85
|
+
* スラッグで単件取得。アイテム本体に `render()` が生える。
|
|
76
86
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* TTL 未設定の場合はキャッシュを即時返却しバックグラウンドで差分チェックする。
|
|
80
|
-
* 明示的に同期リフレッシュしたい場合は {@link revalidate} を先に呼ぶ。
|
|
87
|
+
* SWR: TTL 未設定 or 期限内ならキャッシュ即時返却 + バックグラウンド差分チェック。
|
|
88
|
+
* TTL 期限切れ、または `opts.fresh === true` でブロッキング取得。
|
|
81
89
|
*
|
|
82
|
-
* @returns キャッシュまたは
|
|
90
|
+
* @returns キャッシュまたは source から取得したアイテム。存在しない場合は null。
|
|
83
91
|
*/
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
/** Next App Router の `generateStaticParams`
|
|
88
|
-
|
|
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<{
|
|
89
97
|
slug: string;
|
|
90
98
|
}[]>;
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
/** 前後記事のナビゲーション。 */
|
|
94
|
-
adjacent(slug: string, opts?: AdjacencyOptions<T>): Promise<{
|
|
95
|
-
prev: T | null;
|
|
96
|
-
next: T | null;
|
|
97
|
-
}>;
|
|
98
|
-
/**
|
|
99
|
-
* 指定スラッグのアイテムキャッシュを無効化する。
|
|
100
|
-
* 次回の getItem 呼び出しで Notion から再取得される。
|
|
101
|
-
*/
|
|
102
|
-
revalidate(slug: string): Promise<void>;
|
|
103
|
-
/** コレクション全体のキャッシュを無効化する。 */
|
|
104
|
-
revalidateAll(): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* 指定アイテムが since 以降に更新されたか確認する。
|
|
107
|
-
* 内部で revalidate → getItem を実行し updatedAt を比較する。
|
|
108
|
-
* 更新があった場合は最新の ItemWithContent を返す。
|
|
109
|
-
*/
|
|
110
|
-
checkForUpdate(args: {
|
|
111
|
-
slug: string;
|
|
112
|
-
since: string;
|
|
113
|
-
}): Promise<CheckForUpdateResult<T>>;
|
|
114
|
-
/**
|
|
115
|
-
* リスト全体が since 以降に更新されたか確認する。
|
|
116
|
-
* 内部で revalidateAll → getList を実行しバージョンを比較する。
|
|
117
|
-
* 更新があった場合は最新の items と version を返す。
|
|
118
|
-
*/
|
|
119
|
-
checkListForUpdate(args: {
|
|
120
|
-
since: string;
|
|
121
|
-
filter?: GetListOptions<T>;
|
|
122
|
-
}): Promise<CheckListForUpdateResult<T>>;
|
|
123
|
-
/** 全コンテンツをプリフェッチしてキャッシュに保存。 */
|
|
124
|
-
prefetch(opts?: {
|
|
125
|
-
concurrency?: number;
|
|
126
|
-
onProgress?: (done: number, total: number) => void;
|
|
127
|
-
}): Promise<{
|
|
128
|
-
ok: number;
|
|
129
|
-
failed: number;
|
|
130
|
-
}>;
|
|
99
|
+
/** キャッシュ操作 namespace。 */
|
|
100
|
+
cache: CollectionCacheOps<T>;
|
|
131
101
|
}
|
|
132
102
|
//#endregion
|
|
133
103
|
//#region src/types/config.d.ts
|
|
@@ -170,83 +140,67 @@ interface RateLimiterConfig {
|
|
|
170
140
|
/** リトライ時の基準待機時間(ミリ秒)。デフォルト: 1000 */
|
|
171
141
|
baseDelayMs?: number;
|
|
172
142
|
}
|
|
173
|
-
/** `createCMS({ dataSources })` の map 型。 */
|
|
174
|
-
type DataSourceMap = Record<string, DataSource<any>>;
|
|
175
143
|
/**
|
|
176
|
-
*
|
|
177
|
-
* `createCMS({ collections: { posts: { ... } } })` に渡す。
|
|
144
|
+
* コレクション 1 件の定義。CLI が生成する `nhc.ts` から `createCMS` に渡される。
|
|
178
145
|
*
|
|
179
|
-
* `
|
|
180
|
-
* `
|
|
181
|
-
* `CMSHooks<Post>` などを直接記述する必要がなくなる。
|
|
146
|
+
* `source` は notion-orm 等の DataSource 実装。
|
|
147
|
+
* `slugField` / `statusField` は TS フィールド名 (DataSource の `properties` キーと一致)。
|
|
182
148
|
*/
|
|
183
|
-
interface
|
|
184
|
-
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 公開扱いするステータス値。DataSource 側の `publishedStatuses` より優先される。
|
|
193
|
-
* 例: ["公開済み", "Published"]
|
|
194
|
-
*/
|
|
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()` のデフォルト絞り込みに使う。 */
|
|
195
157
|
publishedStatuses?: readonly string[];
|
|
196
|
-
/**
|
|
197
|
-
* アクセス許可するステータス値。DataSource 側の `accessibleStatuses` より優先される。
|
|
198
|
-
*/
|
|
158
|
+
/** アクセス許可するステータス値。`get()` の閲覧可否判定に使う。 */
|
|
199
159
|
accessibleStatuses?: readonly string[];
|
|
200
|
-
/**
|
|
201
|
-
* コレクション固有のライフサイクルフック。
|
|
202
|
-
* トップレベルの `hooks` と合成して実行される(グローバルフック → コレクションフックの順)。
|
|
203
|
-
* `T` が確定しているため `item.item.myField` など独自フィールドに型安全にアクセスできる。
|
|
204
|
-
*/
|
|
160
|
+
/** コレクション固有のライフサイクルフック。グローバル hooks の後に実行される。 */
|
|
205
161
|
hooks?: CMSHooks<T>;
|
|
206
162
|
}
|
|
207
|
-
/** `DataSourceMap` から各 T を抽出するユーティリティ型。 */
|
|
208
|
-
type InferDataSourceItem<D> = D extends DataSource<infer T> ? T : BaseContentItem;
|
|
209
163
|
/**
|
|
210
|
-
* `createCMS()`
|
|
211
|
-
*
|
|
164
|
+
* `createCMS({ collections })` の map 型。
|
|
165
|
+
* キーがコレクション名、値が `CollectionDef<T>`。
|
|
212
166
|
*/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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;
|
|
235
190
|
/**
|
|
236
|
-
*
|
|
237
|
-
* `
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* const cms = createCMS({ dataSources, preset: "node", ttlMs: 5 * 60_000 });
|
|
191
|
+
* キャッシュアダプタ (単体または配列)。未指定時はキャッシュなし。
|
|
192
|
+
* - `memoryCache()` のように doc + image 両方を担当するもの
|
|
193
|
+
* - `r2Cache()` (image のみ)、`kvCache()` (doc のみ) のように片側のみ担当するもの
|
|
194
|
+
* - 配列で組み合わせると、各 adapter の `handles` で振り分けられる
|
|
241
195
|
*/
|
|
196
|
+
cache?: CacheAdapter | readonly CacheAdapter[];
|
|
197
|
+
/** SWR の有効期間 (ミリ秒)。未設定時は TTL なし (失効まで stale を返す)。 */
|
|
242
198
|
ttlMs?: number;
|
|
243
|
-
/**
|
|
199
|
+
/** カスタムレンダラー。未指定時は `@notion-headless-cms/renderer` の `renderMarkdown` を動的 import。 */
|
|
244
200
|
renderer?: RendererFn;
|
|
245
|
-
/**
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
content?: ContentConfig;
|
|
249
|
-
/** Cloudflare Workers の waitUntil に相当する非同期処理の登録関数。 */
|
|
201
|
+
/** 画像プロキシのベース URL。デフォルト `/api/images`。 */
|
|
202
|
+
imageProxyBase?: string;
|
|
203
|
+
/** Cloudflare Workers の `waitUntil` に相当する非同期処理の登録関数。 */
|
|
250
204
|
waitUntil?: (p: Promise<unknown>) => void;
|
|
251
205
|
/** ライフサイクルフック (全コレクション共通)。 */
|
|
252
206
|
hooks?: CMSHooks<any>;
|
|
@@ -254,43 +208,12 @@ interface CreateCMSOptions<D extends DataSourceMap = DataSourceMap> {
|
|
|
254
208
|
plugins?: CMSPlugin<any>[];
|
|
255
209
|
/** ロガー。 */
|
|
256
210
|
logger?: Logger;
|
|
257
|
-
/**
|
|
258
|
-
* ログレベルの下限。指定したレベル未満のログを内部で抑制する。
|
|
259
|
-
* Cloudflare Workers の Observability のように debug ログが課金対象になる環境では
|
|
260
|
-
* `"info"` を指定すると debug ログを出力しなくなる。
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* createCMS({ ..., logLevel: "info" }) // debug ログを抑制
|
|
264
|
-
*/
|
|
211
|
+
/** ログレベルの下限。指定したレベル未満のログを内部で抑制する。 */
|
|
265
212
|
logLevel?: LogLevel;
|
|
266
213
|
/** レートリミット・リトライ設定。 */
|
|
267
214
|
rateLimiter?: RateLimiterConfig;
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
* slug・status・公開条件・コレクション固有フックを指定する。
|
|
271
|
-
* 指定したコレクションでは `slug` が必須(未指定時はエラー)。
|
|
272
|
-
* 指定したコレクションの `publishedStatuses`/`accessibleStatuses` は
|
|
273
|
-
* DataSource 側の設定より優先される。
|
|
274
|
-
*
|
|
275
|
-
* `hooks` にコレクション固有フックを定義すると、`dataSources` の型から `T` が
|
|
276
|
-
* 自動推論されるため `CMSHooks<Post>` などを直接書かずに済む。
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* createCMS({
|
|
280
|
-
* dataSources: { posts: createNotionCollection<Post>({ ... }) },
|
|
281
|
-
* collections: {
|
|
282
|
-
* posts: {
|
|
283
|
-
* slug: "slug",
|
|
284
|
-
* status: "status",
|
|
285
|
-
* publishedStatuses: ["公開済み"],
|
|
286
|
-
* hooks: {
|
|
287
|
-
* onCacheHit: (slug, item) => console.log(item.item.title),
|
|
288
|
-
* },
|
|
289
|
-
* }
|
|
290
|
-
* }
|
|
291
|
-
* })
|
|
292
|
-
*/
|
|
293
|
-
collections?: { [K in keyof D]?: CollectionSemantics<InferDataSourceItem<D[K]>> };
|
|
215
|
+
/** レンダリング・コンテンツ処理設定。 */
|
|
216
|
+
content?: ContentConfig;
|
|
294
217
|
}
|
|
295
218
|
//#endregion
|
|
296
219
|
//#region src/cache.d.ts
|
|
@@ -302,6 +225,14 @@ declare function sha256Hex(input: string): Promise<string>;
|
|
|
302
225
|
*/
|
|
303
226
|
declare function isStale(cachedAt: number, ttlMs?: number): boolean;
|
|
304
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
|
|
305
236
|
//#region src/handler.d.ts
|
|
306
237
|
/** `$handler()` の挙動設定。 */
|
|
307
238
|
interface HandlerOptions {
|
|
@@ -318,7 +249,7 @@ interface HandlerOptions {
|
|
|
318
249
|
}
|
|
319
250
|
/** `$handler()` が内部で依存する CMS 機能の最小セット。 */
|
|
320
251
|
interface HandlerAdapter {
|
|
321
|
-
imageCache:
|
|
252
|
+
imageCache: ImageCacheOps;
|
|
322
253
|
/** コレクション名で DataSource を取り出し parseWebhook にフォワードする。 */
|
|
323
254
|
parseWebhook(req: Request, webhookSecret: string | undefined): Promise<InvalidateScope | null>;
|
|
324
255
|
revalidate(scope: InvalidateScope): Promise<void>;
|
|
@@ -334,45 +265,47 @@ interface HandlerAdapter {
|
|
|
334
265
|
declare function createHandler(adapter: HandlerAdapter, opts?: HandlerOptions): (req: Request) => Promise<Response>;
|
|
335
266
|
//#endregion
|
|
336
267
|
//#region src/cms.d.ts
|
|
337
|
-
/** `CMSClient<
|
|
338
|
-
type CMSClient<
|
|
268
|
+
/** `CMSClient<C>` — コレクション別アクセス + グローバル操作の合成型。 */
|
|
269
|
+
type CMSClient<C extends CollectionsConfig> = { [K in keyof C]: CollectionClient<InferCollectionItem<C[K]>> } & CMSGlobalOps;
|
|
339
270
|
/** `CMSClient` のグローバル名前空間。`$` プレフィックス。 */
|
|
340
|
-
interface CMSGlobalOps
|
|
271
|
+
interface CMSGlobalOps {
|
|
341
272
|
/** 登録されているコレクション名の一覧。 */
|
|
342
|
-
readonly $collections: readonly
|
|
343
|
-
/**
|
|
344
|
-
$
|
|
273
|
+
readonly $collections: readonly string[];
|
|
274
|
+
/** 全コレクションまたは特定スコープのキャッシュを無効化する。 */
|
|
275
|
+
$invalidate(scope?: InvalidateScope): Promise<void>;
|
|
345
276
|
/** Web Standard なルーティングハンドラ (画像プロキシ / webhook) を生成する。 */
|
|
346
277
|
$handler(opts?: HandlerOptions): (req: Request) => Promise<Response>;
|
|
347
278
|
/** ハッシュキーでキャッシュ画像を取得する。 */
|
|
348
|
-
$getCachedImage(hash: string):
|
|
279
|
+
$getCachedImage(hash: string): Promise<StorageBinary | null>;
|
|
349
280
|
}
|
|
350
281
|
/**
|
|
351
|
-
* 複数の
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* // Node.js(preset を使った簡潔な記法)
|
|
355
|
-
* const cms = createCMS({ dataSources: cmsDataSources, preset: "node", ttlMs: 5 * 60_000 });
|
|
282
|
+
* 複数の `CollectionDef` を束ねた CMS クライアントを生成する。
|
|
356
283
|
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources: cmsDataSources });
|
|
284
|
+
* 通常はユーザーが直接呼ぶことはなく、CLI 生成の `nhc.ts` の `createCMS`
|
|
285
|
+
* (低レベルのこの関数をラップしたもの) を経由する。
|
|
360
286
|
*
|
|
361
287
|
* @example
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
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 }),
|
|
366
298
|
* });
|
|
367
299
|
*/
|
|
368
|
-
declare function createCMS<
|
|
300
|
+
declare function createCMS<C extends CollectionsConfig>(opts: CreateCMSOptions<C>): CMSClient<C>;
|
|
369
301
|
//#endregion
|
|
370
302
|
//#region src/rendering.d.ts
|
|
371
|
-
/**
|
|
303
|
+
/** 本文レンダリングに必要な依存を束ねたコンテキスト。 */
|
|
372
304
|
interface RenderContext<T extends BaseContentItem> {
|
|
373
305
|
source: DataSource<T>;
|
|
374
306
|
rendererFn: RendererFn | undefined;
|
|
375
|
-
imgCache:
|
|
307
|
+
imgCache: ImageCacheOps;
|
|
308
|
+
imgCacheName: string;
|
|
376
309
|
hasImageCache: boolean;
|
|
377
310
|
imageProxyBase: string;
|
|
378
311
|
contentConfig: ContentConfig | undefined;
|
|
@@ -404,13 +337,17 @@ declare function withRetry<T>(fn: () => Promise<T>, config: RetryConfig): Promis
|
|
|
404
337
|
/**
|
|
405
338
|
* コレクション別キャッシュキーを生成する。
|
|
406
339
|
* item: `{collection}:{slug}` / list: `{collection}`
|
|
340
|
+
*
|
|
341
|
+
* (Cache adapter 内部のキー戦略はアダプタごとに異なるが、
|
|
342
|
+
* 表示や再計算用に core 側でも公開ヘルパーを提供する)
|
|
407
343
|
*/
|
|
408
344
|
declare function collectionKey(collection: string, slug?: string): string;
|
|
409
345
|
/** 単一コレクションの DataSource + SWR キャッシュ依存を束ねたコンテキスト。 */
|
|
410
346
|
interface CollectionContext<T extends BaseContentItem> {
|
|
411
347
|
collection: string;
|
|
412
348
|
source: DataSource<T>;
|
|
413
|
-
docCache:
|
|
349
|
+
docCache: DocumentCacheOps;
|
|
350
|
+
docCacheName: string;
|
|
414
351
|
render: RenderContext<T>;
|
|
415
352
|
hooks: CMSHooks<T>;
|
|
416
353
|
logger: Logger | undefined;
|
|
@@ -421,51 +358,35 @@ interface CollectionContext<T extends BaseContentItem> {
|
|
|
421
358
|
maxConcurrent: number;
|
|
422
359
|
waitUntil: ((p: Promise<unknown>) => void) | undefined;
|
|
423
360
|
/**
|
|
424
|
-
* slug
|
|
425
|
-
* `
|
|
426
|
-
* 設定時は `source.properties[slugField].notion` を Notion プロパティ名として
|
|
361
|
+
* slug として使うフィールド名 (CLI 生成の `CollectionDef.slugField`)。
|
|
362
|
+
* `source.properties[slugField].notion` を Notion プロパティ名として
|
|
427
363
|
* `findByProp` を呼び出す。
|
|
428
364
|
*/
|
|
429
|
-
slugField
|
|
365
|
+
slugField: string;
|
|
430
366
|
}
|
|
431
367
|
/** CollectionClient の実装。ユーザーは `createCMS` 経由でインスタンスを受け取る。 */
|
|
432
368
|
declare class CollectionClientImpl<T extends BaseContentItem> implements CollectionClient<T> {
|
|
433
369
|
private readonly ctx;
|
|
370
|
+
readonly cache: CollectionCacheOps<T>;
|
|
434
371
|
constructor(ctx: CollectionContext<T>);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
372
|
+
get(slug: string, opts?: GetOptions): Promise<ItemWithRender<T> | null>;
|
|
373
|
+
list(opts?: ListOptions<T>): Promise<T[]>;
|
|
374
|
+
params(): Promise<{
|
|
438
375
|
slug: string;
|
|
439
376
|
}[]>;
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}): Promise<CheckForUpdateResult<T>>;
|
|
454
|
-
checkListForUpdate({
|
|
455
|
-
since,
|
|
456
|
-
filter
|
|
457
|
-
}: {
|
|
458
|
-
since: string;
|
|
459
|
-
filter?: GetListOptions<T>;
|
|
460
|
-
}): Promise<CheckListForUpdateResult<T>>;
|
|
461
|
-
prefetch(opts?: {
|
|
462
|
-
concurrency?: number;
|
|
463
|
-
onProgress?: (done: number, total: number) => void;
|
|
464
|
-
}): Promise<{
|
|
465
|
-
ok: number;
|
|
466
|
-
failed: number;
|
|
467
|
-
}>;
|
|
468
|
-
private attachContent;
|
|
377
|
+
private invalidateImpl;
|
|
378
|
+
private warmImpl;
|
|
379
|
+
private adjacentImpl;
|
|
380
|
+
private persistMeta;
|
|
381
|
+
private invalidateContent;
|
|
382
|
+
/**
|
|
383
|
+
* 本文キャッシュをロードする。キャッシュが無いか、メタとの整合性が取れない場合は
|
|
384
|
+
* 再生成して書き戻す。
|
|
385
|
+
*/
|
|
386
|
+
private loadOrBuildContent;
|
|
387
|
+
/** メタ既知の状態で本文だけバックグラウンド再生成する。エラーは握りつぶす。 */
|
|
388
|
+
private rebuildContentBg;
|
|
389
|
+
private attachLazyContent;
|
|
469
390
|
private fetchList;
|
|
470
391
|
private checkAndUpdateItemBg;
|
|
471
392
|
private checkAndUpdateListBg;
|
|
@@ -473,35 +394,5 @@ declare class CollectionClientImpl<T extends BaseContentItem> implements Collect
|
|
|
473
394
|
private findRaw;
|
|
474
395
|
}
|
|
475
396
|
//#endregion
|
|
476
|
-
|
|
477
|
-
/** `nodePreset()` のオプション。 */
|
|
478
|
-
interface NodePresetOptions {
|
|
479
|
-
/**
|
|
480
|
-
* キャッシュ設定。
|
|
481
|
-
* - 省略時: memoryDocumentCache + memoryImageCache をデフォルト有効化
|
|
482
|
-
* - `"disabled"`: キャッシュを完全無効化
|
|
483
|
-
* - オブジェクト: 任意の cache adapter を差し込む
|
|
484
|
-
*/
|
|
485
|
-
cache?: CacheConfig | "disabled";
|
|
486
|
-
/** SWR の TTL (ミリ秒)。`cache` をオブジェクトで渡した場合はそちらが優先される。 */
|
|
487
|
-
ttlMs?: number;
|
|
488
|
-
/** カスタムレンダラー。未指定時は core が @notion-headless-cms/renderer を動的ロード。 */
|
|
489
|
-
renderer?: RendererFn;
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Node.js ランタイム向けの `createCMS` オプションプリセット。
|
|
493
|
-
* メモリキャッシュをデフォルト有効にした `{ cache, renderer }` を返す。
|
|
494
|
-
*
|
|
495
|
-
* @example
|
|
496
|
-
* import { createCMS, nodePreset } from "@notion-headless-cms/core";
|
|
497
|
-
* import { cmsDataSources } from "./generated/cms-schema";
|
|
498
|
-
*
|
|
499
|
-
* const cms = createCMS({
|
|
500
|
-
* ...nodePreset({ ttlMs: 5 * 60_000 }),
|
|
501
|
-
* dataSources: cmsDataSources,
|
|
502
|
-
* });
|
|
503
|
-
*/
|
|
504
|
-
declare function nodePreset(opts?: NodePresetOptions): Pick<CreateCMSOptions, "cache" | "renderer">;
|
|
505
|
-
//#endregion
|
|
506
|
-
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 CachedItem, type CachedItemList, 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 InvalidateScope, 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 };
|
|
507
398
|
//# sourceMappingURL=index.d.mts.map
|