Skip to content

Commit fb8a6c1

Browse files
Use branded types for identifiers everywhere (#1149)
* do it * format
1 parent e287051 commit fb8a6c1

File tree

78 files changed

+469
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+469
-275
lines changed

apps/web/actions/caps/share.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
spaceVideos,
1212
videos,
1313
} from "@cap/database/schema";
14-
import type { Video } from "@cap/web-domain";
14+
import type { Organisation, Space, Video } from "@cap/web-domain";
1515
import { and, eq, inArray } from "drizzle-orm";
1616
import { revalidatePath } from "next/cache";
1717

1818
interface ShareCapParams {
1919
capId: Video.VideoId;
20-
spaceIds: string[];
20+
spaceIds: Space.SpaceIdOrOrganisationId[];
2121
public?: boolean;
2222
}
2323

@@ -53,7 +53,7 @@ export async function shareCap({
5353
.from(organizations)
5454
.where(
5555
and(
56-
inArray(organizations.id, spaceIds),
56+
inArray(organizations.id, spaceIds as Organisation.OrganisationId[]),
5757
inArray(organizations.id, userOrganizationIds),
5858
),
5959
)

apps/web/actions/organization/check-domain.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import { db } from "@cap/database";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { organizations } from "@cap/database/schema";
6+
import type { Organisation } from "@cap/web-domain";
67
import { eq } from "drizzle-orm";
78
import { checkDomainStatus } from "./domain-utils";
89

9-
export async function checkOrganizationDomain(organizationId: string) {
10+
export async function checkOrganizationDomain(
11+
organizationId: Organisation.OrganisationId,
12+
) {
1013
const user = await getCurrentUser();
1114

1215
if (!user || !organizationId) {

apps/web/actions/organization/create-space.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { nanoId, nanoIdLength } from "@cap/database/helpers";
66
import { spaceMembers, spaces, users } from "@cap/database/schema";
77
import { serverEnv } from "@cap/env";
88
import { S3Buckets } from "@cap/web-backend";
9+
import { Space } from "@cap/web-domain";
910
import { and, eq, inArray } from "drizzle-orm";
1011
import { Effect, Option } from "effect";
1112
import { revalidatePath } from "next/cache";
@@ -62,7 +63,7 @@ export async function createSpace(
6263
}
6364

6465
// Generate the space ID early so we can use it in the file path
65-
const spaceId = nanoId();
66+
const spaceId = Space.SpaceId.make(nanoId());
6667

6768
const iconFile = formData.get("icon") as File | null;
6869
let iconUrl = null;

apps/web/actions/organization/delete-space.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
spaceVideos,
1010
} from "@cap/database/schema";
1111
import { S3Buckets } from "@cap/web-backend";
12+
import type { Space } from "@cap/web-domain";
1213
import { eq } from "drizzle-orm";
1314
import { Effect, Option } from "effect";
1415
import { revalidatePath } from "next/cache";
@@ -20,7 +21,7 @@ interface DeleteSpaceResponse {
2021
}
2122

2223
export async function deleteSpace(
23-
spaceId: string,
24+
spaceId: Space.SpaceIdOrOrganisationId,
2425
): Promise<DeleteSpaceResponse> {
2526
try {
2627
const user = await getCurrentUser();

apps/web/actions/organization/get-organization-sso-data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import { db } from "@cap/database";
44
import { organizations } from "@cap/database/schema";
5+
import type { Organisation } from "@cap/web-domain";
56
import { eq } from "drizzle-orm";
67

7-
export async function getOrganizationSSOData(organizationId: string) {
8+
export async function getOrganizationSSOData(
9+
organizationId: Organisation.OrganisationId,
10+
) {
811
if (!organizationId) {
912
throw new Error("Organization ID is required");
1013
}

apps/web/actions/organization/remove-domain.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import { db } from "@cap/database";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { organizations } from "@cap/database/schema";
6+
import type { Organisation } from "@cap/web-domain";
67
import { eq } from "drizzle-orm";
78
import { revalidatePath } from "next/cache";
89

9-
export async function removeOrganizationDomain(organizationId: string) {
10+
export async function removeOrganizationDomain(
11+
organizationId: Organisation.OrganisationId,
12+
) {
1013
const user = await getCurrentUser();
1114

1215
if (!user) {

apps/web/actions/organization/remove-icon.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import { db } from "@cap/database";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { organizations } from "@cap/database/schema";
6+
import type { Organisation } from "@cap/web-domain";
67
import { eq } from "drizzle-orm";
78
import { revalidatePath } from "next/cache";
89

9-
export async function removeOrganizationIcon(organizationId: string) {
10+
export async function removeOrganizationIcon(
11+
organizationId: Organisation.OrganisationId,
12+
) {
1013
const user = await getCurrentUser();
1114

1215
if (!user) {

apps/web/actions/organization/remove-invite.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import { db } from "@cap/database";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { organizationInvites, organizations } from "@cap/database/schema";
6+
import type { Organisation } from "@cap/web-domain";
67
import { and, eq } from "drizzle-orm";
78
import { revalidatePath } from "next/cache";
89

910
export async function removeOrganizationInvite(
1011
inviteId: string,
11-
organizationId: string,
12+
organizationId: Organisation.OrganisationId,
1213
) {
1314
const user = await getCurrentUser();
1415

apps/web/actions/organization/remove-member.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { db } from "@cap/database";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { organizationMembers, organizations } from "@cap/database/schema";
6+
import type { Organisation } from "@cap/web-domain";
67
import { and, eq } from "drizzle-orm";
78
import { revalidatePath } from "next/cache";
89

@@ -13,7 +14,7 @@ import { revalidatePath } from "next/cache";
1314
*/
1415
export async function removeOrganizationMember(
1516
memberId: string,
16-
organizationId: string,
17+
organizationId: Organisation.OrganisationId,
1718
) {
1819
const user = await getCurrentUser();
1920
if (!user) throw new Error("Unauthorized");

apps/web/actions/organization/send-invites.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { OrganizationInvite } from "@cap/database/emails/organization-invite";
77
import { nanoId } from "@cap/database/helpers";
88
import { organizationInvites, organizations } from "@cap/database/schema";
99
import { serverEnv } from "@cap/env";
10+
import type { Organisation } from "@cap/web-domain";
1011
import { eq } from "drizzle-orm";
1112
import { revalidatePath } from "next/cache";
1213

1314
export async function sendOrganizationInvites(
1415
invitedEmails: string[],
15-
organizationId: string,
16+
organizationId: Organisation.OrganisationId,
1617
) {
1718
const user = await getCurrentUser();
1819

0 commit comments

Comments
 (0)