From ddba85a28154488b6f5d6a8a733bb8282c1f82dd Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Sat, 30 Aug 2025 12:12:44 -0400 Subject: [PATCH 1/2] restore type references in roam --- apps/obsidian/scripts/publish.ts | 8 ++-- apps/roam/scripts/publish.ts | 4 +- apps/roam/src/utils/cleanupOrphanedNodes.ts | 41 +++++++++---------- apps/roam/src/utils/syncDgNodesToSupabase.ts | 14 +++---- .../upsertNodesAsContentWithEmbeddings.ts | 7 ++-- 5 files changed, 36 insertions(+), 38 deletions(-) diff --git a/apps/obsidian/scripts/publish.ts b/apps/obsidian/scripts/publish.ts index 17a9e8278..3acc8b5b4 100644 --- a/apps/obsidian/scripts/publish.ts +++ b/apps/obsidian/scripts/publish.ts @@ -4,7 +4,7 @@ import path from "path"; import { exec } from "child_process"; import util from "util"; // https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm -// TODO: Change to apps/obsidian to ESM +// TODO if possible: change apps/obsidian to ESM. Use require until then. // import { Octokit } from "@octokit/core"; const { Octokit } = require("@octokit/core"); import os from "os"; @@ -162,16 +162,16 @@ Release Type Auto-Detection: BRAT Version Priority: BRAT uses alphabetical ordering, so alpha < beta < stable - 0.1.0-alpha-feature (lowest priority) - - 0.1.0-beta.1 (higher priority) + - 0.1.0-beta.1 (higher priority) - 0.1.0 (highest priority) Examples: # Internal release with custom name tsx scripts/publish-obsidian.ts --version 0.1.0-alpha-canvas --release-name "Canvas Integration Feature" - + # Beta release with feature description tsx scripts/publish-obsidian.ts --version 1.0.0-beta.1 --release-name "Beta: New Graph View" - + # Stable release (uses default name) tsx scripts/publish-obsidian.ts --version 1.0.0 `); diff --git a/apps/roam/scripts/publish.ts b/apps/roam/scripts/publish.ts index 382e5b227..368800f55 100644 --- a/apps/roam/scripts/publish.ts +++ b/apps/roam/scripts/publish.ts @@ -3,9 +3,7 @@ import * as path from "path"; import * as fs from "fs"; import { exec } from "child_process"; import util from "util"; -// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm -// import { Octokit } from "@octokit/core"; -// import { createAppAuth } from "@octokit/auth-app"; +// Module configuration in roam does not allow ESM import, we need to use require here. const { Octokit } = require("@octokit/core"); const { createAppAuth } = require("@octokit/auth-app"); diff --git a/apps/roam/src/utils/cleanupOrphanedNodes.ts b/apps/roam/src/utils/cleanupOrphanedNodes.ts index 49f70684b..95b9a1085 100644 --- a/apps/roam/src/utils/cleanupOrphanedNodes.ts +++ b/apps/roam/src/utils/cleanupOrphanedNodes.ts @@ -1,6 +1,5 @@ -import { type SupabaseContext } from "./supabaseContext"; -// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm -type DGSupabaseClient = any; +import type { SupabaseContext } from "./supabaseContext"; +import type { DGSupabaseClient } from "@repo/database/lib/client"; const getAllNodesFromSupabase = async ( supabaseClient: DGSupabaseClient, @@ -22,7 +21,7 @@ const getAllNodesFromSupabase = async ( return []; } - const schemaIds = schemas.map((s: { id: string }) => s.id); + const schemaIds = schemas.map((s: { id: number }) => s.id); let nodeResult: string[] = []; if (schemaIds.length > 0) { @@ -50,10 +49,10 @@ const getAllNodesFromSupabase = async ( nodeResult = conceptResponse.data ?.map( - (c: { Content?: { source_local_id: string } }) => - c.Content?.source_local_id, + (c: { Content?: { source_local_id: string | null } }) => + c.Content?.source_local_id || null, ) - .filter((id: string): id is string => !!id) || []; + .filter((id: string | null): id is string => !!id) || []; } const blockContentResponse = await supabaseClient @@ -73,8 +72,8 @@ const getAllNodesFromSupabase = async ( const blockResult = blockContentResponse.data - ?.map((c: { source_local_id: string }) => c.source_local_id) - .filter((id: string): id is string => !!id) || []; + ?.map((c: { source_local_id: string | null }) => c.source_local_id) + .filter((id: string | null): id is string => !!id) || []; const result = [...new Set([...nodeResult, ...blockResult])]; @@ -115,10 +114,10 @@ const getAllNodeSchemasFromSupabase = async ( return ( data ?.map( - (c: { Content?: { source_local_id: string } }) => - c.Content?.source_local_id, + (c: { Content?: { source_local_id: string | null } }) => + c.Content?.source_local_id || null, ) - .filter((id: string): id is string => !!id) || [] + .filter((id: string | null): id is string => !!id) || [] ); } catch (error) { console.error("Error in getAllNodeSchemasFromSupabase:", error); @@ -133,7 +132,7 @@ const getNonExistentRoamUids = (nodeUids: string[]): string[] => { } const results = window.roamAlphaAPI.q( - `[:find ?uid + `[:find ?uid :in $ [?uid ...] :where (not [_ :block/uid ?uid])]`, nodeUids, @@ -162,7 +161,7 @@ const deleteNodesFromSupabase = async ( console.error("Failed to get content from Supabase:", contentError); } - const contentIds = contentData?.map((c: { id: string }) => c.id) || []; + const contentIds = contentData?.map((c: { id: number }) => c.id) || []; if (contentIds.length > 0) { const { error: conceptError } = await supabaseClient @@ -219,7 +218,7 @@ const deleteNodeSchemasFromSupabase = async ( return 0; } - const schemaContentIds = schemaContentData.map((c: { id: string }) => c.id); + const schemaContentIds = schemaContentData.map((c: { id: number }) => c.id); const { data: schemaConceptData, error: schemaConceptError } = await supabaseClient @@ -238,7 +237,7 @@ const deleteNodeSchemasFromSupabase = async ( } const schemaConceptIds = (schemaConceptData || []).map( - (c: { id: string }) => c.id, + (c: { id: number }) => c.id, ); let instanceConceptIds: number[] = []; @@ -263,11 +262,11 @@ const deleteNodeSchemasFromSupabase = async ( } instanceConceptIds = (instanceConceptData || []).map( - (ic: { id: string }) => ic.id, + (ic: { id: number }) => ic.id, ); instanceContentIds = (instanceConceptData || []) - .map((ic: { represented_by_id: number }) => ic.represented_by_id) - .filter((x: number): x is number => typeof x === "number"); + .map((ic: { represented_by_id: number | null }) => ic.represented_by_id) + .filter((x: number | null): x is number => typeof x === "number"); if (instanceContentIds.length > 0) { const { data: instanceContentData, error: instanceContentLookupError } = @@ -284,8 +283,8 @@ const deleteNodeSchemasFromSupabase = async ( return 0; } instanceSourceLocalIds = (instanceContentData || []) - .map((c: { source_local_id: string }) => c.source_local_id) - .filter((id: string): id is string => !!id); + .map((c: { source_local_id: string | null }) => c.source_local_id) + .filter((id: string | null): id is string => !!id); } } diff --git a/apps/roam/src/utils/syncDgNodesToSupabase.ts b/apps/roam/src/utils/syncDgNodesToSupabase.ts index 61af1d921..31ff6db33 100644 --- a/apps/roam/src/utils/syncDgNodesToSupabase.ts +++ b/apps/roam/src/utils/syncDgNodesToSupabase.ts @@ -19,11 +19,11 @@ import { import { type OnloadArgs } from "roamjs-components/types"; import { fetchEmbeddingsForNodes } from "./upsertNodesAsContentWithEmbeddings"; import { convertRoamNodeToLocalContent } from "./upsertNodesAsContentWithEmbeddings"; -// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm -type LocalContentDataInput = any; -type DGSupabaseClient = any; -type Json = any; -type AccountLocalInput = any; +import type { DGSupabaseClient } from "@repo/database/lib/client"; +import type { Json, CompositeTypes } from "@repo/database/dbTypes"; + +type LocalContentDataInput = Partial>; +type AccountLocalInput = CompositeTypes<"account_local_input">; const SYNC_FUNCTION = "embedding"; const SYNC_INTERVAL = "45s"; @@ -157,7 +157,7 @@ const upsertNodeSchemaToContent = async ({ [?e :edit/time ?edit-time] [?e :edit/user ?eu] [(get-else $ ?eu :user/display-name "Unknown-person") ?author-name] - + ] `; //@ts-ignore - backend to be added to roamjs-components @@ -311,7 +311,7 @@ const getDgNodeTypes = (extensionAPI: OnloadArgs["extensionAPI"]) => { }; const getAllUsers = async (): Promise => { - const query = `[:find ?author_local_id ?author_name + const query = `[:find ?author_local_id ?author_name :keys author_local_id name :where [?user-eid :user/uid ?author_local_id] diff --git a/apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts b/apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts index 0c69cc0a4..829e792c2 100644 --- a/apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts +++ b/apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts @@ -2,9 +2,10 @@ import { type RoamDiscourseNodeData } from "./getAllDiscourseNodesSince"; import { type SupabaseContext } from "./supabaseContext"; import { nextApiRoot } from "@repo/utils/execContext"; -type LocalContentDataInput = any; -type DGSupabaseClient = any; -type Json = any; +import type { DGSupabaseClient } from "@repo/database/lib/client"; +import type { Json, CompositeTypes } from "@repo/database/dbTypes"; + +type LocalContentDataInput = Partial>; const EMBEDDING_BATCH_SIZE = 200; const EMBEDDING_MODEL = "openai_text_embedding_3_small_1536"; From 0e75ac71007559f811f4e781a628e109c2324fa5 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Sat, 30 Aug 2025 13:03:15 -0400 Subject: [PATCH 2/2] coderabbit suggestion --- apps/roam/src/utils/syncDgNodesToSupabase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/roam/src/utils/syncDgNodesToSupabase.ts b/apps/roam/src/utils/syncDgNodesToSupabase.ts index 31ff6db33..09a1ec9e1 100644 --- a/apps/roam/src/utils/syncDgNodesToSupabase.ts +++ b/apps/roam/src/utils/syncDgNodesToSupabase.ts @@ -51,7 +51,7 @@ export const endSyncTask = async ( } const { error } = await supabaseClient.rpc("end_sync_task", { s_target: context.spaceId, - s_function: "embedding", + s_function: SYNC_FUNCTION, s_worker: worker, s_status: status, });