Refactor parseJson to handle different value types
Refactor parseJson function to handle various input types and improve null checks.
This commit is contained in:
@@ -90,8 +90,17 @@ function normalizePositiveIntegerOrNull(value: unknown): number | null {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function parseJson(value: string | null | undefined): unknown {
|
||||
if (!value) return null;
|
||||
function parseJson(value: unknown): unknown {
|
||||
if (value === null || value === undefined) return null;
|
||||
|
||||
// PostgreSQL JSONB columns are returned as parsed objects/arrays by the pg driver
|
||||
if (typeof value === 'object') {
|
||||
return value;
|
||||
}
|
||||
|
||||
// SQLite TEXT columns store JSON as strings that need parsing
|
||||
if (typeof value === 'string') {
|
||||
if (value === '') return null;
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
@@ -99,6 +108,9 @@ function parseJson(value: string | null | undefined): unknown {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function normalizeGroupNameInput(input: unknown): string | null {
|
||||
if (typeof input !== 'string') return null;
|
||||
const value = input.trim();
|
||||
|
||||
Reference in New Issue
Block a user