fix(adapter): apply customTransformInput to where clause values (#6914)

Co-authored-by: ping-maxwell <maxwell.multinite@gmail.com>
Co-authored-by: Maxwell <145994855+ping-maxwell@users.noreply.github.com>
This commit is contained in:
Shawn Erquhart
2025-12-22 17:11:49 +00:00
committed by github-actions[bot]
co-authored by ping-maxwell Maxwell
parent ad3c0b591f
commit 6d4aab5190
4 changed files with 50 additions and 2 deletions
@@ -604,7 +604,7 @@ export const mongodbAdapter = (
if (customIdGen) {
return data;
}
if (action === "update") {
if (action !== "create") {
return data;
}
if (Array.isArray(data)) {
+30
View File
@@ -474,9 +474,19 @@ export const createAdapterFactory =
const transformWhereClause = <W extends Where[] | undefined>({
model,
where,
action,
}: {
where: W;
model: string;
action:
| "create"
| "update"
| "findOne"
| "findMany"
| "updateMany"
| "delete"
| "deleteMany"
| "count";
}): W extends undefined ? undefined : CleanedWhere[] => {
if (!where) return undefined as any;
const newMappedKeys = config.mapKeysTransformInput ?? {};
@@ -562,6 +572,18 @@ export const createAdapterFactory =
}
}
if (config.customTransformInput) {
newValue = config.customTransformInput({
data: newValue,
fieldAttributes: fieldAttr,
field: fieldName,
model: getModelName(model),
schema,
options,
action,
});
}
return {
operator,
connector,
@@ -727,6 +749,7 @@ export const createAdapterFactory =
connector: "AND",
},
],
action: "findOne",
});
try {
if (joinConfig.relation === "one-to-one") {
@@ -886,6 +909,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "update",
});
debugLog(
{ method: "update" },
@@ -946,6 +970,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "updateMany",
});
unsafeModel = getDefaultModelName(unsafeModel);
debugLog(
@@ -1001,6 +1026,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "findOne",
});
unsafeModel = getDefaultModelName(unsafeModel);
let join: JoinConfig | undefined;
@@ -1078,6 +1104,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "findMany",
});
unsafeModel = getDefaultModelName(unsafeModel);
let join: JoinConfig | undefined;
@@ -1151,6 +1178,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "delete",
});
unsafeModel = getDefaultModelName(unsafeModel);
debugLog(
@@ -1183,6 +1211,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "deleteMany",
});
unsafeModel = getDefaultModelName(unsafeModel);
debugLog(
@@ -1216,6 +1245,7 @@ export const createAdapterFactory =
const where = transformWhereClause({
model: unsafeModel,
where: unsafeWhere,
action: "count",
});
unsafeModel = getDefaultModelName(unsafeModel);
debugLog(
+9 -1
View File
@@ -203,7 +203,15 @@ export interface DBAdapterFactoryConfig<
/**
* The action which was called from the adapter.
*/
action: "create" | "update" | "findOne" | "findMany";
action:
| "create"
| "update"
| "findOne"
| "findMany"
| "updateMany"
| "delete"
| "deleteMany"
| "count";
/**
* The model name.
*/
+10
View File
@@ -111,9 +111,19 @@ export type AdapterFactoryCustomizeAdapterCreator = (config: {
transformWhereClause: <W extends Where[] | undefined>({
model,
where,
action,
}: {
where: W;
model: string;
action:
| "create"
| "update"
| "findOne"
| "findMany"
| "updateMany"
| "delete"
| "deleteMany"
| "count";
}) => W extends undefined ? undefined : CleanedWhere[];
}) => CustomAdapter;