@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.
@@ -1,170 +0,0 @@
1
- import { a as CachedItemMeta, c as ContentBlock, i as CachedItemList, r as CachedItemContent, s as StorageBinary, t as BaseContentItem, u as ImageRef } from "./content-DyrOwjbA.mjs";
2
-
3
- //#region src/types/data-source.d.ts
4
- /**
5
- * Notion プロパティ1件の型情報とプロパティ名を保持する。
6
- * CLI が生成する `*Properties` オブジェクトの各要素の型。
7
- */
8
- interface PropertyDef {
9
- type: "title" | "richText" | "select" | "multiSelect" | "date" | "number" | "checkbox" | "url";
10
- /** Notion DB 上のプロパティ名(表示名)。 */
11
- notion: string;
12
- }
13
- /** Notion DB のプロパティ一覧マップ。CLI 生成の `*Properties` の型。 */
14
- type PropertyMap = Record<string, PropertyDef>;
15
- /**
16
- * 無効化対象の粒度。
17
- * - "meta" — メタデータキャッシュのみ失効
18
- * - "content" — 本文キャッシュのみ失効(リスト次回読み出しで lazy 再生成)
19
- * - "all" — 両方(既定)
20
- */
21
- type InvalidateKind = "meta" | "content" | "all";
22
- /**
23
- * キャッシュ無効化のスコープ (DataSource 層で参照する形)。
24
- * `kind` を省略した場合は `"all"` 相当として扱う。
25
- */
26
- type InvalidateScope = "all" | {
27
- collection: string;
28
- kind?: InvalidateKind;
29
- } | {
30
- collection: string;
31
- slug: string;
32
- kind?: InvalidateKind;
33
- };
34
- /**
35
- * Webhook 受信時の検証設定。
36
- */
37
- interface WebhookConfig {
38
- /** 署名検証用シークレット。 */
39
- secret?: string;
40
- }
41
- /**
42
- * コンテンツソースを抽象化する v1 インターフェース。
43
- *
44
- * ユーザーは直接実装しない。`notion-orm` 等の ORM パッケージが実装する。
45
- * core は Notion 固有の知識を持たず、このインターフェース経由でのみデータを扱う。
46
- * 将来 `googledocs-orm` 等の別ソースもこの I/F を満たせば差し替え可能。
47
- */
48
- interface DataSource<T extends BaseContentItem = BaseContentItem> {
49
- /** ソース識別子 (ロギング・デバッグ用)。 */
50
- readonly name: string;
51
- /**
52
- * CLI 生成の `*Properties` に対応するプロパティマップ。
53
- * `properties` オプション経由で生成された DataSource のみ設定される。
54
- * Core が `findByProp` の Notion プロパティ名解決に使用する。
55
- */
56
- readonly properties?: PropertyMap;
57
- /** 公開済みアイテム一覧を取得する。 */
58
- list(opts?: {
59
- publishedStatuses?: readonly string[];
60
- }): Promise<T[]>;
61
- /**
62
- * 指定した Notion プロパティ名と値で1件検索する。
63
- * Core が slug フィールドのルックアップに使用する。
64
- * `properties` オプション経由で生成された DataSource が実装する。
65
- */
66
- findByProp?(notionPropName: string, value: string): Promise<T | null>;
67
- /** アイテム本文を ContentBlock 配列で返す。 */
68
- loadBlocks(item: T): Promise<ContentBlock[]>;
69
- /** アイテム本文を Markdown 文字列で返す (html() 生成の元ソース)。 */
70
- loadMarkdown(item: T): Promise<string>;
71
- /** SWR 鮮度判定用。item の最終更新タイムスタンプ。 */
72
- getLastModified(item: T): string;
73
- /** リスト全体のバージョン文字列 (例: 最新 last_edited_time)。 */
74
- getListVersion(items: T[]): string;
75
- /** 期限切れ画像 URL の再取得 (Notion の署名 URL 対応)。 */
76
- resolveImageUrl?(ref: ImageRef): Promise<string>;
77
- /**
78
- * Webhook リクエストをパースして無効化スコープを返す。
79
- * 実装していない場合は `$handler` が body の `{ slug }` にフォールバック。
80
- */
81
- parseWebhook?(req: Request, config: WebhookConfig): Promise<InvalidateScope>;
82
- }
83
- /**
84
- * `nhcSchema` の各コレクション設定エントリ。
85
- * ユーザーは CLI 生成の `nhcSchema` を渡すだけで、
86
- * この型は `createCMS` 内部で DataSource のファクトリに渡される。
87
- */
88
- interface CollectionConfig<T extends BaseContentItem = BaseContentItem> {
89
- /** Notion データソース (database) ID。 */
90
- databaseId: string;
91
- /** スキーマ情報 (ORM が解釈する不透明データ)。 */
92
- schema?: any;
93
- /** 公開扱いするステータス値。 */
94
- publishedStatuses?: string[];
95
- /** アクセス許可するステータス値。 */
96
- accessibleStatuses?: string[];
97
- /** `T` を型レベルで持ち回るためのマーカー (ランタイム値なし)。 */
98
- __itemType?: T;
99
- }
100
- /**
101
- * `nhc generate` が生成する `nhcSchema` の型。
102
- * コレクション名をキーとして、各コレクションの設定を保持する。
103
- */
104
- type CMSSchema = Record<string, CollectionConfig<any>>;
105
- /** `CollectionConfig<T>` から `T` を抽出するユーティリティ型。 */
106
- type InferCollectionItem<C> = C extends CollectionConfig<infer T> ? T : BaseContentItem;
107
- /**
108
- * DataSource を生成するファクトリ関数の型。
109
- * `createCMS` はコレクション名 → この関数 → DataSource の経路で組み立てる。
110
- *
111
- * ユーザーコードは直接呼ばない。`@notion-headless-cms/notion-orm` 等の
112
- * ORM パッケージが provide する。ORM 固有のオプション (Notion なら
113
- * `{ token }`、Google Docs なら `{ credentials }` 等) は `TOptions` の
114
- * generic で受け取る。
115
- *
116
- * @example
117
- * // notion-orm が DataSourceFactory<{ token: string }> として実装する
118
- * const factory: DataSourceFactory<{ token: string }> = ({ collection, config, options }) =>
119
- * createNotionCollection({
120
- * token: options.token,
121
- * dataSourceId: config.databaseId,
122
- * schema: config.schema,
123
- * });
124
- */
125
- type DataSourceFactory<TOptions = unknown> = <T extends BaseContentItem>(args: {
126
- collection: string;
127
- config: CollectionConfig<T>;
128
- options: TOptions;
129
- }) => DataSource<T>;
130
- //#endregion
131
- //#region src/types/cache.d.ts
132
- /**
133
- * ドキュメントキャッシュを抽象化するインターフェース。
134
- *
135
- * v0.4.0 で `getItem`/`setItem` を `getItemMeta`/`setItemMeta` +
136
- * `getItemContent`/`setItemContent` に分割した。
137
- * メタデータのみ取り出す軽量パスと、本文を遅延ロードするパスを分離するため。
138
- */
139
- interface DocumentCacheAdapter<T extends BaseContentItem = BaseContentItem> {
140
- readonly name: string;
141
- getList(): Promise<CachedItemList<T> | null>;
142
- setList(data: CachedItemList<T>): Promise<void>;
143
- getItemMeta(slug: string): Promise<CachedItemMeta<T> | null>;
144
- setItemMeta(slug: string, data: CachedItemMeta<T>): Promise<void>;
145
- getItemContent(slug: string): Promise<CachedItemContent | null>;
146
- setItemContent(slug: string, data: CachedItemContent): Promise<void>;
147
- /**
148
- * 無効化。`scope.kind` で meta/content の粒度を指定できる。
149
- * 省略時は両方失効させる。
150
- */
151
- invalidate?(scope: InvalidateScope): Promise<void>;
152
- }
153
- /** 画像キャッシュを抽象化するインターフェース。 */
154
- interface ImageCacheAdapter {
155
- readonly name: string;
156
- get(hash: string): Promise<StorageBinary | null>;
157
- set(hash: string, data: ArrayBuffer, contentType: string): Promise<void>;
158
- }
159
- /**
160
- * キャッシュ設定。`"disabled"` を渡すと完全にキャッシュを無効化する。
161
- * オブジェクトの場合、document / image それぞれ独立したアダプタを差し込める。
162
- */
163
- type CacheConfig<T extends BaseContentItem = BaseContentItem> = "disabled" | {
164
- document?: DocumentCacheAdapter<T>;
165
- image?: ImageCacheAdapter; /** キャッシュの有効期間(ミリ秒)。未設定の場合はTTLなし。 */
166
- ttlMs?: number;
167
- };
168
- //#endregion
169
- export { CollectionConfig as a, InferCollectionItem as c, PropertyDef as d, PropertyMap as f, CMSSchema as i, InvalidateKind as l, DocumentCacheAdapter as n, DataSource as o, WebhookConfig as p, ImageCacheAdapter as r, DataSourceFactory as s, CacheConfig as t, InvalidateScope as u };
170
- //# sourceMappingURL=cache-QrXdXYMs.d.mts.map