fix(db): handle PG JSONB as native objects in j() mapper

PG returns JSONB columns as native JS objects, not strings.
j() helper only handled strings via JSON.parse, returning the
fallback for objects. Now passes through objects/arrays directly.
Fixes pairing extras (kiosk_key_plaintext), capabilities, scopes,
and all other JSONB fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-26 01:58:06 +02:00
parent f4be3ee901
commit edf3c2e2eb
No known key found for this signature in database

View file

@ -14,6 +14,8 @@ export function B(value: boolean): 0 | 1 {
}
export function j<T>(value: unknown, fallback: T): T {
if (value == null) return fallback;
if (typeof value === "object" || Array.isArray(value)) return value as T;
if (typeof value !== "string" || value.length === 0) return fallback;
try {
return JSON.parse(value) as T;