@notion-headless-cms/fetch-blocks 0.0.1
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 +28 -0
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +2 -0
- package/dist/react.mjs +3 -0
- package/package.json +76 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BlockHandler } from "@notion-headless-cms/markdown-html";
|
|
2
|
+
import { ContentFetcher, FetchBlockTreeOgpOptions } from "@notion-headless-cms/notion-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
interface BlocksFetcherOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 同時に展開する子ブロックの最大数。デフォルト 3。
|
|
8
|
+
* Notion API のレート制限 (3 req/s) に抵触しないよう抑制する。
|
|
9
|
+
*/
|
|
10
|
+
concurrency?: number;
|
|
11
|
+
/** カスタムブロックハンドラーのマップ。`Transformer` (notion-to-md) に渡る。 */
|
|
12
|
+
blocks?: Record<string, BlockHandler>;
|
|
13
|
+
/** embed / bookmark / link_preview ブロックの OGP 取得設定。 */
|
|
14
|
+
ogp?: FetchBlockTreeOgpOptions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Notion `blocks.children.list` を再帰的に呼ぶ既定の取得戦略。
|
|
18
|
+
* BlockObjectResponse ツリーを返すため `@notion-headless-cms/react-renderer` の
|
|
19
|
+
* `NotionRenderer` で高忠実度に描画できる。
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ ネストが深い大きなページでは Cloudflare Workers Free プランの
|
|
22
|
+
* 50 subrequest/invocation 上限を超えうる。その場合は
|
|
23
|
+
* `@notion-headless-cms/fetch-markdown` の `markdownFetcher()` を検討する。
|
|
24
|
+
*/
|
|
25
|
+
declare function blocksFetcher(opts?: BlocksFetcherOptions): ContentFetcher;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { BlocksFetcherOptions, blocksFetcher };
|
|
28
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Transformer } from "@notion-headless-cms/markdown-html";
|
|
2
|
+
import { fetchBlockTree } from "@notion-headless-cms/notion-orm";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Notion `blocks.children.list` を再帰的に呼ぶ既定の取得戦略。
|
|
6
|
+
* BlockObjectResponse ツリーを返すため `@notion-headless-cms/react-renderer` の
|
|
7
|
+
* `NotionRenderer` で高忠実度に描画できる。
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ ネストが深い大きなページでは Cloudflare Workers Free プランの
|
|
10
|
+
* 50 subrequest/invocation 上限を超えうる。その場合は
|
|
11
|
+
* `@notion-headless-cms/fetch-markdown` の `markdownFetcher()` を検討する。
|
|
12
|
+
*/
|
|
13
|
+
function blocksFetcher(opts = {}) {
|
|
14
|
+
const blocks = opts.blocks;
|
|
15
|
+
const ogp = opts.ogp;
|
|
16
|
+
const concurrency = opts.concurrency;
|
|
17
|
+
return {
|
|
18
|
+
kind: "blocks",
|
|
19
|
+
async loadMarkdown(client, pageId) {
|
|
20
|
+
return new Transformer(blocks ? { blocks } : void 0).transform(client, pageId);
|
|
21
|
+
},
|
|
22
|
+
async loadNotionBlocks(client, pageId) {
|
|
23
|
+
return fetchBlockTree(client, pageId, {
|
|
24
|
+
...ogp ? { ogp } : {},
|
|
25
|
+
...concurrency !== void 0 ? { concurrency } : {}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { blocksFetcher };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { BlockHandler } from \"@notion-headless-cms/markdown-html\";\nimport { Transformer } from \"@notion-headless-cms/markdown-html\";\nimport type {\n ContentFetcher,\n FetchBlockTreeOgpOptions,\n NotionBlockTreeNode,\n} from \"@notion-headless-cms/notion-orm\";\nimport { fetchBlockTree } from \"@notion-headless-cms/notion-orm\";\n\nexport interface BlocksFetcherOptions {\n /**\n * 同時に展開する子ブロックの最大数。デフォルト 3。\n * Notion API のレート制限 (3 req/s) に抵触しないよう抑制する。\n */\n concurrency?: number;\n /** カスタムブロックハンドラーのマップ。`Transformer` (notion-to-md) に渡る。 */\n blocks?: Record<string, BlockHandler>;\n /** embed / bookmark / link_preview ブロックの OGP 取得設定。 */\n ogp?: FetchBlockTreeOgpOptions;\n}\n\n/**\n * Notion `blocks.children.list` を再帰的に呼ぶ既定の取得戦略。\n * BlockObjectResponse ツリーを返すため `@notion-headless-cms/react-renderer` の\n * `NotionRenderer` で高忠実度に描画できる。\n *\n * ⚠️ ネストが深い大きなページでは Cloudflare Workers Free プランの\n * 50 subrequest/invocation 上限を超えうる。その場合は\n * `@notion-headless-cms/fetch-markdown` の `markdownFetcher()` を検討する。\n */\nexport function blocksFetcher(opts: BlocksFetcherOptions = {}): ContentFetcher {\n const blocks = opts.blocks;\n const ogp = opts.ogp;\n const concurrency = opts.concurrency;\n return {\n kind: \"blocks\",\n async loadMarkdown(client, pageId) {\n const transformer = new Transformer(blocks ? { blocks } : undefined);\n return transformer.transform(client, pageId);\n },\n async loadNotionBlocks(client, pageId): Promise<NotionBlockTreeNode[]> {\n return fetchBlockTree(client, pageId, {\n ...(ogp ? { ogp } : {}),\n ...(concurrency !== undefined ? { concurrency } : {}),\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAgB,cAAc,OAA6B,CAAC,GAAmB;CAC7E,MAAM,SAAS,KAAK;CACpB,MAAM,MAAM,KAAK;CACjB,MAAM,cAAc,KAAK;CACzB,OAAO;EACL,MAAM;EACN,MAAM,aAAa,QAAQ,QAAQ;GAEjC,OAAO,IADiB,YAAY,SAAS,EAAE,OAAO,IAAI,KAAA,CACzC,EAAE,UAAU,QAAQ,MAAM;EAC7C;EACA,MAAM,iBAAiB,QAAQ,QAAwC;GACrE,OAAO,eAAe,QAAQ,QAAQ;IACpC,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;IACrB,GAAI,gBAAgB,KAAA,IAAY,EAAE,YAAY,IAAI,CAAC;GACrD,CAAC;EACH;CACF;AACF"}
|
package/dist/react.d.mts
ADDED
package/dist/react.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@notion-headless-cms/fetch-blocks",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Notion ブロック children API を再帰的に取得する fetch 戦略。BlockObjectResponse ツリーを返し、react-renderer で描画する。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"notion",
|
|
7
|
+
"headless-cms",
|
|
8
|
+
"fetcher",
|
|
9
|
+
"blocks",
|
|
10
|
+
"block-tree",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"homepage": "https://github.com/kjfsm/notion-headless-cms#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/kjfsm/notion-headless-cms/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/kjfsm/notion-headless-cms.git",
|
|
21
|
+
"directory": "packages/fetch-blocks"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./react": {
|
|
31
|
+
"types": "./dist/react.d.mts",
|
|
32
|
+
"import": "./dist/react.mjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown src/index.ts src/react.ts --format esm --dts --sourcemap --out-dir dist",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:coverage": "vitest run --coverage --coverage.reporter=lcov --coverage.reporter=text",
|
|
46
|
+
"publint": "publint --strict",
|
|
47
|
+
"attw": "attw --pack . --profile esm-only"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public",
|
|
51
|
+
"provenance": true
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@notion-headless-cms/markdown-html": "workspace:*",
|
|
55
|
+
"@notion-headless-cms/notion-orm": "workspace:*"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@notion-headless-cms/react-renderer": "workspace:*",
|
|
59
|
+
"@notionhq/client": "^5.20.0",
|
|
60
|
+
"react": "^19.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@notion-headless-cms/react-renderer": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"react": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@notion-headless-cms/react-renderer": "workspace:*",
|
|
72
|
+
"@notionhq/client": "catalog:",
|
|
73
|
+
"@types/react": "catalog:",
|
|
74
|
+
"react": "catalog:"
|
|
75
|
+
}
|
|
76
|
+
}
|