fix toDriver mutation convertion not respecting default values, react re-renders on navigation, mutator result logging

This commit is contained in:
dswbx
2025-06-14 08:06:05 +02:00
parent 8e1ecfcfe3
commit 6b3ac9e6e2
5 changed files with 27 additions and 11 deletions

View File

@@ -125,10 +125,13 @@ export class Mutator<
// if listener returned, take what's returned
const _data = result.returned ? result.params.data : data;
let validatedData = {
...entity.getDefaultObject(),
...(await this.getValidatedData(_data, "create")),
};
let validatedData = await this.getValidatedData(
{
...entity.getDefaultObject(),
..._data,
},
"create",
);
// check if required fields are present
const required = entity.getRequiredFields();
@@ -289,10 +292,6 @@ export class Mutator<
): Promise<MutatorResult<Output[]>> {
const entity = this.entity;
const validatedData = await this.getValidatedData(data, "update");
console.log("updateWhere", {
entity,
validatedData,
});
// @todo: add a way to delete all by adding force?
if (!where || typeof where !== "object" || Object.keys(where).length === 0) {

View File

@@ -2,6 +2,7 @@ import { $console } from "core/console";
import type { Entity, EntityData } from "../Entity";
import type { EntityManager } from "../EntityManager";
import { Result, type ResultJSON, type ResultOptions } from "../Result";
import { isDebug } from "core";
export type MutatorResultOptions = ResultOptions & {
silent?: boolean;
@@ -16,13 +17,15 @@ export class MutatorResult<T = EntityData[]> extends Result<T> {
public entity: Entity,
options?: MutatorResultOptions,
) {
const logParams = options?.logParams === undefined ? isDebug() : options.logParams;
super(em.connection, {
hydrator: (rows) => em.hydrate(entity.name, rows as any),
beforeExecute: (compiled) => {
if (!options?.silent) {
$console.debug(
`[Mutation]\n${compiled.sql}\n`,
options?.logParams ? compiled.parameters : undefined,
logParams ? compiled.parameters : undefined,
);
}
},