MCPcopy Create free account
hub / github.com/brianlovin/github-stars-notion-sync / createViews

Function createViews

scripts/setup.ts:87–114  ·  view source on GitHub ↗
(notion: Client, databaseId: string, dataSourceId: string)

Source from the content-addressed store, hash-verified

85}
86
87async function createViews(notion: Client, databaseId: string, dataSourceId: string): Promise<void> {
88 const ds = await notion.request<any>({ path: `data_sources/${dataSourceId}`, method: "get" });
89 const propIds: Record<string, string> = {};
90 for (const [name, def] of Object.entries((ds?.properties ?? {}) as Record<string, any>)) {
91 if (def?.id) propIds[name] = def.id;
92 }
93
94 const ourViewIds = new Set<string>();
95 for (const v of viewPayloads(databaseId, dataSourceId, propIds)) {
96 try {
97 const created = await notion.request<any>({ path: "views", method: "post", body: v });
98 if (created?.id) ourViewIds.add(created.id);
99 ok(`View "${v.name}"`);
100 } catch (e: any) {
101 fail(`View "${v.name}" failed: ${e.message}`);
102 }
103 }
104
105 // Remove the auto-created default view so users land on "All Repos".
106 try {
107 const listed = await notion.request<any>({ path: `views?database_id=${databaseId}`, method: "get" });
108 for (const v of (listed?.results ?? []) as Array<{ id: string; name?: string }>) {
109 if (ourViewIds.has(v.id)) continue;
110 await notion.request({ path: `views/${v.id}`, method: "delete" });
111 ok(`Removed default view`);
112 }
113 } catch { /* non-fatal */ }
114}
115
116// ---------- Env-state builder ---------------------------------------------
117

Callers 1

mainFunction · 0.85

Calls 3

viewPayloadsFunction · 0.85
okFunction · 0.85
failFunction · 0.85

Tested by

no test coverage detected