mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix toDriver mutation convertion not respecting default values, react re-renders on navigation, mutator result logging
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"bin": "./dist/cli/index.js",
|
"bin": "./dist/cli/index.js",
|
||||||
"version": "0.15.0-rc.0",
|
"version": "0.15.0-rc.2",
|
||||||
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
|
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
|
||||||
"homepage": "https://bknd.io",
|
"homepage": "https://bknd.io",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -125,10 +125,13 @@ export class Mutator<
|
|||||||
|
|
||||||
// if listener returned, take what's returned
|
// if listener returned, take what's returned
|
||||||
const _data = result.returned ? result.params.data : data;
|
const _data = result.returned ? result.params.data : data;
|
||||||
let validatedData = {
|
let validatedData = await this.getValidatedData(
|
||||||
...entity.getDefaultObject(),
|
{
|
||||||
...(await this.getValidatedData(_data, "create")),
|
...entity.getDefaultObject(),
|
||||||
};
|
..._data,
|
||||||
|
},
|
||||||
|
"create",
|
||||||
|
);
|
||||||
|
|
||||||
// check if required fields are present
|
// check if required fields are present
|
||||||
const required = entity.getRequiredFields();
|
const required = entity.getRequiredFields();
|
||||||
@@ -289,10 +292,6 @@ export class Mutator<
|
|||||||
): Promise<MutatorResult<Output[]>> {
|
): Promise<MutatorResult<Output[]>> {
|
||||||
const entity = this.entity;
|
const entity = this.entity;
|
||||||
const validatedData = await this.getValidatedData(data, "update");
|
const validatedData = await this.getValidatedData(data, "update");
|
||||||
console.log("updateWhere", {
|
|
||||||
entity,
|
|
||||||
validatedData,
|
|
||||||
});
|
|
||||||
|
|
||||||
// @todo: add a way to delete all by adding force?
|
// @todo: add a way to delete all by adding force?
|
||||||
if (!where || typeof where !== "object" || Object.keys(where).length === 0) {
|
if (!where || typeof where !== "object" || Object.keys(where).length === 0) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { $console } from "core/console";
|
|||||||
import type { Entity, EntityData } from "../Entity";
|
import type { Entity, EntityData } from "../Entity";
|
||||||
import type { EntityManager } from "../EntityManager";
|
import type { EntityManager } from "../EntityManager";
|
||||||
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
import { Result, type ResultJSON, type ResultOptions } from "../Result";
|
||||||
|
import { isDebug } from "core";
|
||||||
|
|
||||||
export type MutatorResultOptions = ResultOptions & {
|
export type MutatorResultOptions = ResultOptions & {
|
||||||
silent?: boolean;
|
silent?: boolean;
|
||||||
@@ -16,13 +17,15 @@ export class MutatorResult<T = EntityData[]> extends Result<T> {
|
|||||||
public entity: Entity,
|
public entity: Entity,
|
||||||
options?: MutatorResultOptions,
|
options?: MutatorResultOptions,
|
||||||
) {
|
) {
|
||||||
|
const logParams = options?.logParams === undefined ? isDebug() : options.logParams;
|
||||||
|
|
||||||
super(em.connection, {
|
super(em.connection, {
|
||||||
hydrator: (rows) => em.hydrate(entity.name, rows as any),
|
hydrator: (rows) => em.hydrate(entity.name, rows as any),
|
||||||
beforeExecute: (compiled) => {
|
beforeExecute: (compiled) => {
|
||||||
if (!options?.silent) {
|
if (!options?.silent) {
|
||||||
$console.debug(
|
$console.debug(
|
||||||
`[Mutation]\n${compiled.sql}\n`,
|
`[Mutation]\n${compiled.sql}\n`,
|
||||||
options?.logParams ? compiled.parameters : undefined,
|
logParams ? compiled.parameters : undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import { EntityTable2 } from "ui/modules/data/components/EntityTable2";
|
|||||||
import { useEntityForm } from "ui/modules/data/hooks/useEntityForm";
|
import { useEntityForm } from "ui/modules/data/hooks/useEntityForm";
|
||||||
|
|
||||||
export function DataEntityUpdate({ params }) {
|
export function DataEntityUpdate({ params }) {
|
||||||
|
return <DataEntityUpdateImpl params={params} key={params.entity} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DataEntityUpdateImpl({ params }) {
|
||||||
const { $data, relations } = useBkndData();
|
const { $data, relations } = useBkndData();
|
||||||
const entity = $data.entity(params.entity as string);
|
const entity = $data.entity(params.entity as string);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
@@ -240,7 +244,12 @@ function EntityDetailRelations({
|
|||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-grow flex-col gap-3 p-3">
|
<div className="flex flex-grow flex-col gap-3 p-3">
|
||||||
<EntityDetailInner id={id} entity={entity} relation={selected} />
|
<EntityDetailInner
|
||||||
|
id={id}
|
||||||
|
entity={entity}
|
||||||
|
relation={selected}
|
||||||
|
key={JSON.stringify(selected?.toJSON())}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -257,6 +266,7 @@ function EntityDetailInner({
|
|||||||
}) {
|
}) {
|
||||||
const other = relation.other(entity);
|
const other = relation.other(entity);
|
||||||
const [navigate] = useNavigate();
|
const [navigate] = useNavigate();
|
||||||
|
|
||||||
const [search, setSearch] = useState({
|
const [search, setSearch] = useState({
|
||||||
select: other.entity.getSelect(undefined, "table"),
|
select: other.entity.getSelect(undefined, "table"),
|
||||||
sort: other.entity.getDefaultSort(),
|
sort: other.entity.getDefaultSort(),
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ const searchSchema = s.partialObject({
|
|||||||
const PER_PAGE_OPTIONS = [5, 10, 25, 50, 100];
|
const PER_PAGE_OPTIONS = [5, 10, 25, 50, 100];
|
||||||
|
|
||||||
export function DataEntityList({ params }) {
|
export function DataEntityList({ params }) {
|
||||||
|
return <DataEntityListImpl params={params} key={params.entity} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DataEntityListImpl({ params }) {
|
||||||
const { $data } = useBkndData();
|
const { $data } = useBkndData();
|
||||||
const entity = $data.entity(params.entity as string);
|
const entity = $data.entity(params.entity as string);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
|
|||||||
Reference in New Issue
Block a user