UNPKG

@aws/aurora-dsql-node-postgres-connector

Version:

An AWS Aurora DSQL connector with IAM authentication for node-postgres

51 lines 2.22 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import { Client } from "pg"; import { AuroraDSQLUtil } from "./aurora-dsql-util"; class AuroraDSQLClient extends Client { constructor(config) { if (config === undefined) { throw new Error("Configuration is required"); } let dsqlConfig = AuroraDSQLUtil.parsePgConfig(config); super(dsqlConfig); this.dsqlConfig = dsqlConfig; } // TypeScript doesn't allow multiple declarations of the same function name hence the following declaration was used connect(callback) { const _super = Object.create(null, { connect: { get: () => super.connect } }); return __awaiter(this, void 0, void 0, function* () { if (this.dsqlConfig !== undefined) { try { this.password = yield AuroraDSQLUtil.getDSQLToken(this.dsqlConfig.host, this.dsqlConfig.user, this.dsqlConfig.profile, this.dsqlConfig.region); } catch (error) { if (callback) { callback(error); return; } throw error; } } if (callback) { return _super.connect.call(this, callback); } return _super.connect.call(this); }); } } export { AuroraDSQLClient }; //# sourceMappingURL=aurora-dsql-client.js.map