@acuris/eventstore-postgresql
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -5,4 +5,7 @@ import * as Pg from "pg"; | ||
import { PgEventReader } from "./PgEventReader"; | ||
export declare function pgConfigForAWS(region: string, hostname: string, port: number, database: string, username: string): Pg.ClientConfig; | ||
export declare function pgConfigForRDS(region: string, clusterIdentifier: string, username: string): Promise<Pg.ClientConfig>; | ||
export declare class PgEventSource implements EventSource { | ||
static open(schema: string, pgConfig?: string | Pg.ClientConfig): Promise<PgEventSource>; | ||
static openRDS(region: string, clusterIdentifier: string, username: string, schema: string, pgConfig?: Partial<Pg.ClientConfig>): Promise<PgEventSource>; | ||
private conn; | ||
@@ -9,0 +12,0 @@ private readonly endOnClose; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgEventSource = void 0; | ||
exports.PgEventSource = exports.pgConfigForRDS = exports.pgConfigForAWS = void 0; | ||
const Pg = __importStar(require("pg")); | ||
@@ -30,2 +30,19 @@ const PgSchemaManager_1 = require("./PgSchemaManager"); | ||
const PgEventStreamWriter_1 = require("./PgEventStreamWriter"); | ||
function pgConfigForAWS(region, hostname, port, database, username) { | ||
const AWS = require("aws-sdk"); | ||
const signer = new AWS.RDS.Signer({ hostname, username, port, region }); | ||
const token = signer.getAuthToken({}); | ||
return { host: hostname, user: username, port, database, password: token, ssl: { rejectUnauthorized: false } }; | ||
} | ||
exports.pgConfigForAWS = pgConfigForAWS; | ||
async function pgConfigForRDS(region, clusterIdentifier, username) { | ||
const AWS = require("aws-sdk"); | ||
const rds = new AWS.RDS({ region }); | ||
const clusters = await rds.describeDBClusters({}).promise(); | ||
const clusterInfo = clusters.DBClusters.find(it => it.DBClusterIdentifier === clusterIdentifier); | ||
if (!clusterInfo) | ||
throw new Error(`Cluster "${clusterIdentifier}" not found`); | ||
return pgConfigForAWS(region, clusterInfo.Endpoint, clusterInfo.Port, clusterInfo.DatabaseName, username); | ||
} | ||
exports.pgConfigForRDS = pgConfigForRDS; | ||
class PgEventSource { | ||
@@ -42,2 +59,5 @@ constructor(conn, schema, endOnClose = false) { | ||
} | ||
static async openRDS(region, clusterIdentifier, username, schema, pgConfig) { | ||
return PgEventSource.open(schema, { ...await pgConfigForRDS(region, clusterIdentifier, username), ...pgConfig }); | ||
} | ||
get manageSchema() { | ||
@@ -44,0 +64,0 @@ return new PgSchemaManager_1.PgSchemaManager(this.conn, this.schema); |
{ | ||
"name": "@acuris/eventstore-postgresql", | ||
"private": false, | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "Eventstore implementation storing events in Postgresql", | ||
@@ -53,3 +53,6 @@ "keywords": [ | ||
} | ||
}, | ||
"optionalDependencies": { | ||
"aws-sdk": "^2.831.0" | ||
} | ||
} |
25151
536
4