From fd19b5e5d6a811dc5e71b346f945dc77b9df64de Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Thu, 12 Nov 2026 18:25:54 +0000 Subject: [PATCH] refactor(result): read _extra through IsPlainObject instead of a cast --- guardrails.suppressions.json | 2 +- src/implementations/database/result.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/guardrails.suppressions.json b/guardrails.suppressions.json index cce1fe5..c78bcc1 100644 --- a/guardrails.suppressions.json +++ b/guardrails.suppressions.json @@ -4,7 +4,7 @@ }, "tsExpectError": 56, "tsIgnore": 0, - "safety": 1, + "safety": 0, "config": {}, "agentFiles": true } diff --git a/src/implementations/database/result.ts b/src/implementations/database/result.ts index a726a8a..59c4223 100644 --- a/src/implementations/database/result.ts +++ b/src/implementations/database/result.ts @@ -7,6 +7,7 @@ import { INSTANCE_COLUMN, } from "./utils"; import { IsDocument, IsNumber, IsString } from "./guards"; +import { IsPlainObject } from "./member"; /** * What `pg`'s default type parsers answer for one column: text, a number, a boolean, a `Date`, a @@ -100,10 +101,7 @@ export function DecodeRow(row: RowObject, table: TableModel): RowObject { } document[name] = ReviveValue(value, spec.type); } - // SAFETY: `_extra` is declared `jsonb NOT NULL DEFAULT '{}'` and the adapter writes it only as a jsonb object (EMPTY_EXTRA, MergeExtra), which pg parses to an object; it reads null only for a copy of a row that lacks the key (the column is NOT NULL), and undefined, which the spread drops, when the select list leaves it out. - const extra = { - ...(overflow as RowObject | null), - }; + const extra = IsPlainObject(overflow) ? { ...overflow } : {}; delete extra[ID_COLUMN]; delete extra[INSTANCE_COLUMN]; return { ...document, ...extra };