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