From 86a637935a71c0a2f50aad7a963b30964fc88cd8 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 11 Feb 2024 23:55:18 -0400 Subject: [PATCH] chore: update oid types --- connection/connection_params.ts | 12 ++++++++++-- mod.ts | 2 +- query/decode.ts | 4 ++-- query/oid.ts | 13 +++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/connection/connection_params.ts b/connection/connection_params.ts index ec4d07e..8201625 100644 --- a/connection/connection_params.ts +++ b/connection/connection_params.ts @@ -1,7 +1,7 @@ import { parseConnectionUri } from "../utils/utils.ts"; import { ConnectionParamsError } from "../client/error.ts"; import { fromFileUrl, isAbsolute } from "../deps.ts"; -import { OidKey } from "../query/oid.ts"; +import { OidType } from "../query/oid.ts"; /** * The connection string must match the following URI structure. All parameters but database and user are optional @@ -92,9 +92,17 @@ export interface TLSOptions { caCertificates: string[]; } +/** + * The strategy to use when decoding results data + */ export type DecodeStrategy = "string" | "auto"; +/** + * A dictionary of functions used to decode (parse) column field values from string to a custom type. These functions will + * take precedence over the {@linkcode DecodeStrategy}. Each key in the dictionary is the column OID type number or Oid type name, + * and the value is the decoder function. + */ export type Decoders = { - [key in number | OidKey]?: DecoderFunction; + [key in number | OidType]?: DecoderFunction; }; /** diff --git a/mod.ts b/mod.ts index 143abff..be4ee05 100644 --- a/mod.ts +++ b/mod.ts @@ -10,7 +10,7 @@ export { Oid, OidTypes } from "./query/oid.ts"; // TODO // Remove the following reexports after https://doc.deno.land // supports two level depth exports -export type { OidKey, OidType } from "./query/oid.ts"; +export type { OidType, OidValue } from "./query/oid.ts"; export type { ClientOptions, ConnectionOptions, diff --git a/query/decode.ts b/query/decode.ts index 2904567..c2b5ec4 100644 --- a/query/decode.ts +++ b/query/decode.ts @@ -1,4 +1,4 @@ -import { Oid, OidType, OidTypes } from "./oid.ts"; +import { Oid, OidTypes, OidValue } from "./oid.ts"; import { bold, yellow } from "../deps.ts"; import { decodeBigint, @@ -218,7 +218,7 @@ export function decode( if (controls?.decoders) { // check if there is a custom decoder by oid (number) or by type name (string) const decoderFunc = controls.decoders?.[column.typeOid] || - controls.decoders?.[OidTypes[column.typeOid as OidType]]; + controls.decoders?.[OidTypes[column.typeOid as OidValue]]; if (decoderFunc) { return decoderFunc(strValue, column.typeOid); diff --git a/query/oid.ts b/query/oid.ts index 9b36c88..93c03ec 100644 --- a/query/oid.ts +++ b/query/oid.ts @@ -1,8 +1,10 @@ -export type OidKey = keyof typeof Oid; -export type OidType = (typeof Oid)[OidKey]; +/** A Postgres Object identifiers (OIDs) type name. */ +export type OidType = keyof typeof Oid; +/** A Postgres Object identifiers (OIDs) numeric value. */ +export type OidValue = (typeof Oid)[OidType]; /** - * Oid is a map of OidKey to OidType. + * A map of OidType to OidValue. */ export const Oid = { bool: 16, @@ -175,11 +177,10 @@ export const Oid = { } as const; /** - * OidTypes is a map of OidType to OidKey. - * Used to decode values and avoid search iteration + * A map of OidValue to OidType. Used to decode values and avoid search iteration. */ export const OidTypes: { - [key in OidType]: OidKey; + [key in OidValue]: OidType; } = { 16: "bool", 17: "bytea",