Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,43 +0,0 @@
// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
tenantTypeFindMany: vi.fn(),
}));
vi.mock("~/utils/db.server", () => ({
db: {
tenantType: {
findMany: mocks.tenantTypeFindMany,
},
},
}));
import { getTenantTypeOptions } from "./tenantTypes.db.server";
describe("tenant type db helpers", () => {
beforeEach(() => {
mocks.tenantTypeFindMany.mockReset();
mocks.tenantTypeFindMany.mockResolvedValue([
{ id: "type_1", title: "Workspace" },
{ id: "type_2", title: "Customer" },
]);
});
it("loads lightweight tenant type options for account forms", async () => {
await expect(getTenantTypeOptions()).resolves.toEqual([
{ id: "type_1", title: "Workspace" },
{ id: "type_2", title: "Customer" },
]);
expect(mocks.tenantTypeFindMany).toHaveBeenCalledWith({
select: {
id: true,
title: true,
},
orderBy: {
createdAt: "asc",
},
});
});
});
@@ -1,139 +0,0 @@
import { Prisma, SubscriptionProduct, TenantType } from "@hivegrid/db/prisma-browser";
import { db } from "~/utils/db.server";
import { cachified, clearCacheKey } from "~/utils/cache.server";
export type TenantTypeWithDetails = TenantType & {
subscriptionProducts: SubscriptionProduct[];
_count: { tenants: number };
};
const includeDetails = {
subscriptionProducts: true,
_count: { select: { tenants: true } },
};
// TenantTypes are a quasi-static, non-tenant-scoped table read on every authenticated app pageview
// (loadAppData). The cache is invalidated on every tenant-type mutation below. NOTE: the embedded
// `_count.tenants` also changes when tenants are created/deleted (outside this module's scope), so a
// short TTL is used to keep that count from drifting more than a few minutes on the app overview.
const TENANT_TYPES_CACHE_KEY = "tenantTypes:all";
const TENANT_TYPES_CACHE_TTL = 1000 * 60 * 5; // 5min — bounded staleness for the embedded tenant count
export async function getAllTenantTypes(): Promise<TenantTypeWithDetails[]> {
return await cachified({
key: TENANT_TYPES_CACHE_KEY,
ttl: TENANT_TYPES_CACHE_TTL,
getFreshValue: () =>
db.tenantType.findMany({
include: {
subscriptionProducts: true,
_count: { select: { tenants: true } },
},
orderBy: {
createdAt: "asc",
},
}),
});
}
export async function getTenantTypeOptions(): Promise<Array<Pick<TenantType, "id" | "title">>> {
return await db.tenantType.findMany({
select: {
id: true,
title: true,
},
orderBy: {
createdAt: "asc",
},
});
}
export async function getDefaultTenantTypes() {
return await db.tenantType.findMany({
where: { isDefault: true },
orderBy: {
createdAt: "asc",
},
});
}
export async function getTenantType(id: string): Promise<TenantTypeWithDetails | null> {
return await db.tenantType.findUnique({
where: { id: id },
include: includeDetails,
});
}
export async function getTenantTypeByTitle(title: string): Promise<TenantTypeWithDetails | null> {
return await db.tenantType.findUnique({
where: { title },
include: includeDetails,
});
}
export async function createTenantType(data: {
title: string;
titlePlural: string;
description: string | null;
isDefault?: boolean;
subscriptionProducts: string[];
}) {
return await db.tenantType
.create({
data: {
title: data.title,
titlePlural: data.titlePlural,
description: data.description,
isDefault: data.isDefault,
subscriptionProducts: {
connect: data.subscriptionProducts.map((id) => ({ id })),
},
},
})
.then((item) => {
clearCacheKey(TENANT_TYPES_CACHE_KEY);
return item;
});
}
export async function updateTenantType(
id: string,
data: {
title?: string;
titlePlural?: string;
description?: string | null;
isDefault?: boolean;
subscriptionProducts?: string[];
}
) {
const update: Prisma.TenantTypeUncheckedUpdateInput = {
title: data.title,
titlePlural: data.titlePlural,
description: data.description,
isDefault: data.isDefault,
};
if (data.subscriptionProducts) {
update.subscriptionProducts = {
set: data.subscriptionProducts.map((id) => ({ id })),
};
}
return await db.tenantType
.update({
where: { id: id },
data: update,
})
.then((item) => {
clearCacheKey(TENANT_TYPES_CACHE_KEY);
return item;
});
}
export async function deleteTenantType(id: string) {
return await db.tenantType
.delete({
where: { id: id },
})
.then((item) => {
clearCacheKey(TENANT_TYPES_CACHE_KEY);
return item;
});
}