UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

59 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeSerialPseudoType = normalizeSerialPseudoType; exports.isSerialPseudoType = isSerialPseudoType; const SERIAL_PSEUDO_TYPE_MAP = { serial: 'integer', serial4: 'integer', bigserial: 'bigint', serial8: 'bigint', smallserial: 'smallint', serial2: 'smallint', }; /** * Converts Postgres serial pseudo-type names into their real storage types so ZTD * cast expressions never emit non-existent types. * * @param typeName Optional type name (possibly qualified) that is trimmed before normalization. * @returns The normalized type name when a pseudo-type matches, the trimmed input when no match is found, or `undefined` when the argument is `undefined`. * @example * normalizeSerialPseudoType('serial') // 'integer' * normalizeSerialPseudoType('public.BIGSERIAL') // 'public.bigint' */ function normalizeSerialPseudoType(typeName) { if (!typeName) { return typeName; } const trimmed = typeName.trim(); if (!trimmed) { return trimmed; } // Preserve schema or catalog qualifiers while normalizing the terminal segment. const segments = trimmed.split('.'); const base = segments.pop(); const normalizedBase = SERIAL_PSEUDO_TYPE_MAP[base.toLowerCase()]; if (!normalizedBase) { return trimmed; } segments.push(normalizedBase); return segments.join('.'); } /** * Returns true when the provided type name resolves to a known serial pseudo-type. */ function isSerialPseudoType(typeName) { if (!typeName) { return false; } const trimmed = typeName.trim(); if (!trimmed) { return false; } const segments = trimmed.split('.'); const base = segments.pop(); if (!base) { return false; } return Boolean(SERIAL_PSEUDO_TYPE_MAP[base.toLowerCase()]); } //# sourceMappingURL=serialTypeNormalization.js.map