Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/roam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@repo/database": "*",
"@repo/tailwind-config": "*",
"@types/contrast-color": "^1.0.0",
"@types/react-vertical-timeline-component": "^3.3.3",
Expand All @@ -30,6 +29,7 @@
"dependencies": {
"@octokit/auth-app": "^7.1.4",
"@octokit/core": "^6.1.3",
"@repo/database": "*",
"@repo/types": "*",
"tldraw": "2.3.0",
"@vercel/blob": "^0.27.0",
Expand Down
6 changes: 3 additions & 3 deletions apps/roam/src/utils/supabaseContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserD
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
import getRoamUrl from "roamjs-components/dom/getRoamUrl";

import { Enums } from "@repo/database/types.gen";
import type { Enums } from "@repo/database/dbTypes";
import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage";
import getBlockProps from "~/utils/getBlockProps";
import setBlockProps from "~/utils/setBlockProps";
import { type DGSupabaseClient } from "@repo/ui/lib/supabase/client";
import type { DGSupabaseClient } from "@repo/database/lib/client";
import {
fetchOrCreateSpaceDirect,
fetchOrCreatePlatformAccount,
createLoggedInClient,
} from "@repo/ui/lib/supabase/contextFunctions";
} from "@repo/database/lib/contextFunctions";

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

Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/api/supabase/agent-identifier/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { NextResponse, NextRequest } from "next/server";

import { createClient } from "~/utils/supabase/server";
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import { TablesInsert, Constants } from "@repo/database/types.gen.ts";
import { type TablesInsert, Constants } from "@repo/database/dbTypes";

type AgentIdentifierDataInput = TablesInsert<"AgentIdentifier">;
const { AgentIdentifierType } = Constants.public.Enums;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { NextResponse, NextRequest } from "next/server";
import type { PostgrestResponse } from "@supabase/supabase-js";

import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import {
processAndInsertBatch,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/api/supabase/content-embedding/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { NextResponse, NextRequest } from "next/server";
import type { PostgrestSingleResponse } from "@supabase/supabase-js";

import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import {
getOrCreateEntity,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/api/supabase/content/batch/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NextResponse, NextRequest } from "next/server";
import type { PostgrestResponse } from "@supabase/supabase-js";
import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import { validateAndInsertBatch } from "~/utils/supabase/dbUtils";
import {
Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/api/supabase/content/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type { PostgrestSingleResponse } from "@supabase/supabase-js";

import { createClient } from "~/utils/supabase/server";
import { getOrCreateEntity } from "~/utils/supabase/dbUtils";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import { contentInputValidation } from "~/utils/supabase/validators";
import { Tables, TablesInsert } from "@repo/database/types.gen.ts";
import type { Tables, TablesInsert } from "@repo/database/dbTypes";

type ContentDataInput = TablesInsert<"Content">;
type ContentRecord = Tables<"Content">;
Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/api/supabase/document/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { PostgrestSingleResponse } from "@supabase/supabase-js";

import { createClient } from "~/utils/supabase/server";
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import { Tables, TablesInsert } from "@repo/database/types.gen.ts";
import type { Tables, TablesInsert } from "@repo/database/dbTypes";

type DocumentDataInput = TablesInsert<"Document">;
type DocumentRecord = Tables<"Document">;
Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/api/supabase/platform-account/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { NextResponse, NextRequest } from "next/server";

import { createClient } from "~/utils/supabase/server";
import { getOrCreateEntity, ItemValidator } from "~/utils/supabase/dbUtils";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";
import { TablesInsert, Constants } from "@repo/database/types.gen.ts";
import { type TablesInsert, Constants } from "@repo/database/dbTypes";

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

Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/api/supabase/similarity-rank/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NextResponse, NextRequest } from "next/server";
import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";

type SimilarityRankInput = {
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/api/supabase/space/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
handleRouteError,
defaultOptionsHandler,
} from "~/utils/supabase/apiUtils";
import { fetchOrCreateSpaceDirect } from "@repo/ui/lib/supabase/contextFunctions";
import { fetchOrCreateSpaceDirect } from "@repo/database/lib/contextFunctions";

export const POST = async (request: NextRequest): Promise<NextResponse> => {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { NextResponse, NextRequest } from "next/server";
import { PostgrestSingleResponse } from "@supabase/supabase-js";
import { Database, Constants } from "@repo/database/types.gen.ts";
import { type Database, Constants } from "@repo/database/dbTypes";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import { createClient } from "~/utils/supabase/server";
import {
createApiResponse,
asPostgrestFailure,
handleRouteError,
} from "~/utils/supabase/apiUtils";
import { createApiResponse, handleRouteError } from "~/utils/supabase/apiUtils";

type ApiParams = Promise<{ target: string; fn: string; worker: string }>;
export type SegmentDataType = { params: ApiParams };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NextResponse, NextRequest } from "next/server";
import type { PostgrestSingleResponse } from "@supabase/supabase-js";
import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import {
createApiResponse,
handleRouteError,
defaultOptionsHandler,
asPostgrestFailure,
} from "~/utils/supabase/apiUtils";

type SyncTaskInfo = {
Expand Down
6 changes: 2 additions & 4 deletions apps/website/app/utils/supabase/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
PostgrestSingleResponse,
} from "@supabase/supabase-js";

import { Database } from "@repo/database/types.gen.ts";
import type { Database } from "@repo/database/dbTypes";
import { createClient } from "~/utils/supabase/server";
import { asPostgrestFailure } from "@repo/ui/lib/supabase/contextFunctions";
// Temporarily re-exporting because many imports point here. Will be moved to a future packages/utils.
export { asPostgrestFailure } from "@repo/ui/lib/supabase/contextFunctions";
import { asPostgrestFailure } from "@repo/database/lib/contextFunctions";
import cors from "~/utils/llm/cors";

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/utils/supabase/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createClient as createSupabaseClient } from "@supabase/supabase-js";
import { Database } from "@repo/database/types.gen.ts";
import type { Database } from "@repo/database/dbTypes";

// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth

Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/utils/supabase/dbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
PostgrestResponse,
PostgrestSingleResponse,
} from "@supabase/supabase-js";
import { Database, Tables, TablesInsert } from "@repo/database/types.gen.ts";
import type { Database, Tables, TablesInsert } from "@repo/database/dbTypes";

export const KNOWN_EMBEDDING_TABLES: {
[key: string]: {
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/utils/supabase/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";
import { Database } from "@repo/database/types.gen";
import type { Database } from "@repo/database/dbTypes";
import { envContents } from "@repo/database/dbDotEnv";

// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/utils/supabase/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ItemProcessor,
ItemValidator,
} from "./dbUtils";
import { Tables, TablesInsert } from "@repo/database/types.gen.ts";
import type { Tables, TablesInsert } from "@repo/database/dbTypes";

// Use the first known ContentEmbedding table for type checking, as they have the same structure
export type ContentEmbeddingDataInput =
Expand Down
1 change: 1 addition & 0 deletions apps/website/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const nextConfig = {
serverRuntimeConfig: {
maxDuration: 300,
},
transpilePackages: ["@repo/database", "@repo/utils", "@repo/ui"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem is this solving related to "Move some functions to packages/database"?

};
export default nextConfig;
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ We follow the Supabase [Declarative Database Schema](https://supabase.com/docs/g
7. `turbo build`, which will do the following:
1. Start Supabase
2. Apply the new migration locally
3. Regenerate the types file with `supabase gen types typescript --local > types.gen.ts`
3. Regenerate the types file with `supabase gen types typescript --local > src/dbTypes.ts`
4. Copy it where appropriate
8. You can start using your changes again `turbo dev`
9. When your migration is pushed in a branch, Supabase will create a branch instance. Note there is a small cost to this, so we do not want those branches to linger.
Expand Down
2 changes: 1 addition & 1 deletion packages/database/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default [
},
},
{
ignores: ["types.gen.ts", "supabase/functions/**"],
ignores: ["src/dbTypes.ts", "supabase/functions/**"],
},
];
4 changes: 2 additions & 2 deletions packages/database/features/step-definitions/stepdefs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import assert from "assert";
import { Given, When, Then, world, type DataTable } from "@cucumber/cucumber";
import { createClient } from "@supabase/supabase-js";
import { Constants, type Database, type Enums } from "@repo/database/types.gen";
import { Constants, type Database, type Enums } from "@repo/database/dbTypes";
import { getVariant, config } from "@repo/database/dbDotEnv";

import {
spaceAnonUserEmail,
fetchOrCreateSpaceDirect,
fetchOrCreatePlatformAccount,
} from "@repo/ui/lib/supabase/contextFunctions";
} from "@repo/database/lib/contextFunctions";

type Platform = Enums<"Platform">;
const PLATFORMS: readonly Platform[] = Constants.public.Enums.Platform;
Expand Down
16 changes: 12 additions & 4 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"license": "Apache-2.0",
"type": "module",
"exports": {
"./types.gen.ts": "./types.gen.ts",
"./types.gen": "./types.gen.ts",
"./dbDotEnv": "./dbDotEnv.ts"
"./lib/*": "./src/lib/*.ts",
"./dbDotEnv": "./src/dbDotEnv.ts",
"./dbTypes": "./src/dbTypes.ts",
"./inputTypes": "./src/inputTypes.ts"
},
"scripts": {
"init": "supabase login",
Expand All @@ -19,13 +20,20 @@
"build": "tsx scripts/build.ts && npm run genenv -- local",
"test": "tsc && cucumber-js",
"genenv": "tsx scripts/createEnv.ts",
"gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > types.gen.ts",
"gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > src/dbTypes.ts",
"dbdiff": "supabase stop && supabase db diff",
"dbdiff:save": "supabase stop && supabase db diff -f",
"deploy": "tsx scripts/deploy.ts",
"deploy:functions": "tsx scripts/lint.ts -f"
},
"dependencies": {
"@repo/utils": "*",
"@supabase/auth-js": "2.71.1",
"@supabase/functions-js": "2.4.5",
"@supabase/supabase-js": "2.55.0"
},
"devDependencies": {
"@repo/typescript-config": "*",
"@cucumber/cucumber": "^11.3.0",
"@vercel/sdk": "^1.10.0",
"prettier-plugin-gherkin": "^3.1.2",
Expand Down
9 changes: 5 additions & 4 deletions packages/database/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const projectRoot = join(__dirname, "..");

if (process.env.HOME !== "/vercel") {
try {
execSync("supabase start");
execSync("supabase migrations up");
execSync("supabase start", { cwd: projectRoot, stdio: "inherit" });
execSync("supabase migrations up", { cwd: projectRoot, stdio: "inherit" });
const stdout = execSync(
"supabase gen types typescript --local --schema public",
{ encoding: "utf8" },
{ encoding: "utf8" , cwd: projectRoot },
);
writeFileSync(join(projectRoot, "types.gen.ts"), stdout);
writeFileSync(join(projectRoot, "src", "dbTypes.ts"),
"// Generated by supabase -- do not edit\n" + stdout);
} catch (err) {
console.error(err);
throw err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync, existsSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const __dirname = dirname(dirname(fileURLToPath(import.meta.url)));

export const getVariant = (): string | null => {
if (process.env.HOME === "/vercel" || process.env.GITHUB_ACTIONS === "true")
Expand Down
Loading