Skip to content

Commit 9922963

Browse files
authored
ENG-633 Refactor: Move some functions to packages/database (#356)
* Code refactor: Move db utilities to database, and other to utils * various corrections from coderabbit * use type import on dbTypes (except constant). repo/database is a runtime dependency for roam
1 parent 2bd3690 commit 9922963

38 files changed

Lines changed: 107 additions & 68 deletions

File tree

apps/roam/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
},
1414
"license": "Apache-2.0",
1515
"devDependencies": {
16-
"@repo/database": "*",
1716
"@repo/tailwind-config": "*",
1817
"@types/contrast-color": "^1.0.0",
1918
"@types/react-vertical-timeline-component": "^3.3.3",
@@ -30,6 +29,7 @@
3029
"dependencies": {
3130
"@octokit/auth-app": "^7.1.4",
3231
"@octokit/core": "^6.1.3",
32+
"@repo/database": "*",
3333
"@repo/types": "*",
3434
"tldraw": "2.3.0",
3535
"@vercel/blob": "^0.27.0",

apps/roam/src/utils/supabaseContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserD
33
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
44
import getRoamUrl from "roamjs-components/dom/getRoamUrl";
55

6-
import { Enums } from "@repo/database/types.gen";
6+
import type { Enums } from "@repo/database/dbTypes";
77
import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage";
88
import getBlockProps from "~/utils/getBlockProps";
99
import setBlockProps from "~/utils/setBlockProps";
10-
import { type DGSupabaseClient } from "@repo/ui/lib/supabase/client";
10+
import type { DGSupabaseClient } from "@repo/database/lib/client";
1111
import {
1212
fetchOrCreateSpaceDirect,
1313
fetchOrCreatePlatformAccount,
1414
createLoggedInClient,
15-
} from "@repo/ui/lib/supabase/contextFunctions";
15+
} from "@repo/database/lib/contextFunctions";
1616

1717
declare const crypto: { randomUUID: () => string };
1818

apps/website/app/api/supabase/agent-identifier/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { NextResponse, NextRequest } from "next/server";
22

33
import { createClient } from "~/utils/supabase/server";
44
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
5+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
56
import {
67
createApiResponse,
78
handleRouteError,
89
defaultOptionsHandler,
9-
asPostgrestFailure,
1010
} from "~/utils/supabase/apiUtils";
11-
import { TablesInsert, Constants } from "@repo/database/types.gen.ts";
11+
import { type TablesInsert, Constants } from "@repo/database/dbTypes";
1212

1313
type AgentIdentifierDataInput = TablesInsert<"AgentIdentifier">;
1414
const { AgentIdentifierType } = Constants.public.Enums;

apps/website/app/api/supabase/content-embedding/batch/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { NextResponse, NextRequest } from "next/server";
22
import type { PostgrestResponse } from "@supabase/supabase-js";
33

44
import { createClient } from "~/utils/supabase/server";
5+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
56
import {
67
createApiResponse,
78
handleRouteError,
89
defaultOptionsHandler,
9-
asPostgrestFailure,
1010
} from "~/utils/supabase/apiUtils";
1111
import {
1212
processAndInsertBatch,

apps/website/app/api/supabase/content-embedding/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { NextResponse, NextRequest } from "next/server";
22
import type { PostgrestSingleResponse } from "@supabase/supabase-js";
33

44
import { createClient } from "~/utils/supabase/server";
5+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
56
import {
67
createApiResponse,
78
handleRouteError,
89
defaultOptionsHandler,
9-
asPostgrestFailure,
1010
} from "~/utils/supabase/apiUtils";
1111
import {
1212
getOrCreateEntity,

apps/website/app/api/supabase/content/batch/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NextResponse, NextRequest } from "next/server";
22
import type { PostgrestResponse } from "@supabase/supabase-js";
33
import { createClient } from "~/utils/supabase/server";
4+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
45
import {
56
createApiResponse,
67
handleRouteError,
78
defaultOptionsHandler,
8-
asPostgrestFailure,
99
} from "~/utils/supabase/apiUtils";
1010
import { validateAndInsertBatch } from "~/utils/supabase/dbUtils";
1111
import {

apps/website/app/api/supabase/content/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import type { PostgrestSingleResponse } from "@supabase/supabase-js";
33

44
import { createClient } from "~/utils/supabase/server";
55
import { getOrCreateEntity } from "~/utils/supabase/dbUtils";
6+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
67
import {
78
createApiResponse,
89
handleRouteError,
910
defaultOptionsHandler,
10-
asPostgrestFailure,
1111
} from "~/utils/supabase/apiUtils";
1212
import { contentInputValidation } from "~/utils/supabase/validators";
13-
import { Tables, TablesInsert } from "@repo/database/types.gen.ts";
13+
import type { Tables, TablesInsert } from "@repo/database/dbTypes";
1414

1515
type ContentDataInput = TablesInsert<"Content">;
1616
type ContentRecord = Tables<"Content">;

apps/website/app/api/supabase/document/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type { PostgrestSingleResponse } from "@supabase/supabase-js";
33

44
import { createClient } from "~/utils/supabase/server";
55
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
6+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
67
import {
78
createApiResponse,
89
handleRouteError,
910
defaultOptionsHandler,
10-
asPostgrestFailure,
1111
} from "~/utils/supabase/apiUtils";
12-
import { Tables, TablesInsert } from "@repo/database/types.gen.ts";
12+
import type { Tables, TablesInsert } from "@repo/database/dbTypes";
1313

1414
type DocumentDataInput = TablesInsert<"Document">;
1515
type DocumentRecord = Tables<"Document">;

apps/website/app/api/supabase/platform-account/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { NextResponse, NextRequest } from "next/server";
22

33
import { createClient } from "~/utils/supabase/server";
44
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
5+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
56
import {
67
createApiResponse,
78
handleRouteError,
89
defaultOptionsHandler,
9-
asPostgrestFailure,
1010
} from "~/utils/supabase/apiUtils";
11-
import { TablesInsert, Constants } from "@repo/database/types.gen.ts";
11+
import { type TablesInsert, Constants } from "@repo/database/dbTypes";
1212

1313
const { AgentType, Platform } = Constants.public.Enums;
1414

apps/website/app/api/supabase/similarity-rank/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse, NextRequest } from "next/server";
22
import { createClient } from "~/utils/supabase/server";
3+
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
34
import {
45
createApiResponse,
56
handleRouteError,
67
defaultOptionsHandler,
7-
asPostgrestFailure,
88
} from "~/utils/supabase/apiUtils";
99

1010
type SimilarityRankInput = {

0 commit comments

Comments
 (0)