@wirecat/notion-cli 0.0.0-stage → 0.1.0
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/CHANGELOG.md +33 -0
- package/LICENSE +204 -0
- package/README.md +36 -2
- package/contracts/wirecat.json +1315 -0
- package/dist/bin/notion.d.ts +3 -0
- package/dist/bin/notion.d.ts.map +1 -0
- package/dist/bin/notion.js +40 -0
- package/dist/bin/notion.js.map +1 -0
- package/dist/bundle/all-profiles-OETMCOLN.js +278 -0
- package/dist/bundle/anthropic-5Y3O2TYM.js +91 -0
- package/dist/bundle/app-server-IVWBIVHC.js +231 -0
- package/dist/bundle/bun-EO636SAD.js +169 -0
- package/dist/bundle/bun-sqlite-C2T7QJ2M.js +76 -0
- package/dist/bundle/chunk-24FAYAML.js +52 -0
- package/dist/bundle/chunk-2YR3RYT4.js +73 -0
- package/dist/bundle/chunk-35K5T6WV.js +24 -0
- package/dist/bundle/chunk-3D3PFXBP.js +2315 -0
- package/dist/bundle/chunk-47R43UVJ.js +1068 -0
- package/dist/bundle/chunk-4GC5DBHW.js +100 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-64D5VUZ4.js +9564 -0
- package/dist/bundle/chunk-66PL7P4C.js +23 -0
- package/dist/bundle/chunk-7FII4DCE.js +362 -0
- package/dist/bundle/chunk-7N5QB6NL.js +156 -0
- package/dist/bundle/chunk-AE2KQ37N.js +95 -0
- package/dist/bundle/chunk-AQZO3ITW.js +58 -0
- package/dist/bundle/chunk-B2WFKFYL.js +1488 -0
- package/dist/bundle/chunk-B2XKEEFX.js +230 -0
- package/dist/bundle/chunk-B4B65XIO.js +73 -0
- package/dist/bundle/chunk-BWICUW7W.js +288 -0
- package/dist/bundle/chunk-CLG2ISQH.js +206 -0
- package/dist/bundle/chunk-CWVAYQXI.js +185 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DIM5YWBU.js +53 -0
- package/dist/bundle/chunk-EGTBL3MJ.js +6848 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EPAZ7DJB.js +783 -0
- package/dist/bundle/chunk-ESZT4WW3.js +142 -0
- package/dist/bundle/chunk-EU5WCOMQ.js +4001 -0
- package/dist/bundle/chunk-F6MLJ3V5.js +72 -0
- package/dist/bundle/chunk-FF4DDBCB.js +1028 -0
- package/dist/bundle/chunk-GA3URWIF.js +46 -0
- package/dist/bundle/chunk-HRTIRRXR.js +3112 -0
- package/dist/bundle/chunk-HWRKURQH.js +54 -0
- package/dist/bundle/chunk-IQWEJEB5.js +39724 -0
- package/dist/bundle/chunk-JK44XO2S.js +392 -0
- package/dist/bundle/chunk-JKIN5TOU.js +131 -0
- package/dist/bundle/chunk-K5TWMQSY.js +188 -0
- package/dist/bundle/chunk-KHOVVPLC.js +18 -0
- package/dist/bundle/chunk-NLDYZBTC.js +5862 -0
- package/dist/bundle/chunk-OWJDC4CB.js +217 -0
- package/dist/bundle/chunk-QBC23NHD.js +38 -0
- package/dist/bundle/chunk-QC3KOJT4.js +300 -0
- package/dist/bundle/chunk-R6ZM45NF.js +1239 -0
- package/dist/bundle/chunk-RAZKIHGH.js +76 -0
- package/dist/bundle/chunk-RDZ7SVBZ.js +731 -0
- package/dist/bundle/chunk-RLSFOR2D.js +161 -0
- package/dist/bundle/chunk-RSIS7BR7.js +2778 -0
- package/dist/bundle/chunk-ST2UC7FS.js +1324 -0
- package/dist/bundle/chunk-TR7R5DL4.js +370 -0
- package/dist/bundle/chunk-TSCIIXN3.js +106 -0
- package/dist/bundle/chunk-UWIA2G6Q.js +12737 -0
- package/dist/bundle/chunk-UWW24JQF.js +66 -0
- package/dist/bundle/chunk-WK3OSDNV.js +1197 -0
- package/dist/bundle/chunk-WM7663C2.js +1221 -0
- package/dist/bundle/chunk-WVZFXI36.js +274 -0
- package/dist/bundle/chunk-WWMB4UHF.js +78 -0
- package/dist/bundle/chunk-XC5CKHX2.js +63 -0
- package/dist/bundle/chunk-XL2HXHP3.js +82 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YA4LSSDZ.js +64499 -0
- package/dist/bundle/chunk-ZI3YTXSF.js +2 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-6G5DC2FN.js +35 -0
- package/dist/bundle/command-server-entry-A66DJ3MH.js +164 -0
- package/dist/bundle/decode-7XOFRAAT.js +163 -0
- package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
- package/dist/bundle/dispatch-FEKU5UXC.js +411 -0
- package/dist/bundle/dist-YFKABFFF.js +7577 -0
- package/dist/bundle/echarts-XD2JSWU4.js +42501 -0
- package/dist/bundle/embed-F3HYGAF7.js +38 -0
- package/dist/bundle/embedder-GSEDDUH7.js +111 -0
- package/dist/bundle/failure-HDJLR2YJ.js +25 -0
- package/dist/bundle/first-run-TXNTIUSP.js +28 -0
- package/dist/bundle/first-screen-JZPJND7J.js +33 -0
- package/dist/bundle/instructions-NZGJ4FW5.js +11 -0
- package/dist/bundle/mcp-VFIOZDVY.js +167 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-RPKPDYQS.js +176 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-KH2UUYVO.js +74 -0
- package/dist/bundle/notion.js +185 -0
- package/dist/bundle/oauth-NKAI7TQD.js +20 -0
- package/dist/bundle/open-WSAEAA2V.js +23 -0
- package/dist/bundle/openai-JPVDGHG5.js +238 -0
- package/dist/bundle/process-5ZFVKOQX.js +91 -0
- package/dist/bundle/program-M3D56D6T.js +28854 -0
- package/dist/bundle/prompt-FROYQ5LV.js +17 -0
- package/dist/bundle/recognize-NYCHQMCX.js +26 -0
- package/dist/bundle/remote-4OERF3Z4.js +32 -0
- package/dist/bundle/rerank-TEGXFUWY.js +52 -0
- package/dist/bundle/schemas-MZNNOEYN.js +12214 -0
- package/dist/bundle/serve-HLYYBAXY.js +199 -0
- package/dist/bundle/server-D5OYNEUW.js +193 -0
- package/dist/bundle/server-LWZGVMNW.js +62 -0
- package/dist/bundle/sqlite-runtime-H2S5RR2F.js +20 -0
- package/dist/bundle/state-OPOXCDZL.js +36 -0
- package/dist/bundle/store-NHMXEJPD.js +164 -0
- package/dist/bundle/store-Y3KRLCJ7.js +281 -0
- package/dist/bundle/store-maintenance-command-D4W7WSLQ.js +53 -0
- package/dist/commands/api.d.ts +4 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +140 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/databases.d.ts +3 -0
- package/dist/commands/databases.d.ts.map +1 -0
- package/dist/commands/databases.js +65 -0
- package/dist/commands/databases.js.map +1 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.d.ts.map +1 -0
- package/dist/commands/documents.js +41 -0
- package/dist/commands/documents.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +104 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +58 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +45603 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +3 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +2089 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/metadata.d.ts +6 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/metadata.js +24 -0
- package/dist/generated/metadata.js.map +1 -0
- package/dist/generated/schemas.d.ts +1223 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +11557 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +11120 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +29 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/notion/client.d.ts +42 -0
- package/dist/notion/client.d.ts.map +1 -0
- package/dist/notion/client.js +118 -0
- package/dist/notion/client.js.map +1 -0
- package/dist/notion/errors.d.ts +24 -0
- package/dist/notion/errors.d.ts.map +1 -0
- package/dist/notion/errors.js +102 -0
- package/dist/notion/errors.js.map +1 -0
- package/dist/notion/ids.d.ts +7 -0
- package/dist/notion/ids.d.ts.map +1 -0
- package/dist/notion/ids.js +37 -0
- package/dist/notion/ids.js.map +1 -0
- package/dist/notion/links.d.ts +6 -0
- package/dist/notion/links.d.ts.map +1 -0
- package/dist/notion/links.js +22 -0
- package/dist/notion/links.js.map +1 -0
- package/dist/notion/notion.d.ts +95 -0
- package/dist/notion/notion.d.ts.map +1 -0
- package/dist/notion/notion.js +269 -0
- package/dist/notion/notion.js.map +1 -0
- package/dist/notion/port.d.ts +13 -0
- package/dist/notion/port.d.ts.map +1 -0
- package/dist/notion/port.js +60 -0
- package/dist/notion/port.js.map +1 -0
- package/dist/notion/read-posts.d.ts +36 -0
- package/dist/notion/read-posts.d.ts.map +1 -0
- package/dist/notion/read-posts.js +24 -0
- package/dist/notion/read-posts.js.map +1 -0
- package/dist/notion/reads.d.ts +327 -0
- package/dist/notion/reads.d.ts.map +1 -0
- package/dist/notion/reads.js +18 -0
- package/dist/notion/reads.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +62 -0
- package/dist/program.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/sync/cursor.d.ts +54 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +52 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/front-matter.d.ts +10 -0
- package/dist/sync/front-matter.d.ts.map +1 -0
- package/dist/sync/front-matter.js +114 -0
- package/dist/sync/front-matter.js.map +1 -0
- package/dist/sync/markdown.d.ts +8 -0
- package/dist/sync/markdown.d.ts.map +1 -0
- package/dist/sync/markdown.js +40 -0
- package/dist/sync/markdown.js.map +1 -0
- package/dist/sync/source.d.ts +64 -0
- package/dist/sync/source.d.ts.map +1 -0
- package/dist/sync/source.js +634 -0
- package/dist/sync/source.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +85 -4
- package/skills/notion-cli/SKILL.md +34 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
|
+
import { withoutSignedLinks } from "../notion/links.js";
|
|
3
|
+
import { decodeCursor, encodeCursor } from "./cursor.js";
|
|
4
|
+
import { frontMatter, frontMatterLines, titleOf } from "./front-matter.js";
|
|
5
|
+
import { pageText } from "./markdown.js";
|
|
6
|
+
/** The folder that stands for everything the token sees, the scope when no folder is chosen. */
|
|
7
|
+
export const WORKSPACE_ROOT = "notion-workspace";
|
|
8
|
+
const MINUTE = 60_000;
|
|
9
|
+
/** Notion rounds `last_edited_time` to the minute; a read this soon after an edit may miss another in that minute. */
|
|
10
|
+
export const SETTLE_MS = 3 * MINUTE;
|
|
11
|
+
export const MIN_OVERLAP_MS = 2 * MINUTE;
|
|
12
|
+
const DEFAULTS = { overlapMs: 10 * MINUTE, walkEveryMs: 24 * 60 * MINUTE, maxRequests: 2000 };
|
|
13
|
+
const PAGE_SIZE = 100;
|
|
14
|
+
/**
|
|
15
|
+
* Until cli-core plans a page with children as both a folder and a document (C2), only the workspace and databases
|
|
16
|
+
* are folders: the engine syncs top-level pages and database rows, not pages under pages.
|
|
17
|
+
*/
|
|
18
|
+
export const isNotionFolder = (file) => file.providerMetadata.kind === "workspace" || file.providerMetadata.kind === "database";
|
|
19
|
+
const parentId = (parent) => {
|
|
20
|
+
switch (parent.type) {
|
|
21
|
+
case "workspace":
|
|
22
|
+
return WORKSPACE_ROOT;
|
|
23
|
+
case "page_id":
|
|
24
|
+
return parent.page_id;
|
|
25
|
+
case "data_source_id":
|
|
26
|
+
return parent.data_source_id;
|
|
27
|
+
case "database_id":
|
|
28
|
+
return parent.database_id;
|
|
29
|
+
case "block_id":
|
|
30
|
+
return parent.block_id;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const minus = (iso, ms) => new Date(Date.parse(iso) - ms).toISOString();
|
|
34
|
+
const later = (a, b) => (!a ? b : !b ? a : Date.parse(a) >= Date.parse(b) ? a : b);
|
|
35
|
+
const isNotFound = (error) => isCliError(error) && error.code === "not_found";
|
|
36
|
+
/** Answers about one item, not the sync: a linked database view answers 404 by design, a restricted page 403. */
|
|
37
|
+
const isItemError = (error) => isCliError(error) && (error.code === "not_found" || error.code === "permission_error");
|
|
38
|
+
const text = (parts) => parts.map((part) => part.plain_text).join("");
|
|
39
|
+
export const notionSource = (notion, options = {}) => {
|
|
40
|
+
const overlapMs = options.overlapMs ?? DEFAULTS.overlapMs;
|
|
41
|
+
if (overlapMs < MIN_OVERLAP_MS)
|
|
42
|
+
throw new CliError("validation_error", "the sync overlap must be two minutes or more");
|
|
43
|
+
const walkEveryMs = options.walkEveryMs ?? DEFAULTS.walkEveryMs;
|
|
44
|
+
const maxRequests = options.maxRequests ?? DEFAULTS.maxRequests;
|
|
45
|
+
const roots = options.roots?.length ? options.roots : [WORKSPACE_ROOT];
|
|
46
|
+
const now = options.now ?? Date.now;
|
|
47
|
+
const warn = options.warn ?? (() => undefined);
|
|
48
|
+
let requests = 0;
|
|
49
|
+
const counted = (call) => (...args) => {
|
|
50
|
+
requests++;
|
|
51
|
+
return call.apply(notion, args);
|
|
52
|
+
};
|
|
53
|
+
const reads = {
|
|
54
|
+
self: counted(notion.self),
|
|
55
|
+
search: counted(notion.search),
|
|
56
|
+
queryDataSource: counted(notion.queryDataSource),
|
|
57
|
+
retrievePage: counted(notion.retrievePage),
|
|
58
|
+
retrieveDatabase: counted(notion.retrieveDatabase),
|
|
59
|
+
retrieveBlock: counted(notion.retrieveBlock),
|
|
60
|
+
blockChildren: counted(notion.blockChildren),
|
|
61
|
+
pageMarkdown: counted(notion.pageMarkdown),
|
|
62
|
+
};
|
|
63
|
+
// Read once per call: the state the engine holds does not change while the source lists.
|
|
64
|
+
let known = new Map();
|
|
65
|
+
// Containers resolved within one call; a page's parent is re-read on the next one, as it may have moved.
|
|
66
|
+
let containers = new Map();
|
|
67
|
+
let accessible = new Set();
|
|
68
|
+
let newestSeen = Number.NEGATIVE_INFINITY;
|
|
69
|
+
const fresh = () => {
|
|
70
|
+
known = new Map([...(options.known?.() ?? [])].map((file) => [file.id, file]));
|
|
71
|
+
containers = new Map();
|
|
72
|
+
accessible = new Set(known.keys());
|
|
73
|
+
};
|
|
74
|
+
/** Notion's time: its Date header, or failing that the newest edit it has shown, which is never later than it. */
|
|
75
|
+
const notionNow = () => Math.max(notion.serverTime?.() ?? Number.NEGATIVE_INFINITY, newestSeen);
|
|
76
|
+
/** The container a page sits in: its page or database, or the workspace when that parent is out of the token's view. */
|
|
77
|
+
const containerOf = async (parent) => {
|
|
78
|
+
if (parent.type === "workspace")
|
|
79
|
+
return WORKSPACE_ROOT;
|
|
80
|
+
if (parent.type === "data_source_id" || parent.type === "database_id")
|
|
81
|
+
return parent.database_id;
|
|
82
|
+
const id = parentId(parent);
|
|
83
|
+
const cached = containers.get(id);
|
|
84
|
+
if (cached)
|
|
85
|
+
return cached;
|
|
86
|
+
let container;
|
|
87
|
+
try {
|
|
88
|
+
if (parent.type === "block_id")
|
|
89
|
+
container = await containerOf((await reads.retrieveBlock(id)).parent);
|
|
90
|
+
else {
|
|
91
|
+
if (!accessible.has(id))
|
|
92
|
+
await reads.retrievePage(id);
|
|
93
|
+
container = id;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!isItemError(error))
|
|
98
|
+
throw error;
|
|
99
|
+
container = WORKSPACE_ROOT;
|
|
100
|
+
}
|
|
101
|
+
containers.set(id, container);
|
|
102
|
+
return container;
|
|
103
|
+
};
|
|
104
|
+
const versionOf = (edited) => {
|
|
105
|
+
newestSeen = Math.max(newestSeen, Date.parse(edited));
|
|
106
|
+
return Date.parse(edited) + SETTLE_MS > notionNow() ? `${edited}~unsettled~${now()}` : edited;
|
|
107
|
+
};
|
|
108
|
+
const pageFile = async (page) => {
|
|
109
|
+
accessible.add(page.id);
|
|
110
|
+
const row = page.parent.type === "data_source_id" || page.parent.type === "database_id";
|
|
111
|
+
return {
|
|
112
|
+
id: page.id,
|
|
113
|
+
name: titleOf(page.properties),
|
|
114
|
+
mime: "application/vnd.notion.page",
|
|
115
|
+
parents: [await containerOf(page.parent)],
|
|
116
|
+
version: versionOf(page.last_edited_time),
|
|
117
|
+
modifiedAt: page.last_edited_time,
|
|
118
|
+
createdAt: page.created_time,
|
|
119
|
+
url: page.url,
|
|
120
|
+
trashed: page.in_trash,
|
|
121
|
+
canDownload: true,
|
|
122
|
+
providerMetadata: {
|
|
123
|
+
kind: row ? "row" : "page",
|
|
124
|
+
parent: { type: page.parent.type, id: parentId(page.parent) },
|
|
125
|
+
...(page.created_by ? { createdBy: page.created_by.id } : {}),
|
|
126
|
+
...(page.last_edited_by ? { lastEditedBy: page.last_edited_by.id } : {}),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const databaseFile = async (database) => {
|
|
131
|
+
accessible.add(database.id);
|
|
132
|
+
return {
|
|
133
|
+
id: database.id,
|
|
134
|
+
name: text(database.title),
|
|
135
|
+
mime: "application/vnd.notion.database",
|
|
136
|
+
parents: [await containerOf(database.parent)],
|
|
137
|
+
version: database.last_edited_time,
|
|
138
|
+
modifiedAt: database.last_edited_time,
|
|
139
|
+
createdAt: database.created_time,
|
|
140
|
+
url: database.url,
|
|
141
|
+
trashed: database.in_trash,
|
|
142
|
+
canDownload: false,
|
|
143
|
+
providerMetadata: {
|
|
144
|
+
kind: "database",
|
|
145
|
+
parent: { type: database.parent.type, id: parentId(database.parent) },
|
|
146
|
+
dataSources: database.data_sources,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const workspaceFile = () => ({
|
|
151
|
+
id: WORKSPACE_ROOT,
|
|
152
|
+
name: "Notion workspace",
|
|
153
|
+
mime: "application/vnd.notion.workspace",
|
|
154
|
+
parents: [],
|
|
155
|
+
url: "",
|
|
156
|
+
trashed: false,
|
|
157
|
+
canDownload: false,
|
|
158
|
+
providerMetadata: { kind: "workspace" },
|
|
159
|
+
});
|
|
160
|
+
const retrieve = async (id, kind) => {
|
|
161
|
+
if (id === WORKSPACE_ROOT)
|
|
162
|
+
return workspaceFile();
|
|
163
|
+
if (kind === "database")
|
|
164
|
+
return databaseFile(await reads.retrieveDatabase(id));
|
|
165
|
+
try {
|
|
166
|
+
return await pageFile(await reads.retrievePage(id));
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (kind || !isCliError(error) || !["not_found", "validation_error"].includes(error.code))
|
|
170
|
+
throw error;
|
|
171
|
+
return databaseFile(await reads.retrieveDatabase(id));
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/** One `created_time` window of a data source; Notion stops a query at 10,000 rows and says so. */
|
|
175
|
+
const rowWindow = async (database, source, after, since) => {
|
|
176
|
+
const filters = [
|
|
177
|
+
...(since ? [{ timestamp: "last_edited_time", last_edited_time: { on_or_after: since } }] : []),
|
|
178
|
+
...(after ? [{ timestamp: "created_time", created_time: { on_or_after: after } }] : []),
|
|
179
|
+
];
|
|
180
|
+
const filter = filters.length > 1 ? { and: filters } : filters[0];
|
|
181
|
+
const rows = [];
|
|
182
|
+
let incomplete = false;
|
|
183
|
+
let start;
|
|
184
|
+
do {
|
|
185
|
+
const page = await reads.queryDataSource(source, {
|
|
186
|
+
...(filter ? { filter } : {}),
|
|
187
|
+
sorts: [{ timestamp: "created_time", direction: "ascending" }],
|
|
188
|
+
page_size: PAGE_SIZE,
|
|
189
|
+
...(start ? { start_cursor: start } : {}),
|
|
190
|
+
});
|
|
191
|
+
for (const result of page.results)
|
|
192
|
+
rows.push(result);
|
|
193
|
+
if (page.request_status?.type === "incomplete")
|
|
194
|
+
incomplete = true;
|
|
195
|
+
start = page.has_more && page.next_cursor ? page.next_cursor : undefined;
|
|
196
|
+
} while (start);
|
|
197
|
+
let next;
|
|
198
|
+
if (incomplete) {
|
|
199
|
+
next = rows.at(-1)?.created_time;
|
|
200
|
+
if (!next || next === after)
|
|
201
|
+
throw new CliError("validation_error", `database ${database} has more than 10000 rows created in one minute`, {
|
|
202
|
+
reason: "notion.window-too-dense",
|
|
203
|
+
database,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return { rows, next };
|
|
207
|
+
};
|
|
208
|
+
const allRows = async (database) => {
|
|
209
|
+
const files = new Map();
|
|
210
|
+
for (const source of database.data_sources) {
|
|
211
|
+
let after;
|
|
212
|
+
do {
|
|
213
|
+
const window = await rowWindow(database.id, source.id, after, null);
|
|
214
|
+
for (const row of window.rows)
|
|
215
|
+
if (!row.in_trash)
|
|
216
|
+
files.set(row.id, await pageFile(row));
|
|
217
|
+
after = window.next;
|
|
218
|
+
} while (after);
|
|
219
|
+
}
|
|
220
|
+
return [...files.values()];
|
|
221
|
+
};
|
|
222
|
+
const searchPage = (kind, start) => reads.search({
|
|
223
|
+
filter: { property: "object", value: kind },
|
|
224
|
+
sort: { timestamp: "last_edited_time", direction: "descending" },
|
|
225
|
+
page_size: PAGE_SIZE,
|
|
226
|
+
...(start ? { start_cursor: start } : {}),
|
|
227
|
+
});
|
|
228
|
+
const isCut = (page) => page.request_status?.type === "incomplete";
|
|
229
|
+
/**
|
|
230
|
+
* Everything search gives, for the top of a walk. Search counts database rows too, so a workspace past 10,000 pages
|
|
231
|
+
* and rows always gets a cut answer; failing here would stop every walk, and with it every deletion check.
|
|
232
|
+
*/
|
|
233
|
+
const searchAll = async (kind) => {
|
|
234
|
+
const results = [];
|
|
235
|
+
let start;
|
|
236
|
+
do {
|
|
237
|
+
const page = await searchPage(kind, start);
|
|
238
|
+
for (const result of page.results)
|
|
239
|
+
results.push(result);
|
|
240
|
+
start = page.has_more && page.next_cursor ? page.next_cursor : undefined;
|
|
241
|
+
if (isCut(page))
|
|
242
|
+
warn({
|
|
243
|
+
code: "provider_error",
|
|
244
|
+
message: `Notion's search gave only the ${results.length} most recently edited ${kind}s; a top-level one it left out is found once it is edited`,
|
|
245
|
+
});
|
|
246
|
+
} while (start);
|
|
247
|
+
return results;
|
|
248
|
+
};
|
|
249
|
+
/** A database search named, or undefined when Notion will not give it: search entries can be stale. */
|
|
250
|
+
const readDatabase = async (id) => {
|
|
251
|
+
try {
|
|
252
|
+
return await reads.retrieveDatabase(id);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
if (!isItemError(error))
|
|
256
|
+
throw error;
|
|
257
|
+
warn({ id, code: error.code, message: "a database search listed could not be read" });
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const childPages = async (blockId, found) => {
|
|
262
|
+
let start;
|
|
263
|
+
do {
|
|
264
|
+
const page = await reads.blockChildren(blockId, start);
|
|
265
|
+
for (const block of page.results) {
|
|
266
|
+
if (block.in_trash)
|
|
267
|
+
continue;
|
|
268
|
+
if (block.type === "child_page")
|
|
269
|
+
found.pages.push(block.id);
|
|
270
|
+
else if (block.type === "child_database")
|
|
271
|
+
found.databases.push(block.id);
|
|
272
|
+
else if (block.has_children)
|
|
273
|
+
await childPages(block.id, found);
|
|
274
|
+
}
|
|
275
|
+
start = page.has_more && page.next_cursor ? page.next_cursor : undefined;
|
|
276
|
+
} while (start);
|
|
277
|
+
return found;
|
|
278
|
+
};
|
|
279
|
+
const listed = async (id) => {
|
|
280
|
+
if (id === WORKSPACE_ROOT) {
|
|
281
|
+
const pages = (await searchAll("page"));
|
|
282
|
+
const sources = (await searchAll("data_source"));
|
|
283
|
+
for (const page of pages)
|
|
284
|
+
accessible.add(page.id);
|
|
285
|
+
const databases = new Map();
|
|
286
|
+
for (const source of sources) {
|
|
287
|
+
const id = source.parent.database_id;
|
|
288
|
+
accessible.add(id);
|
|
289
|
+
if (databases.has(id) || source.in_trash)
|
|
290
|
+
continue;
|
|
291
|
+
const database = await readDatabase(id);
|
|
292
|
+
if (database)
|
|
293
|
+
databases.set(id, database);
|
|
294
|
+
}
|
|
295
|
+
const files = [];
|
|
296
|
+
for (const page of pages)
|
|
297
|
+
if (!page.in_trash)
|
|
298
|
+
files.push(await pageFile(page));
|
|
299
|
+
for (const database of databases.values())
|
|
300
|
+
if (!database.in_trash)
|
|
301
|
+
files.push(await databaseFile(database));
|
|
302
|
+
return files.filter((file) => file.parents[0] === WORKSPACE_ROOT);
|
|
303
|
+
}
|
|
304
|
+
const kind = known.get(id)?.providerMetadata.kind ?? (await retrieve(id)).providerMetadata.kind;
|
|
305
|
+
if (kind === "database")
|
|
306
|
+
return allRows(await reads.retrieveDatabase(id));
|
|
307
|
+
if (kind === "row")
|
|
308
|
+
return [];
|
|
309
|
+
const found = await childPages(id, { pages: [], databases: [] });
|
|
310
|
+
const files = [];
|
|
311
|
+
const child = async (id, read) => {
|
|
312
|
+
try {
|
|
313
|
+
const file = await read();
|
|
314
|
+
if (!file.trashed)
|
|
315
|
+
files.push(file);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
if (!isItemError(error))
|
|
319
|
+
throw error;
|
|
320
|
+
warn({ id, code: error.code, message: "a child Notion would not give was left out" });
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
for (const page of found.pages)
|
|
324
|
+
await child(page, async () => pageFile(await reads.retrievePage(page)));
|
|
325
|
+
for (const database of found.databases)
|
|
326
|
+
await child(database, async () => databaseFile(await reads.retrieveDatabase(database)));
|
|
327
|
+
return files;
|
|
328
|
+
};
|
|
329
|
+
/** Known items missing from a listing, each read directly: gone only on 404 or the trash, kept on any doubt. */
|
|
330
|
+
const confirm = async (missing, container, listing) => {
|
|
331
|
+
for (const file of missing) {
|
|
332
|
+
try {
|
|
333
|
+
const current = await retrieve(file.id, file.providerMetadata.kind);
|
|
334
|
+
if (current.trashed)
|
|
335
|
+
listing.gone.push(file.id);
|
|
336
|
+
else if (current.parents[0] === container)
|
|
337
|
+
listing.files.push(current);
|
|
338
|
+
else
|
|
339
|
+
listing.moved.push(current);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (isNotFound(error))
|
|
343
|
+
listing.gone.push(file.id);
|
|
344
|
+
else if (isItemError(error)) {
|
|
345
|
+
listing.files.push(file);
|
|
346
|
+
warn({ id: file.id, code: error.code, message: "kept as it was: Notion would not say" });
|
|
347
|
+
}
|
|
348
|
+
else
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
/** A container's children, with every known child that did not come back checked directly before it counts as gone. */
|
|
354
|
+
const listChildren = async (id) => {
|
|
355
|
+
const listing = { files: await listed(id), gone: [], moved: [] };
|
|
356
|
+
const seen = new Set(listing.files.map((file) => file.id));
|
|
357
|
+
await confirm([...known.values()].filter((file) => file.parents[0] === id && !seen.has(file.id)), id, listing);
|
|
358
|
+
return listing;
|
|
359
|
+
};
|
|
360
|
+
const sourcesInScope = (cursor) => {
|
|
361
|
+
const sources = new Map(cursor.sources.map((item) => [item.source, item]));
|
|
362
|
+
for (const file of known.values())
|
|
363
|
+
for (const source of file.providerMetadata.dataSources ?? [])
|
|
364
|
+
sources.set(source.id, { database: file.id, source: source.id });
|
|
365
|
+
return [...sources.values()];
|
|
366
|
+
};
|
|
367
|
+
const startPass = (cursor) => {
|
|
368
|
+
const walk = now() - cursor.walkedAt >= walkEveryMs;
|
|
369
|
+
const tasks = [
|
|
370
|
+
{ t: "search", kind: "page" },
|
|
371
|
+
{ t: "search", kind: "data_source" },
|
|
372
|
+
...(walk
|
|
373
|
+
? roots.map((id) => ({ t: "walk", id }))
|
|
374
|
+
: sourcesInScope(cursor).map((item) => ({ t: "rows", ...item }))),
|
|
375
|
+
];
|
|
376
|
+
return { next: cursor.mark, startedAt: now(), walk, tasks };
|
|
377
|
+
};
|
|
378
|
+
const changes = async (token) => {
|
|
379
|
+
const cursor = decodeCursor(token);
|
|
380
|
+
fresh();
|
|
381
|
+
requests = 0;
|
|
382
|
+
const pass = cursor.pass ?? startPass(cursor);
|
|
383
|
+
const since = cursor.mark ? minus(cursor.mark, overlapMs) : null;
|
|
384
|
+
const items = new Map();
|
|
385
|
+
const emit = (file) => items.set(file.id, { id: file.id, removed: false, file });
|
|
386
|
+
const gone = (id) => items.set(id, { id, removed: true });
|
|
387
|
+
// The engine walks every folder it is sent, all its rows, so a database it already holds is not sent again.
|
|
388
|
+
const unheld = (file) => {
|
|
389
|
+
const before = known.get(file.id);
|
|
390
|
+
return !before || before.name !== file.name || before.parents[0] !== file.parents[0];
|
|
391
|
+
};
|
|
392
|
+
const addSource = (database, source) => {
|
|
393
|
+
if (!cursor.sources.some((item) => item.source === source))
|
|
394
|
+
cursor.sources.push({ database, source });
|
|
395
|
+
};
|
|
396
|
+
const search = async (kind) => {
|
|
397
|
+
let start;
|
|
398
|
+
do {
|
|
399
|
+
const page = await searchPage(kind, start);
|
|
400
|
+
start = page.has_more && page.next_cursor ? page.next_cursor : undefined;
|
|
401
|
+
let reachedMark = false;
|
|
402
|
+
for (const result of page.results) {
|
|
403
|
+
if (since && Date.parse(result.last_edited_time) < Date.parse(since)) {
|
|
404
|
+
start = undefined;
|
|
405
|
+
reachedMark = true;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
// Only what this pass saw before it began counts towards the next mark; later edits must stay inside it.
|
|
409
|
+
if (kind === "page")
|
|
410
|
+
pass.next = later(pass.next, result.last_edited_time);
|
|
411
|
+
if (result.object === "page") {
|
|
412
|
+
emit(await pageFile(result));
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const id = result.parent.database_id;
|
|
416
|
+
// A database outside the chosen folders is not read; one inside them is held already, or comes by a walk.
|
|
417
|
+
if (!roots.includes(WORKSPACE_ROOT) && !known.has(id))
|
|
418
|
+
continue;
|
|
419
|
+
const database = await readDatabase(id);
|
|
420
|
+
if (!database)
|
|
421
|
+
continue;
|
|
422
|
+
const file = await databaseFile(database);
|
|
423
|
+
if (file.trashed)
|
|
424
|
+
gone(id);
|
|
425
|
+
else if (unheld(file))
|
|
426
|
+
emit(file);
|
|
427
|
+
}
|
|
428
|
+
// Search has no time filter to split a cut answer by, so edits past the cut fail the sync instead of passing.
|
|
429
|
+
if (isCut(page) && !reachedMark)
|
|
430
|
+
throw new CliError("provider_error", `Notion cut the search for edited ${kind}s short`, {
|
|
431
|
+
reason: "notion.search-incomplete",
|
|
432
|
+
...(page.request_status?.incomplete_reason
|
|
433
|
+
? { incomplete_reason: page.request_status.incomplete_reason }
|
|
434
|
+
: {}),
|
|
435
|
+
});
|
|
436
|
+
} while (start);
|
|
437
|
+
};
|
|
438
|
+
const rows = async (task) => {
|
|
439
|
+
let window;
|
|
440
|
+
try {
|
|
441
|
+
window = await rowWindow(task.database, task.source, task.after, task.full ? null : since);
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
if (!isNotFound(error))
|
|
445
|
+
throw error;
|
|
446
|
+
cursor.sources = cursor.sources.filter((item) => item.source !== task.source);
|
|
447
|
+
const database = await readDatabase(task.database);
|
|
448
|
+
if (!database || database.in_trash)
|
|
449
|
+
gone(task.database);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const seen = new Set();
|
|
453
|
+
for (const row of window.rows) {
|
|
454
|
+
seen.add(row.id);
|
|
455
|
+
emit(await pageFile(row));
|
|
456
|
+
}
|
|
457
|
+
if (task.full) {
|
|
458
|
+
// A window covers the rows created from its start up to the next window's start; a known row of that span
|
|
459
|
+
// the window did not return is read directly before it counts as gone.
|
|
460
|
+
const from = task.after ? Date.parse(task.after) : Number.NEGATIVE_INFINITY;
|
|
461
|
+
const to = window.next ? Date.parse(window.next) : Number.POSITIVE_INFINITY;
|
|
462
|
+
const missing = [...known.values()].filter((file) => {
|
|
463
|
+
const created = Date.parse(file.createdAt ?? "");
|
|
464
|
+
return (file.providerMetadata.kind === "row" &&
|
|
465
|
+
file.providerMetadata.parent?.id === task.source &&
|
|
466
|
+
!seen.has(file.id) &&
|
|
467
|
+
created >= from &&
|
|
468
|
+
created < to);
|
|
469
|
+
});
|
|
470
|
+
const listing = { files: [], gone: [], moved: [] };
|
|
471
|
+
await confirm(missing, task.database, listing);
|
|
472
|
+
for (const file of [...listing.files, ...listing.moved])
|
|
473
|
+
emit(file);
|
|
474
|
+
for (const id of listing.gone)
|
|
475
|
+
gone(id);
|
|
476
|
+
}
|
|
477
|
+
if (window.next)
|
|
478
|
+
pass.tasks.push({ ...task, after: window.next });
|
|
479
|
+
};
|
|
480
|
+
const walkDatabase = async (id) => {
|
|
481
|
+
const database = await readDatabase(id);
|
|
482
|
+
if (!database || database.in_trash) {
|
|
483
|
+
if (!roots.includes(id))
|
|
484
|
+
gone(id);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
for (const source of database.data_sources) {
|
|
488
|
+
addSource(id, source.id);
|
|
489
|
+
pass.tasks.push({ t: "rows", database: id, source: source.id, full: true });
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const walk = async (id) => {
|
|
493
|
+
const kind = id === WORKSPACE_ROOT ? "workspace" : (known.get(id)?.providerMetadata.kind ?? "database");
|
|
494
|
+
// Pages under pages wait for cli-core's page-with-children (C2); listing them now would cost requests for nothing.
|
|
495
|
+
if (kind === "database")
|
|
496
|
+
return walkDatabase(id);
|
|
497
|
+
if (kind !== "workspace")
|
|
498
|
+
return;
|
|
499
|
+
const listing = await listChildren(id);
|
|
500
|
+
for (const file of listing.moved)
|
|
501
|
+
emit(file);
|
|
502
|
+
for (const file of listing.files) {
|
|
503
|
+
if (!isNotionFolder(file) || unheld(file))
|
|
504
|
+
emit(file);
|
|
505
|
+
if (file.providerMetadata.kind === "database")
|
|
506
|
+
pass.tasks.push({ t: "walk", id: file.id });
|
|
507
|
+
}
|
|
508
|
+
for (const gid of listing.gone)
|
|
509
|
+
gone(gid);
|
|
510
|
+
};
|
|
511
|
+
let done = 0;
|
|
512
|
+
while (pass.tasks.length && requests < maxRequests) {
|
|
513
|
+
const task = pass.tasks[0];
|
|
514
|
+
try {
|
|
515
|
+
if (task.t === "search")
|
|
516
|
+
await search(task.kind);
|
|
517
|
+
else if (task.t === "rows")
|
|
518
|
+
await rows(task);
|
|
519
|
+
else
|
|
520
|
+
await walk(task.id);
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
const failure = isCliError(error) ? error : new CliError("provider_error", String(error));
|
|
524
|
+
const id = task.t === "rows" ? task.database : task.t === "walk" ? task.id : undefined;
|
|
525
|
+
if (isItemError(failure)) {
|
|
526
|
+
warn({ ...(id ? { id } : {}), code: failure.code, message: `left out of this sync: ${failure.message}` });
|
|
527
|
+
pass.tasks.shift();
|
|
528
|
+
done++;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
// With nothing done yet the error is the answer; otherwise the work so far is kept and the next sync goes on.
|
|
532
|
+
if (!done)
|
|
533
|
+
throw failure;
|
|
534
|
+
warn({
|
|
535
|
+
...(id ? { id } : {}),
|
|
536
|
+
code: failure.code,
|
|
537
|
+
message: `the sync stopped here and goes on next time: ${failure.message}`,
|
|
538
|
+
...(typeof failure.details.retry_after_ms === "number"
|
|
539
|
+
? { retry_after_ms: failure.details.retry_after_ms }
|
|
540
|
+
: {}),
|
|
541
|
+
});
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
pass.tasks.shift();
|
|
545
|
+
done++;
|
|
546
|
+
}
|
|
547
|
+
if (pass.tasks.length)
|
|
548
|
+
cursor.pass = pass;
|
|
549
|
+
else {
|
|
550
|
+
cursor.mark = later(cursor.mark, pass.next);
|
|
551
|
+
if (pass.walk)
|
|
552
|
+
cursor.walkedAt = pass.startedAt;
|
|
553
|
+
delete cursor.pass;
|
|
554
|
+
}
|
|
555
|
+
return { items: [...items.values()], cursor: encodeCursor(cursor) };
|
|
556
|
+
};
|
|
557
|
+
const people = (page) => {
|
|
558
|
+
const found = new Map();
|
|
559
|
+
const add = (user, role) => {
|
|
560
|
+
if (user)
|
|
561
|
+
found.set(`${role}:${user.id}`, { id: user.id, ...(user.name ? { name: user.name } : {}), role });
|
|
562
|
+
};
|
|
563
|
+
add(page.created_by, "author");
|
|
564
|
+
add(page.last_edited_by, "editor");
|
|
565
|
+
for (const [name, value] of Object.entries(page.properties))
|
|
566
|
+
if (value.type === "people")
|
|
567
|
+
for (const user of value.people)
|
|
568
|
+
add(user, `property:${name}`);
|
|
569
|
+
return [...found.values()];
|
|
570
|
+
};
|
|
571
|
+
return {
|
|
572
|
+
async identity() {
|
|
573
|
+
const self = await reads.self();
|
|
574
|
+
if (!self.bot?.workspace_id)
|
|
575
|
+
throw new CliError("invalid_response", "Notion did not name the token's workspace", {
|
|
576
|
+
reason: "notion.no-workspace",
|
|
577
|
+
});
|
|
578
|
+
return `${self.bot.workspace_id}:${self.id}`;
|
|
579
|
+
},
|
|
580
|
+
async metadata(id) {
|
|
581
|
+
fresh();
|
|
582
|
+
return retrieve(id, known.get(id)?.providerMetadata.kind);
|
|
583
|
+
},
|
|
584
|
+
async children(id) {
|
|
585
|
+
fresh();
|
|
586
|
+
return (await listChildren(id)).files;
|
|
587
|
+
},
|
|
588
|
+
async startToken() {
|
|
589
|
+
const top = await reads.search({
|
|
590
|
+
filter: { property: "object", value: "page" },
|
|
591
|
+
sort: { timestamp: "last_edited_time", direction: "descending" },
|
|
592
|
+
page_size: 1,
|
|
593
|
+
});
|
|
594
|
+
const cursor = { v: 1, mark: top.results[0]?.last_edited_time ?? null, walkedAt: now(), sources: [] };
|
|
595
|
+
return encodeCursor(cursor);
|
|
596
|
+
},
|
|
597
|
+
changes,
|
|
598
|
+
async content(id, maxChars) {
|
|
599
|
+
containers = new Map();
|
|
600
|
+
const page = await reads.retrievePage(id);
|
|
601
|
+
if (page.in_trash)
|
|
602
|
+
throw new CliError("not_found", "the page is in Notion's trash");
|
|
603
|
+
const file = await pageFile(page);
|
|
604
|
+
const body = await pageText(reads, id);
|
|
605
|
+
const fields = frontMatter(page.properties);
|
|
606
|
+
const metadata = {
|
|
607
|
+
...file,
|
|
608
|
+
providerMetadata: {
|
|
609
|
+
...file.providerMetadata,
|
|
610
|
+
frontMatter: fields,
|
|
611
|
+
people: people(page),
|
|
612
|
+
...(body.missing ? { missingBlocks: body.missing } : {}),
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
const searchable = [file.name, ...frontMatterLines(fields), body.markdown].filter(Boolean).join("\n\n");
|
|
616
|
+
if (maxChars !== undefined && searchable.length > maxChars)
|
|
617
|
+
throw new CliError("validation_error", "the page is longer than the text limit", {
|
|
618
|
+
reason: "source.text-limit",
|
|
619
|
+
text_limit: maxChars,
|
|
620
|
+
});
|
|
621
|
+
const content = {
|
|
622
|
+
metadata,
|
|
623
|
+
markdown: body.markdown,
|
|
624
|
+
text: withoutSignedLinks(searchable).text,
|
|
625
|
+
tabs: [],
|
|
626
|
+
};
|
|
627
|
+
return content;
|
|
628
|
+
},
|
|
629
|
+
async bytes() {
|
|
630
|
+
throw new CliError("validation_error", "a Notion page has no file to download");
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
};
|
|
634
|
+
//# sourceMappingURL=source.js.map
|