@mcp-monorepo/notion-query 1.1.0 → 1.3.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/dist/index.js +56 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/client.d.ts +9 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/client.js +19 -0
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/config.d.ts +44 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +49 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/id-utils.d.ts +8 -0
- package/dist/lib/id-utils.d.ts.map +1 -0
- package/dist/lib/id-utils.js +20 -0
- package/dist/lib/id-utils.js.map +1 -0
- package/dist/lib/markdown-converter.d.ts +8 -0
- package/dist/lib/markdown-converter.d.ts.map +1 -0
- package/dist/lib/markdown-converter.js +95 -0
- package/dist/lib/markdown-converter.js.map +1 -0
- package/dist/lib/notion-syncer.d.ts +27 -0
- package/dist/lib/notion-syncer.d.ts.map +1 -0
- package/dist/lib/notion-syncer.js +212 -0
- package/dist/lib/notion-syncer.js.map +1 -0
- package/dist/lib/parser.d.ts +13 -0
- package/dist/lib/parser.d.ts.map +1 -0
- package/dist/lib/parser.js +88 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/property-parser.d.ts +23 -0
- package/dist/lib/property-parser.d.ts.map +1 -0
- package/dist/lib/property-parser.js +200 -0
- package/dist/lib/property-parser.js.map +1 -0
- package/dist/lib/response-formatter.d.ts +16 -0
- package/dist/lib/response-formatter.d.ts.map +1 -0
- package/dist/lib/response-formatter.js +173 -0
- package/dist/lib/response-formatter.js.map +1 -0
- package/dist/lib/sync-state-manager.d.ts +29 -0
- package/dist/lib/sync-state-manager.d.ts.map +1 -0
- package/dist/lib/sync-state-manager.js +45 -0
- package/dist/lib/sync-state-manager.js.map +1 -0
- package/dist/local-rag/DEMO.d.ts +22 -0
- package/dist/local-rag/DEMO.d.ts.map +1 -0
- package/dist/local-rag/DEMO.js +142 -0
- package/dist/local-rag/DEMO.js.map +1 -0
- package/dist/local-rag/chunker.d.ts +24 -0
- package/dist/local-rag/chunker.d.ts.map +1 -0
- package/dist/local-rag/chunker.js +58 -0
- package/dist/local-rag/chunker.js.map +1 -0
- package/dist/local-rag/embedder.d.ts +43 -0
- package/dist/local-rag/embedder.d.ts.map +1 -0
- package/dist/local-rag/embedder.js +74 -0
- package/dist/local-rag/embedder.js.map +1 -0
- package/dist/local-rag/embedder.service.d.ts +15 -0
- package/dist/local-rag/embedder.service.d.ts.map +1 -0
- package/dist/local-rag/embedder.service.js +84 -0
- package/dist/local-rag/embedder.service.js.map +1 -0
- package/dist/local-rag/embedder.worker.d.ts +2 -0
- package/dist/local-rag/embedder.worker.d.ts.map +1 -0
- package/dist/local-rag/embedder.worker.js +34 -0
- package/dist/local-rag/embedder.worker.js.map +1 -0
- package/dist/local-rag/errors.d.ts +31 -0
- package/dist/local-rag/errors.d.ts.map +1 -0
- package/dist/local-rag/errors.js +47 -0
- package/dist/local-rag/errors.js.map +1 -0
- package/dist/local-rag/html-parser.d.ts +2 -0
- package/dist/local-rag/html-parser.d.ts.map +1 -0
- package/dist/local-rag/html-parser.js +32 -0
- package/dist/local-rag/html-parser.js.map +1 -0
- package/dist/local-rag/index.d.ts +67 -0
- package/dist/local-rag/index.d.ts.map +1 -0
- package/dist/local-rag/index.js +410 -0
- package/dist/local-rag/index.js.map +1 -0
- package/dist/local-rag/parser.d.ts +59 -0
- package/dist/local-rag/parser.d.ts.map +1 -0
- package/dist/local-rag/parser.js +206 -0
- package/dist/local-rag/parser.js.map +1 -0
- package/dist/local-rag/types.d.ts +209 -0
- package/dist/local-rag/types.d.ts.map +1 -0
- package/dist/local-rag/types.js +5 -0
- package/dist/local-rag/types.js.map +1 -0
- package/dist/local-rag/utils/pool.d.ts +60 -0
- package/dist/local-rag/utils/pool.d.ts.map +1 -0
- package/dist/local-rag/utils/pool.js +140 -0
- package/dist/local-rag/utils/pool.js.map +1 -0
- package/dist/local-rag/utils/typed-emitter.d.ts +28 -0
- package/dist/local-rag/utils/typed-emitter.d.ts.map +1 -0
- package/dist/local-rag/utils/typed-emitter.js +44 -0
- package/dist/local-rag/utils/typed-emitter.js.map +1 -0
- package/dist/local-rag/vectordb/index.d.ts +91 -0
- package/dist/local-rag/vectordb/index.d.ts.map +1 -0
- package/dist/local-rag/vectordb/index.js +278 -0
- package/dist/local-rag/vectordb/index.js.map +1 -0
- package/dist/local-rag/vectordb/manager.d.ts +28 -0
- package/dist/local-rag/vectordb/manager.d.ts.map +1 -0
- package/dist/local-rag/vectordb/manager.js +91 -0
- package/dist/local-rag/vectordb/manager.js.map +1 -0
- package/dist/local-rag/vectordb/migration.d.ts +27 -0
- package/dist/local-rag/vectordb/migration.d.ts.map +1 -0
- package/dist/local-rag/vectordb/migration.js +121 -0
- package/dist/local-rag/vectordb/migration.js.map +1 -0
- package/dist/local-rag/vectordb/retriever.d.ts +51 -0
- package/dist/local-rag/vectordb/retriever.d.ts.map +1 -0
- package/dist/local-rag/vectordb/retriever.js +157 -0
- package/dist/local-rag/vectordb/retriever.js.map +1 -0
- package/dist/local-rag/vectordb/schema.d.ts +33 -0
- package/dist/local-rag/vectordb/schema.d.ts.map +1 -0
- package/dist/local-rag/vectordb/schema.js +102 -0
- package/dist/local-rag/vectordb/schema.js.map +1 -0
- package/dist/local-rag/watcher.d.ts +48 -0
- package/dist/local-rag/watcher.d.ts.map +1 -0
- package/dist/local-rag/watcher.js +102 -0
- package/dist/local-rag/watcher.js.map +1 -0
- package/dist/tools/create-pages.d.ts +4 -0
- package/dist/tools/create-pages.d.ts.map +1 -0
- package/dist/tools/create-pages.js +184 -0
- package/dist/tools/create-pages.js.map +1 -0
- package/dist/tools/fetch.d.ts +4 -0
- package/dist/tools/fetch.d.ts.map +1 -0
- package/dist/tools/fetch.js +90 -0
- package/dist/tools/fetch.js.map +1 -0
- package/dist/tools/query-datasource.d.ts +4 -0
- package/dist/tools/query-datasource.d.ts.map +1 -0
- package/dist/tools/{notion-query.js → query-datasource.js} +31 -38
- package/dist/tools/query-datasource.js.map +1 -0
- package/dist/tools/search.d.ts +12 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +75 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/update-page.d.ts +4 -0
- package/dist/tools/update-page.d.ts.map +1 -0
- package/dist/tools/update-page.js +135 -0
- package/dist/tools/update-page.js.map +1 -0
- package/package.json +23 -8
- package/dist/tools/notion-query.d.ts +0 -3
- package/dist/tools/notion-query.d.ts.map +0 -1
- package/dist/tools/notion-query.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DataSourceObjectResponse, type PageObjectResponse, type PartialDataSourceObjectResponse, type PartialPageObjectResponse } from '@notionhq/client';
|
|
2
|
+
type SimplifiedPropertyValue = string | number | boolean | string[] | (string | number | boolean)[] | undefined;
|
|
3
|
+
type SimplifiedPage = Record<string, SimplifiedPropertyValue>;
|
|
4
|
+
type NotionPage = PageObjectResponse | PartialPageObjectResponse | PartialDataSourceObjectResponse | DataSourceObjectResponse;
|
|
5
|
+
/**
|
|
6
|
+
* Takes an array of Notion page objects from the API and converts them into
|
|
7
|
+
* a simplified, flat array of key-value objects.
|
|
8
|
+
* @param pages The array of page objects from the Notion API response.
|
|
9
|
+
* @returns An array of simplified page objects.
|
|
10
|
+
*/
|
|
11
|
+
export declare const simplifyNotionPages: (pages: NotionPage[]) => SimplifiedPage[];
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EACpC,KAAK,yBAAyB,EAC/B,MAAM,kBAAkB,CAAA;AAEzB,KAAK,uBAAuB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAA;AAG/G,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;AAU7D,KAAK,UAAU,GACX,kBAAkB,GAClB,yBAAyB,GACzB,+BAA+B,GAC/B,wBAAwB,CAAA;AAsD5B;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,UAAU,EAAE,KAAG,cAAc,EA8BvE,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// notion-query/lib/parser.ts
|
|
2
|
+
/**
|
|
3
|
+
* Simplifies a single Notion property object into a more readable, simple value.
|
|
4
|
+
* @param prop The Notion property object.
|
|
5
|
+
* @returns A simplified value (string, number, boolean, array, etc.) or undefined.
|
|
6
|
+
*/
|
|
7
|
+
const simplifyPropertyValue = (prop) => {
|
|
8
|
+
switch (prop.type) {
|
|
9
|
+
case 'title':
|
|
10
|
+
return prop.title.map((t) => t.plain_text).join('');
|
|
11
|
+
case 'rich_text':
|
|
12
|
+
return prop.rich_text.map((t) => t.plain_text).join('');
|
|
13
|
+
case 'number':
|
|
14
|
+
return prop.number;
|
|
15
|
+
case 'checkbox':
|
|
16
|
+
return prop.checkbox;
|
|
17
|
+
case 'select':
|
|
18
|
+
return prop.select?.name;
|
|
19
|
+
case 'multi_select':
|
|
20
|
+
return prop.multi_select.map((s) => s.name);
|
|
21
|
+
case 'status':
|
|
22
|
+
return prop.status?.name;
|
|
23
|
+
case 'date': {
|
|
24
|
+
const date = prop.date;
|
|
25
|
+
if (!date)
|
|
26
|
+
return undefined;
|
|
27
|
+
return date.end ? `${date.start} to ${date.end}` : date.start;
|
|
28
|
+
}
|
|
29
|
+
case 'people':
|
|
30
|
+
return prop.people.map((p) => p.name ?? p.id);
|
|
31
|
+
case 'relation':
|
|
32
|
+
return prop.relation.map((r) => r.id);
|
|
33
|
+
case 'formula': {
|
|
34
|
+
const formula = prop.formula;
|
|
35
|
+
return formula[formula.type];
|
|
36
|
+
}
|
|
37
|
+
case 'rollup': {
|
|
38
|
+
const rollup = prop.rollup;
|
|
39
|
+
if (rollup.type === 'array' && rollup.array) {
|
|
40
|
+
return rollup.array.flatMap((item) => simplifyPropertyValue(item)).filter((p) => p !== undefined);
|
|
41
|
+
}
|
|
42
|
+
return rollup[rollup.type];
|
|
43
|
+
}
|
|
44
|
+
case 'url':
|
|
45
|
+
return prop.url;
|
|
46
|
+
case 'email':
|
|
47
|
+
return prop.email;
|
|
48
|
+
case 'phone_number':
|
|
49
|
+
return prop.phone_number;
|
|
50
|
+
default:
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Takes an array of Notion page objects from the API and converts them into
|
|
56
|
+
* a simplified, flat array of key-value objects.
|
|
57
|
+
* @param pages The array of page objects from the Notion API response.
|
|
58
|
+
* @returns An array of simplified page objects.
|
|
59
|
+
*/
|
|
60
|
+
export const simplifyNotionPages = (pages) => {
|
|
61
|
+
return pages.map((page) => {
|
|
62
|
+
const simplifiedPage = {};
|
|
63
|
+
if ('icon' in page) {
|
|
64
|
+
if (page.icon?.type === 'emoji') {
|
|
65
|
+
simplifiedPage.icon = page.icon.emoji;
|
|
66
|
+
}
|
|
67
|
+
else if (page.icon?.type === 'external') {
|
|
68
|
+
simplifiedPage.icon = page.icon.external.url;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if ('cover' in page) {
|
|
72
|
+
if (page.cover?.type === 'external') {
|
|
73
|
+
simplifiedPage.cover = page.cover.external.url;
|
|
74
|
+
}
|
|
75
|
+
else if (page.cover?.type === 'file') {
|
|
76
|
+
simplifiedPage.cover = page.cover.file.url;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
simplifiedPage.url = 'url' in page ? page.url : undefined;
|
|
80
|
+
if ('properties' in page && page.properties) {
|
|
81
|
+
for (const [propName, propValue] of Object.entries(page.properties)) {
|
|
82
|
+
simplifiedPage[propName] = simplifyPropertyValue(propValue);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return simplifiedPage;
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,6BAA6B;AA+B7B;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAAC,IAAoB,EAA2B,EAAE;IAC9E,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,OAAO;YACV,OAAQ,IAAI,CAAC,KAAkC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACnF,KAAK,WAAW;YACd,OAAQ,IAAI,CAAC,SAAsC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACvF,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,MAAgB,CAAA;QAC9B,KAAK,UAAU;YACb,OAAO,IAAI,CAAC,QAAmB,CAAA;QACjC,KAAK,QAAQ;YACX,OAAQ,IAAI,CAAC,MAAuC,EAAE,IAAI,CAAA;QAC5D,KAAK,cAAc;YACjB,OAAQ,IAAI,CAAC,YAAmC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACrE,KAAK,QAAQ;YACX,OAAQ,IAAI,CAAC,MAAuC,EAAE,IAAI,CAAA;QAC5D,KAAK,MAAM,CAAC,CAAC,CAAC;YACZ,MAAM,IAAI,GAAG,IAAI,CAAC,IAAuC,CAAA;YACzD,IAA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AC,UAAU,CAAC,EAAE,CAAC;gBACpE,cAAc,CAAC,QAAQ,CAAC,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;QAED,OAAO,cAAc,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type CreatePageParameters, type UpdatePageParameters } from '@notionhq/client';
|
|
2
|
+
import { type DataSourceObjectResponse } from '@notionhq/client/build/src/api-endpoints.js';
|
|
3
|
+
type DataSourceSchema = DataSourceObjectResponse['properties'];
|
|
4
|
+
type NotionProperties = CreatePageParameters['properties'];
|
|
5
|
+
type NotionUpdateProperties = UpdatePageParameters['properties'];
|
|
6
|
+
/**
|
|
7
|
+
* Parses a flat properties object from the 'create-pages' tool input
|
|
8
|
+
* into the format required by the Notion API.
|
|
9
|
+
* @param properties - A flat key-value map of properties from the tool input.
|
|
10
|
+
* @param dataSourceSchema - The schema of the parent data source.
|
|
11
|
+
* @returns A Notion `CreatePageParameters['properties']` object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parsePropertiesForCreate(properties: Record<string, string | number | boolean | null>, dataSourceSchema?: DataSourceSchema): NotionProperties;
|
|
14
|
+
/**
|
|
15
|
+
* Parses a flat properties object with special keys (e.g., 'date:deadline:start')
|
|
16
|
+
* from the 'update-page' tool input into the format required by the Notion API.
|
|
17
|
+
* @param properties - A flat key-value map with special-cased keys from the tool input [1].
|
|
18
|
+
* @param schema - The schema of the data source the page belongs to.
|
|
19
|
+
* @returns A Notion `NotionUpdateProperties` object.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parsePropertiesForUpdate(properties: Record<string, string | number | boolean | null>, schema: DataSourceSchema): NotionUpdateProperties;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=property-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-parser.d.ts","sourceRoot":"","sources":["../../src/lib/property-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvF,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,6CAA6C,CAAA;AAE3F,KAAK,gBAAgB,GAAG,wBAAwB,CAAC,YAAY,CAAC,CAAA;AAC9D,KAAK,gBAAgB,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAA;AAC1D,KAAK,sBAAsB,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAA;AAEhE;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAC5D,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,gBAAgB,CA2FlB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAC5D,MAAM,EAAE,gBAAgB,GACvB,sBAAsB,CAoHxB"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { logger } from '@mcp-monorepo/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a flat properties object from the 'create-pages' tool input
|
|
4
|
+
* into the format required by the Notion API.
|
|
5
|
+
* @param properties - A flat key-value map of properties from the tool input.
|
|
6
|
+
* @param dataSourceSchema - The schema of the parent data source.
|
|
7
|
+
* @returns A Notion `CreatePageParameters['properties']` object.
|
|
8
|
+
*/
|
|
9
|
+
export function parsePropertiesForCreate(properties, dataSourceSchema) {
|
|
10
|
+
const notionProperties = {};
|
|
11
|
+
// Find the name of the 'title' property from the schema, if it exists [11].
|
|
12
|
+
const titleSchemaKey = dataSourceSchema
|
|
13
|
+
? Object.keys(dataSourceSchema).find((key) => dataSourceSchema[key]?.type === 'title')
|
|
14
|
+
: 'title';
|
|
15
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
16
|
+
// eslint-disable-next-line no-restricted-syntax -- User input
|
|
17
|
+
if (value === null || value === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
// For convenience, allow 'title' as a key and map it to the actual title property name [1].
|
|
20
|
+
if (key.toLowerCase() === 'title' && titleSchemaKey) {
|
|
21
|
+
notionProperties[titleSchemaKey] = {
|
|
22
|
+
title: [{ text: { content: String(value) } }],
|
|
23
|
+
};
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
// If no schema is available (e.g., for a workspace page), only the 'title' is valid [9].
|
|
27
|
+
if (!dataSourceSchema) {
|
|
28
|
+
if (key.toLowerCase() === 'title') {
|
|
29
|
+
notionProperties[key] = { title: [{ text: { content: String(value) } }] };
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
logger.warn(`Skipping property "${key}"; only 'title' is allowed for pages not in a database.`);
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const schema = dataSourceSchema[key];
|
|
37
|
+
if (!schema) {
|
|
38
|
+
logger.warn(`Skipping property "${key}" as it was not found in the data source schema.`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// Format the property based on its type from the schema [11].
|
|
42
|
+
switch (schema.type) {
|
|
43
|
+
case 'title':
|
|
44
|
+
notionProperties[key] = { title: [{ text: { content: String(value) } }] };
|
|
45
|
+
break;
|
|
46
|
+
case 'rich_text':
|
|
47
|
+
notionProperties[key] = { rich_text: [{ text: { content: String(value) } }] };
|
|
48
|
+
break;
|
|
49
|
+
case 'number':
|
|
50
|
+
notionProperties[key] = { number: Number(value) };
|
|
51
|
+
break;
|
|
52
|
+
case 'select':
|
|
53
|
+
notionProperties[key] = { select: { name: String(value) } };
|
|
54
|
+
break;
|
|
55
|
+
case 'status':
|
|
56
|
+
notionProperties[key] = { status: { name: String(value) } };
|
|
57
|
+
break;
|
|
58
|
+
case 'multi_select':
|
|
59
|
+
notionProperties[key] = {
|
|
60
|
+
multi_select: String(value)
|
|
61
|
+
.split(',')
|
|
62
|
+
.map((name) => ({ name: name.trim() })),
|
|
63
|
+
};
|
|
64
|
+
break;
|
|
65
|
+
case 'date':
|
|
66
|
+
notionProperties[key] = { date: { start: String(value) } };
|
|
67
|
+
break;
|
|
68
|
+
case 'checkbox': {
|
|
69
|
+
const lowerValue = String(value).toLowerCase();
|
|
70
|
+
const boolValue = lowerValue === 'true' || lowerValue === 'yes' || value === 1 || value === true;
|
|
71
|
+
notionProperties[key] = { checkbox: boolValue };
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 'url':
|
|
75
|
+
notionProperties[key] = { url: String(value) };
|
|
76
|
+
break;
|
|
77
|
+
case 'email':
|
|
78
|
+
notionProperties[key] = { email: String(value) };
|
|
79
|
+
break;
|
|
80
|
+
case 'phone_number':
|
|
81
|
+
notionProperties[key] = { phone_number: String(value) };
|
|
82
|
+
break;
|
|
83
|
+
// Advanced types like relation, people, and files are complex and would require
|
|
84
|
+
// more specific input formats than string/number, often needing IDs.
|
|
85
|
+
// They are omitted here but can be extended if the tool input is enhanced.
|
|
86
|
+
case 'relation':
|
|
87
|
+
case 'people':
|
|
88
|
+
case 'files':
|
|
89
|
+
default:
|
|
90
|
+
logger.warn(`Unsupported property type "${schema.type}" for key "${key}" during creation.`);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return notionProperties;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parses a flat properties object with special keys (e.g., 'date:deadline:start')
|
|
98
|
+
* from the 'update-page' tool input into the format required by the Notion API.
|
|
99
|
+
* @param properties - A flat key-value map with special-cased keys from the tool input [1].
|
|
100
|
+
* @param schema - The schema of the data source the page belongs to.
|
|
101
|
+
* @returns A Notion `NotionUpdateProperties` object.
|
|
102
|
+
*/
|
|
103
|
+
export function parsePropertiesForUpdate(properties, schema) {
|
|
104
|
+
const notionProperties = {};
|
|
105
|
+
const groupedComplexProps = {};
|
|
106
|
+
// 1. Group complex, colon-separated properties like 'date' and 'place' [1].
|
|
107
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
108
|
+
const parts = key.split(':');
|
|
109
|
+
if (parts.length > 1 && (parts[0] === 'date' || parts[0] === 'place')) {
|
|
110
|
+
const [type, propName, ...rest] = parts;
|
|
111
|
+
const part = rest.join(':'); // Join the rest in case property name has a colon
|
|
112
|
+
if (!groupedComplexProps[propName]) {
|
|
113
|
+
groupedComplexProps[propName] = { type: type, data: {} };
|
|
114
|
+
}
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
groupedComplexProps[propName].data[part] = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// 2. Process grouped complex properties
|
|
121
|
+
for (const [name, { type, data }] of Object.entries(groupedComplexProps)) {
|
|
122
|
+
if (type === 'date') {
|
|
123
|
+
const dateObj = { start: data.start };
|
|
124
|
+
if (data.end)
|
|
125
|
+
dateObj.end = data.end;
|
|
126
|
+
// eslint-disable-next-line
|
|
127
|
+
notionProperties[name] = { date: data.start === null ? null : dateObj };
|
|
128
|
+
}
|
|
129
|
+
else if (type === 'place') {
|
|
130
|
+
// For a place to be valid, latitude and longitude are required [11].
|
|
131
|
+
if (typeof data.latitude === 'number' && typeof data.longitude === 'number') {
|
|
132
|
+
const placeObj = {
|
|
133
|
+
lat: data.latitude,
|
|
134
|
+
lon: data.longitude,
|
|
135
|
+
};
|
|
136
|
+
if (data.name)
|
|
137
|
+
placeObj.name = String(data.name);
|
|
138
|
+
if (data.address)
|
|
139
|
+
placeObj.address = String(data.address);
|
|
140
|
+
if (data.google_place_id)
|
|
141
|
+
placeObj.google_place_id = String(data.google_place_id);
|
|
142
|
+
notionProperties[name] = { place: placeObj };
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
logger.warn(`Skipping place property "${name}" due to missing or invalid latitude/longitude.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// 3. Process simple and standard properties
|
|
150
|
+
for (const [name, value] of Object.entries(properties)) {
|
|
151
|
+
if (name.includes(':'))
|
|
152
|
+
continue; // Skip keys already processed in the grouping step.
|
|
153
|
+
const propSchema = schema[name];
|
|
154
|
+
const propType = propSchema?.type ?? (name.toLowerCase() === 'title' ? 'title' : undefined);
|
|
155
|
+
if (!propType) {
|
|
156
|
+
logger.warn(`Could not determine type for property "${name}". Skipping update.`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
/* eslint-disable no-restricted-syntax */
|
|
160
|
+
switch (propType) {
|
|
161
|
+
case 'title':
|
|
162
|
+
notionProperties[name] = { title: [{ text: { content: String(value) } }] };
|
|
163
|
+
break;
|
|
164
|
+
case 'rich_text':
|
|
165
|
+
notionProperties[name] = { rich_text: [{ text: { content: String(value ?? '') } }] };
|
|
166
|
+
break;
|
|
167
|
+
case 'number':
|
|
168
|
+
notionProperties[name] = { number: value === null ? null : Number(value) };
|
|
169
|
+
break;
|
|
170
|
+
case 'select':
|
|
171
|
+
notionProperties[name] = { select: value === null ? null : { name: String(value) } };
|
|
172
|
+
break;
|
|
173
|
+
case 'status':
|
|
174
|
+
notionProperties[name] = { status: value === null ? null : { name: String(value) } };
|
|
175
|
+
break;
|
|
176
|
+
case 'checkbox': {
|
|
177
|
+
const boolValue = String(value).toLowerCase() === '__yes__' || String(value).toLowerCase() === 'true';
|
|
178
|
+
notionProperties[name] = { checkbox: boolValue };
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case 'url':
|
|
182
|
+
notionProperties[name] = { url: value === null ? null : String(value) };
|
|
183
|
+
break;
|
|
184
|
+
case 'email':
|
|
185
|
+
notionProperties[name] = { email: value === null ? null : String(value) };
|
|
186
|
+
break;
|
|
187
|
+
case 'phone_number':
|
|
188
|
+
notionProperties[name] = { phone_number: value === null ? null : String(value) };
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
if (!Object.keys(groupedComplexProps).includes(name)) {
|
|
192
|
+
logger.warn(`Updates for property type "${propType}" are not supported. Skipping "${name}".`);
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
/* eslint-enable no-restricted-syntax */
|
|
197
|
+
}
|
|
198
|
+
return notionProperties;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=property-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-parser.js","sourceRoot":"","sources":["../../src/lib/property-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAQ7C;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAA4D,EAC5D,gBAAmC;IAEnC,MAAM,gBAAgB,GAAqB,EAAE,CAAA;IAE7C,4EAA4E;IAC5E,MAAM,cAAc,GAAG,gBAAgB;QACrC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC;QACtF,CAAC,CAAC,OAAO,CAAA;IAEX,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,8DAA8D;QAC9D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QAEnD,4FAA4F;QAC5F,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,cAAc,EAAE,CAAC;YACpD,gBAAgB,CAAC,cAAc,CAAC,GAAG;gBACjC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;aAC9C,CAAA;YACD,SAAQ;QACV,CAA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,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;gBAChF,MAAK;YACP;gBACE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACrD,MAAM,CAAC,IAAI,CAAC,8BAA8B,QAAQ,kCAAkC,IAAI,IAAI,CAAC,CAAA;gBAC/F,CAAC;gBACD,MAAK;QACT,CAAC;QACD,wCAAwC;IAC1C,CAAC;IAED,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type BlockObjectResponse, type DatabaseObjectResponse, type DataSourceObjectResponse, type PageObjectResponse } from '@notionhq/client/build/src/api-endpoints.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formats a Notion Page object and its content into a single Markdown string [5].
|
|
4
|
+
* @param page - The fetched Page object from the Notion API.
|
|
5
|
+
* @param blocks - The content blocks of the page.
|
|
6
|
+
* @returns A promise that resolves to a comprehensive Markdown string representing the page.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatPageToMarkdown(page: PageObjectResponse, blocks: BlockObjectResponse[]): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Formats a Notion Database object and its data sources into a Markdown string that describes its schemas [10].
|
|
11
|
+
* @param database - The fetched Database object from the Notion API.
|
|
12
|
+
* @param data_sources - An array of fetched Data Source objects belonging to the database.
|
|
13
|
+
* @returns A promise that resolves to a Markdown string representing the database and its data source schemas.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatDatabaseToMarkdown(database: DatabaseObjectResponse, data_sources: DataSourceObjectResponse[]): Promise<string>;
|
|
16
|
+
//# sourceMappingURL=response-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-formatter.d.ts","sourceRoot":"","sources":["../../src/lib/response-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACxB,MAAM,6CAA6C,CAAA;AAoGpD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBnH;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,sBAAsB,EAChC,YAAY,EAAE,wBAAwB,EAAE,GACvC,OAAO,CAAC,MAAM,CAAC,CA8CjB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { notionToMarkdown } from './markdown-converter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formats a single Notion page property into a readable string based on its type [2].
|
|
4
|
+
* @param name - The name of the property.
|
|
5
|
+
* @param prop - The property value object from the Notion API.
|
|
6
|
+
* @returns A formatted string representing the property's value.
|
|
7
|
+
*/
|
|
8
|
+
function formatPageProperty(name, prop) {
|
|
9
|
+
let value = 'Unsupported type';
|
|
10
|
+
switch (prop.type) {
|
|
11
|
+
case 'title':
|
|
12
|
+
value = prop.title.map((t) => t.plain_text).join('');
|
|
13
|
+
break;
|
|
14
|
+
case 'rich_text':
|
|
15
|
+
value = prop.rich_text.map((t) => t.plain_text).join('');
|
|
16
|
+
break;
|
|
17
|
+
case 'number':
|
|
18
|
+
value = prop.number;
|
|
19
|
+
break;
|
|
20
|
+
case 'select':
|
|
21
|
+
value = prop.select?.name;
|
|
22
|
+
break;
|
|
23
|
+
case 'multi_select':
|
|
24
|
+
value = prop.multi_select.map((s) => s.name).join(', ');
|
|
25
|
+
break;
|
|
26
|
+
case 'status':
|
|
27
|
+
value = prop.status?.name;
|
|
28
|
+
break;
|
|
29
|
+
case 'date':
|
|
30
|
+
if (prop.date) {
|
|
31
|
+
value = prop.date.end ? `${prop.date.start} -> ${prop.date.end}` : prop.date.start;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
value = undefined;
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'people':
|
|
38
|
+
value = prop.people.map((p) => ('name' in p ? p.name : p.id)).join(', ');
|
|
39
|
+
break;
|
|
40
|
+
case 'files':
|
|
41
|
+
value = prop.files.map((f) => f.name).join(', ');
|
|
42
|
+
break;
|
|
43
|
+
case 'checkbox':
|
|
44
|
+
value = prop.checkbox ? 'Yes' : 'No';
|
|
45
|
+
break;
|
|
46
|
+
case 'url':
|
|
47
|
+
value = prop.url;
|
|
48
|
+
break;
|
|
49
|
+
case 'email':
|
|
50
|
+
value = prop.email;
|
|
51
|
+
break;
|
|
52
|
+
case 'phone_number':
|
|
53
|
+
value = prop.phone_number;
|
|
54
|
+
break;
|
|
55
|
+
case 'formula': {
|
|
56
|
+
const { formula } = prop;
|
|
57
|
+
if (formula.type === 'string')
|
|
58
|
+
value = formula.string;
|
|
59
|
+
if (formula.type === 'number')
|
|
60
|
+
value = formula.number;
|
|
61
|
+
if (formula.type === 'boolean')
|
|
62
|
+
value = formula.boolean ? 'Yes' : 'No';
|
|
63
|
+
if (formula.type === 'date')
|
|
64
|
+
value = formula.date?.start;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'relation':
|
|
68
|
+
value = `${prop.relation.length} relation(s)`;
|
|
69
|
+
break;
|
|
70
|
+
case 'created_time':
|
|
71
|
+
value = new Date(prop.created_time).toLocaleString();
|
|
72
|
+
break;
|
|
73
|
+
case 'last_edited_time':
|
|
74
|
+
value = new Date(prop.last_edited_time).toLocaleString();
|
|
75
|
+
break;
|
|
76
|
+
case 'created_by':
|
|
77
|
+
value = 'id' in prop.created_by ? prop.created_by.id : '';
|
|
78
|
+
break;
|
|
79
|
+
case 'last_edited_by':
|
|
80
|
+
value = 'id' in prop.last_edited_by ? prop.last_edited_by.id : '';
|
|
81
|
+
break;
|
|
82
|
+
case 'rollup': {
|
|
83
|
+
const rollup = prop.rollup;
|
|
84
|
+
if (rollup.type === 'number')
|
|
85
|
+
value = rollup.number;
|
|
86
|
+
else if (rollup.type === 'date')
|
|
87
|
+
value = rollup.date?.start;
|
|
88
|
+
else if (rollup.type === 'array')
|
|
89
|
+
value = `${rollup.array.length} items`;
|
|
90
|
+
else
|
|
91
|
+
value = `Unsupported rollup type`;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'unique_id':
|
|
95
|
+
value = prop.unique_id.prefix ? `${prop.unique_id.prefix}-${prop.unique_id.number}` : `${prop.unique_id.number}`;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
99
|
+
return `- **${name}**: ${value ?? 'null'}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Formats a Notion Page object and its content into a single Markdown string [5].
|
|
103
|
+
* @param page - The fetched Page object from the Notion API.
|
|
104
|
+
* @param blocks - The content blocks of the page.
|
|
105
|
+
* @returns A promise that resolves to a comprehensive Markdown string representing the page.
|
|
106
|
+
*/
|
|
107
|
+
export async function formatPageToMarkdown(page, blocks) {
|
|
108
|
+
const contentMarkdown = await notionToMarkdown(blocks);
|
|
109
|
+
const propertiesMarkdown = Object.entries(page.properties)
|
|
110
|
+
.map(([name, prop]) => formatPageProperty(name, prop))
|
|
111
|
+
.join('\n');
|
|
112
|
+
const icon = page.icon?.type === 'emoji' ? `${page.icon.emoji} ` : '';
|
|
113
|
+
return `
|
|
114
|
+
# ${icon}Page: ${page.url}
|
|
115
|
+
|
|
116
|
+
## Properties
|
|
117
|
+
${propertiesMarkdown}
|
|
118
|
+
|
|
119
|
+
## Content
|
|
120
|
+
---
|
|
121
|
+
${contentMarkdown}
|
|
122
|
+
`.trim();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Formats a Notion Database object and its data sources into a Markdown string that describes its schemas [10].
|
|
126
|
+
* @param database - The fetched Database object from the Notion API.
|
|
127
|
+
* @param data_sources - An array of fetched Data Source objects belonging to the database.
|
|
128
|
+
* @returns A promise that resolves to a Markdown string representing the database and its data source schemas.
|
|
129
|
+
*/
|
|
130
|
+
export async function formatDatabaseToMarkdown(database, data_sources) {
|
|
131
|
+
const title = database.title.map((t) => t.plain_text).join('');
|
|
132
|
+
const icon = database.icon?.type === 'emoji' ? `${database.icon.emoji} ` : '';
|
|
133
|
+
const dataSourcesMarkdown = data_sources
|
|
134
|
+
.map((ds) => {
|
|
135
|
+
const dsTitle = ds.title.map((t) => t.plain_text).join('');
|
|
136
|
+
const propertiesMarkdown = Object.entries(ds.properties)
|
|
137
|
+
.map(([name, prop]) => {
|
|
138
|
+
let details = `(type: \`${prop.type}\`, id: \`${prop.id}\`)`;
|
|
139
|
+
let options = [];
|
|
140
|
+
// For select, multi_select, and status, list the available options [13].
|
|
141
|
+
if (prop.type === 'select') {
|
|
142
|
+
options = prop.select.options;
|
|
143
|
+
}
|
|
144
|
+
else if (prop.type === 'multi_select') {
|
|
145
|
+
options = prop.multi_select.options;
|
|
146
|
+
}
|
|
147
|
+
else if (prop.type === 'status') {
|
|
148
|
+
options = prop.status.options;
|
|
149
|
+
}
|
|
150
|
+
if (options.length > 0) {
|
|
151
|
+
const optionsString = options.map((o) => o.name).join(', ');
|
|
152
|
+
details += `\n - Options: ${optionsString}`;
|
|
153
|
+
}
|
|
154
|
+
return ` - **${name}** ${details}`;
|
|
155
|
+
})
|
|
156
|
+
.join('\n');
|
|
157
|
+
return `
|
|
158
|
+
### Data Source: ${dsTitle}
|
|
159
|
+
> To query this data source, use its URL: collection://${ds.id}
|
|
160
|
+
|
|
161
|
+
**Schema / Properties:**
|
|
162
|
+
${propertiesMarkdown}
|
|
163
|
+
`.trim();
|
|
164
|
+
})
|
|
165
|
+
.join('\n\n');
|
|
166
|
+
return `
|
|
167
|
+
# ${icon}Database: ${title}
|
|
168
|
+
> To query pages from this database, use one of the data source URLs below.
|
|
169
|
+
|
|
170
|
+
${dataSourcesMarkdown}
|
|
171
|
+
`.trim();
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=response-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-formatter.js","sourceRoot":"","sources":["../../src/lib/response-formatter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAM1D;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAE,IAA8C;IACtF,IAAI,KAAK,GAAuC,kBAAkB,CAAA;IAElE,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,OAAO;YACV,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACpD,MAAK;QACP,KAAK,WAAW;YACd,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACxD,MAAK;QACP,KAAK,QAAQ;YACX,KAAK,GAAG,IAAI,CAAC,MAAM,CAAA;YACnB,MAAK;QACP,KAAK,QAAQ;YACX,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAA;YACzB,MAAK;QACP,KAAK,cAAc;YACjB,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvD,MAAK;QACP,KAAK,QAAQ;YACX,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAA;YACzB,MAAK;QACP,KAAK,MAAM;YACT,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,C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C,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAC3D,OAAO,IAAI,oBAAoB,aAAa,EAAE,CAAA;YAChD,CAAC;YAED,OAAO,SAAS,IAAI,MAAM,OAAO,EAAE,CAAA;QACrC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAA;QAEb,OAAO;mBACM,OAAO;yDAC+B,EAAE,CAAC,EAAE;;;EAG5D,kBAAkB;OACb,CAAC,IAAI,EAAE,CAAA;IACV,CAAC,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAA;IAEf,OAAO;IACL,IAAI,aAAa,KAAK;;;EAGxB,mBAAmB;GAClB,CAAC,IAAI,EAAE,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the structure for metadata associated with a single synchronized page.
|
|
3
|
+
* 'undefined' for lastEdited indicates the page has been discovered but not yet processed.
|
|
4
|
+
*/
|
|
5
|
+
export type SyncedPageInfo = {
|
|
6
|
+
lastEdited: string | undefined;
|
|
7
|
+
title: string | undefined;
|
|
8
|
+
url: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Defines the structure of the entire synchronization state file.
|
|
12
|
+
*/
|
|
13
|
+
export type SyncState = {
|
|
14
|
+
pages: Record<string, SyncedPageInfo>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Loads the synchronization state from the file system.
|
|
18
|
+
* If the state file does not exist, it returns a default initial state.
|
|
19
|
+
* @returns A promise that resolves to the loaded or initial SyncState.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadSyncState(): Promise<SyncState>;
|
|
22
|
+
/**
|
|
23
|
+
* Saves the provided synchronization state to the file system.
|
|
24
|
+
* This function is critical for maintaining progress across restarts.
|
|
25
|
+
* @param state - The SyncState object to save.
|
|
26
|
+
* @returns A promise that resolves when the file has been written.
|
|
27
|
+
*/
|
|
28
|
+
export declare function saveSyncState(state: SyncState): Promise<void>;
|
|
29
|
+
//# sourceMappingURL=sync-state-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-state-manager.d.ts","sourceRoot":"","sources":["../../src/lib/sync-state-manager.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACtC,CAAA;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,SAAS,CAAC,CAiBxD;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CASnE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { logger } from '@mcp-monorepo/shared';
|
|
3
|
+
import { SYNC_STATE_PATH } from './config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Loads the synchronization state from the file system.
|
|
6
|
+
* If the state file does not exist, it returns a default initial state.
|
|
7
|
+
* @returns A promise that resolves to the loaded or initial SyncState.
|
|
8
|
+
*/
|
|
9
|
+
export async function loadSyncState() {
|
|
10
|
+
try {
|
|
11
|
+
const fileContent = await readFile(SYNC_STATE_PATH, 'utf-8');
|
|
12
|
+
// A simple validation to ensure the loaded data has the expected structure.
|
|
13
|
+
const parsed = JSON.parse(fileContent);
|
|
14
|
+
if (typeof parsed === 'object' && parsed && 'pages' in parsed) {
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
throw new Error('Loaded sync state has an invalid structure.');
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
21
|
+
logger.info('Sync state file not found. Creating a new one.');
|
|
22
|
+
return { pages: {} };
|
|
23
|
+
}
|
|
24
|
+
logger.error('Failed to load or parse sync state file. Starting with a fresh state.', error);
|
|
25
|
+
return { pages: {} };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Saves the provided synchronization state to the file system.
|
|
30
|
+
* This function is critical for maintaining progress across restarts.
|
|
31
|
+
* @param state - The SyncState object to save.
|
|
32
|
+
* @returns A promise that resolves when the file has been written.
|
|
33
|
+
*/
|
|
34
|
+
export async function saveSyncState(state) {
|
|
35
|
+
try {
|
|
36
|
+
const jsonString = JSON.stringify(state, undefined, 2);
|
|
37
|
+
await writeFile(SYNC_STATE_PATH, jsonString, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logger.error('CRITICAL: Failed to save sync state file. Progress may be lost.', error);
|
|
41
|
+
// Re-throwing the error allows the calling function to handle the failure.
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=sync-state-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-state-manager.js","sourceRoot":"","sources":["../../src/lib/sync-state-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAmB7C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAA;QAC5D,4EAA4E;QAC5E,MAA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