import { Block, PropertyValue, StringFormulaValue } from "@notionhq/client/build/src/api-types"; export function isEmptyOrSpaces(value: string) { return (!value || value == undefined || value == "" || value.length == 0); } export function ProcessNotionBlock(blocks: Block[]) { return blocks.map(block => { switch (block.type) { case "paragraph": return { id: block.id, richText: block[block.type].text }; case 'heading_1': return { id: block.id, richText: block[block.type].text }; case 'heading_2': return { id: block.id, richText: block[block.type].text }; case 'heading_3': return { id: block.id, richText: block[block.type].text }; case 'bulleted_list_item': return { id: block.id, richText: block[block.type].text }; case 'numbered_list_item': return { id: block.id, richText: block[block.type].text }; case 'to_do': return { id: block.id, richText: block[block.type].text }; case 'toggle': return { id: block.id, richText: block[block.type].text }; case 'child_page': { let title = block[block.type].title; title && console.warn(`not handling child page: ${title}`); return null; // SyncInfo(result.id, `# ${prettyText}`); } case 'unsupported': { return { id: block.id, richText: null }; // await SyncNotionDatabase(block.id, miroWidgetInfo); } } }) } export function ProcessNotionProperty(property: [key: string, value: PropertyValue][]) { return property.map(([key, value]) => { switch (value.type) { case "title": return { id: value.id, richText: value[value.type], name: key }; case 'rich_text': return { id: value.id, richText: value[value.type], name: key }; case 'select': return { id: value.id, text: value[value.type].name, name: key }; case 'formula': return { id: value.id, text: (value.formula as StringFormulaValue).string, name: key }; default: return null; } }) } export type MiroWidgetInfo = { id: string, type: string }; export interface MiroSyncInfo { [notionPageId: string]: { [notionPropertyId: string]: MiroWidgetInfo[] } } export function ProcessMiroWidget(data: MiroWidget[], miro_app_id: string) { let info: MiroSyncInfo = {}; data.forEach(w => { if (w.metadata == null) return; if (w.metadata[miro_app_id] == null) return; // console.log(w.metadata[miro_app_id]); let notionPageId = w.metadata[miro_app_id].notionPageId as string; let notionPropertyId = w.metadata[miro_app_id].notionPropertyId as string; let obj = { id: w.id, type: w.type }; if (notionPageId === undefined) return; if (info[notionPageId] === undefined) info[notionPageId] = {}; if (notionPropertyId !== undefined) { if (info[notionPageId][notionPropertyId] !== undefined) info[notionPageId][notionPropertyId] = [...info[notionPageId][notionPropertyId], obj]; else info[notionPageId][notionPropertyId] = [obj]; } else { if (info[notionPageId]["_"] !== undefined) info[notionPageId]["_"] = [...info[notionPageId]["_"], obj]; else info[notionPageId]["_"] = [obj]; } }); return info; } export function sleep(ms: number) { return new Promise(resolve => (setTimeout(resolve, ms))); }