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
4 changes: 4 additions & 0 deletions packages/core/fumadb/src/adapters/drizzle/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ export function fromDrizzle(
},
async upsertMany(table, v) {
if (v.values.length === 0) return;
if (v.target.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: adapter rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one target column.");
}
if (v.update.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: adapter rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one update column.");
Expand Down
4 changes: 4 additions & 0 deletions packages/core/fumadb/src/adapters/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export function memoryAdapter(options: MemoryAdapterOptions = {}): FumaDBAdapter
await this.create(table, v.create);
},
async upsertMany(table, v) {
if (v.target.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: adapter rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one target column.");
}
if (v.update.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: adapter rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one update column.");
Expand Down
8 changes: 8 additions & 0 deletions packages/core/fumadb/src/query/orm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ export function toORM<S extends AnySchema>(
async upsertMany(name, { target, update, values }) {
const table = toTable(name);
if (values.length === 0) return;
if (target.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: public query rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one target column.");
}
if (update.length === 0) {
// oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: public query rejects invalid upsert shape
throw new Error("[FumaDB] upsertMany requires at least one update column.");
}

const targetColumns = target.map((columnName) => {
const column = table.columns[columnName as string];
Expand Down
31 changes: 31 additions & 0 deletions packages/core/fumadb/src/query/table-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,37 @@ describe("FumaDB table policies", () => {
}),
);

it.effect("rejects invalid bulk upsert conflict shapes", () =>
useHarness(async (orm) => {
await seedTenants(orm);
const tenantA = withQueryContext(orm, makeContext(["tenant-a"], "tenant-a"));
const values = [
{
id: "post-a-bulk-upsert",
tenantId: "tenant-a",
authorId: "author-a",
title: "A bulk upsert",
},
];

await expect(
tenantA.upsertMany("posts", {
target: [],
update: ["title"],
values,
}),
).rejects.toThrow("[FumaDB] upsertMany requires at least one target column.");

await expect(
tenantA.upsertMany("posts", {
target: ["id"],
update: [],
values,
}),
).rejects.toThrow("[FumaDB] upsertMany requires at least one update column.");
}),
);

it.effect("fails closed when a query wrapper does not forward context rebinding", () =>
useHarness(async (orm) => {
const wrapped = { ...orm };
Expand Down
Loading