Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions apps/obsidian/src/utils/importNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getLoggedInClient, getSupabaseContext } from "./supabaseContext";
import type { DiscourseNode, ImportableNode } from "~/types";
import { QueryEngine } from "~/services/QueryEngine";
import { spaceUriAndLocalIdToRid, ridToSpaceUriAndLocalId } from "./rid";
import type { PostgrestResponse } from "@supabase/supabase-js";
import type { Tables } from "@repo/database/dbTypes";

export const getAvailableGroupIds = async (
client: DGSupabaseClient,
Expand Down Expand Up @@ -191,10 +193,10 @@ export const getSpaceNameFromIds = async (
return new Map();
}

const { data, error } = await client
.from("Space")
const { data, error } = (await client
.from("my_spaces")
.select("id, name")
.in("id", spaceIds);
.in("id", spaceIds)) as PostgrestResponse<Tables<"Space">>;

if (error) {
console.error("Error fetching space names:", error);
Expand All @@ -217,10 +219,10 @@ export const getSpaceUris = async (
return new Map();
}

const { data, error } = await client
.from("Space")
const { data, error } = (await client
.from("my_spaces")
.select("id, url")
.in("id", spaceIds);
.in("id", spaceIds)) as PostgrestResponse<Tables<"Space">>;

if (error) {
console.error("Error fetching space urls:", error);
Expand Down Expand Up @@ -422,11 +424,13 @@ const fetchFileReferences = async ({
last_modified: number;
}>
> => {
const { data, error } = await client
.from("FileReference")
const { data, error } = (await client
.from("my_file_references")
.select("filepath, filehash, created, last_modified")
.eq("space_id", spaceId)
.eq("source_local_id", nodeInstanceId);
.eq("source_local_id", nodeInstanceId)) as PostgrestResponse<
Tables<"FileReference">
>;

if (error) {
console.error("Error fetching file references:", error);
Expand Down
4 changes: 2 additions & 2 deletions apps/obsidian/src/utils/publishNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const publishNodeToGroup = async ({
(frontmatter.publishedToGroups as undefined | string[]) || [];

const idResponse = await client
.from("Content")
.from("my_contents")
.select("last_modified")
.eq("source_local_id", nodeId)
.eq("space_id", spaceId)
Expand Down Expand Up @@ -356,7 +356,7 @@ export const publishNodeToGroup = async ({
// Always sync non-text assets when node is published to this group
const existingFiles: string[] = [];
const existingReferencesReq = await client
.from("FileReference")
.from("my_file_references")
.select("*")
.eq("space_id", spaceId)
.eq("source_local_id", nodeId);
Expand Down
12 changes: 6 additions & 6 deletions apps/obsidian/src/utils/syncDgNodesToSupabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const getAllNodeInstanceIdsFromSupabase = async (
): Promise<string[]> => {
try {
const { data, error } = await supabaseClient
.from("Content")
.from("my_contents")
.select("source_local_id")
.eq("space_id", spaceId)
.eq("scale", "document")
Expand Down Expand Up @@ -161,7 +161,7 @@ const getLastContentSyncTime = async (
spaceId: number,
): Promise<Date> => {
const { data } = await supabaseClient
.from("Content")
.from("my_contents")
.select("last_modified")
.eq("space_id", spaceId)
.order("last_modified", { ascending: false })
Expand All @@ -175,7 +175,7 @@ const getLastNodeSchemaSyncTime = async (
spaceId: number,
): Promise<Date> => {
const { data } = await supabaseClient
.from("Concept")
.from("my_concepts")
.select("last_modified")
.eq("space_id", spaceId)
.eq("is_schema", true)
Expand All @@ -191,7 +191,7 @@ const getLastRelationSchemaSyncTime = async (
spaceId: number,
): Promise<Date> => {
const { data } = await supabaseClient
.from("Concept")
.from("my_concepts")
.select("last_modified")
.eq("space_id", spaceId)
.eq("is_schema", true)
Expand All @@ -207,7 +207,7 @@ const getLastRelationSyncTime = async (
spaceId: number,
): Promise<Date> => {
const { data } = await supabaseClient
.from("Concept")
.from("my_concepts")
.select("last_modified")
.eq("space_id", spaceId)
.eq("is_schema", false)
Expand Down Expand Up @@ -265,7 +265,7 @@ const getExistingTitlesFromDatabase = async (
): Promise<Map<string, string>> => {
const { data: existingDirectContent, error: directError } =
await supabaseClient
.from("Content")
.from("my_contents")
.select("source_local_id, text")
.eq("space_id", spaceId)
.eq("variant", "direct")
Expand Down
22 changes: 12 additions & 10 deletions apps/roam/src/utils/cleanupOrphanedNodes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import type { PostgrestResponse } from "@supabase/supabase-js";
import type { SupabaseContext } from "./supabaseContext";
import type { DGSupabaseClient } from "@repo/database/lib/client";
import type { Tables } from "@repo/database/dbTypes";
import internalError from "./internalError";

const getAllNodesFromSupabase = async (
supabaseClient: DGSupabaseClient,
spaceId: number,
): Promise<string[]> => {
try {
const { data: schemas, error: schemasError } = await supabaseClient
.from("Concept")
const { data: schemas, error: schemasError } = (await supabaseClient
.from("my_concepts")
.select("id")
.eq("space_id", spaceId)
.eq("is_schema", true)
.eq("arity", 0);
.eq("arity", 0)) as PostgrestResponse<Tables<"Concept">>;

if (schemasError) {
internalError({
Expand All @@ -27,7 +29,7 @@ const getAllNodesFromSupabase = async (

if (schemaIds.length > 0) {
const conceptResponse = await supabaseClient
.from("Concept")
.from("my_concepts")
.select("source_local_id")
.eq("space_id", spaceId)
.eq("is_schema", false)
Expand All @@ -52,7 +54,7 @@ const getAllNodesFromSupabase = async (
}

const blockContentResponse = await supabaseClient
.from("Content")
.from("my_contents")
.select("source_local_id")
.eq("space_id", spaceId)
.eq("scale", "block")
Expand Down Expand Up @@ -86,7 +88,7 @@ const getAllNodeSchemasFromSupabase = async (
): Promise<string[]> => {
try {
const { data, error } = await supabaseClient
.from("Concept")
.from("my_concepts")
.select("source_local_id")
.eq("space_id", spaceId)
.eq("is_schema", true)
Expand Down Expand Up @@ -189,12 +191,12 @@ const deleteNodeSchemasFromSupabase = async (
if (uids.length === 0) return;

const { data: schemaConceptData, error: schemaConceptError } =
await supabaseClient
.from("Concept")
(await supabaseClient
.from("my_concepts")
.select("id")
.eq("space_id", spaceId)
.eq("is_schema", true)
.in("source_local_id", uids);
.in("source_local_id", uids)) as PostgrestResponse<Tables<"Concept">>;

if (schemaConceptError) {
internalError({
Expand All @@ -211,7 +213,7 @@ const deleteNodeSchemasFromSupabase = async (
if (schemaConceptIds.length > 0) {
const { data: instanceConceptData, error: instanceConceptError } =
await supabaseClient
.from("Concept")
.from("my_concepts")
.select("source_local_id")
.eq("space_id", spaceId)
.eq("is_schema", false)
Expand Down