@aws/aurora-dsql-node-postgres-connector
Version:
An AWS Aurora DSQL connector with IAM authentication for node-postgres
54 lines • 2.38 kB
JavaScript
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 { Pool } from "pg";
import { AuroraDSQLUtil } from "./aurora-dsql-util";
class AuroraDSQLPool extends Pool {
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 declaration of the same 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* () {
try {
if (this.options !== undefined && this.dsqlConfig !== undefined) {
this.options.password = yield AuroraDSQLUtil.getDSQLToken(this.dsqlConfig.host, this.dsqlConfig.user, this.dsqlConfig.profile, this.dsqlConfig.region, this.dsqlConfig.tokenDurationSecs);
}
else {
throw new Error("options is undefined in this pool");
}
}
catch (error) {
if (callback) {
callback(error, undefined, () => { });
return;
}
throw error;
}
if (callback) {
return _super.connect.call(this, callback);
}
return _super.connect.call(this);
});
}
}
export { AuroraDSQLPool };
//# sourceMappingURL=aurora-dsql-pool.js.map