Files
metapi/src/server/db/postgresJsonTextParsers.ts
T
Citaandapple b3387dfba7 [codex] fix cross-database JSON boundary handling (#283)
* fix: normalize cross-database json boundaries

* fix: address json boundary review comments

---------

Co-authored-by: apple <apple@appledeMacBook-Pro.local>
2026-03-26 20:21:19 +08:00

24 lines
770 B
TypeScript

import pg from 'pg';
export type PgTypesLike = {
builtins: {
JSON: number;
JSONB: number;
};
setTypeParser(oid: number, format: 'text', parser: (value: string) => string): void;
};
let postgresJsonTextParsersInstalled = false;
export function installPostgresJsonTextParsers(typesRegistry: PgTypesLike = pg.types as PgTypesLike): void {
if (postgresJsonTextParsersInstalled) return;
const identity = (value: string) => value;
typesRegistry.setTypeParser(typesRegistry.builtins.JSON, 'text', identity);
typesRegistry.setTypeParser(typesRegistry.builtins.JSONB, 'text', identity);
postgresJsonTextParsersInstalled = true;
}
export function resetPostgresJsonTextParsersInstallStateForTests(): void {
postgresJsonTextParsersInstalled = false;
}