Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: from event -> procedural + async context #137

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/clients/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class AdminClient {

async getToken() {
// TODO: Expire should be at the half of the expiring time.
if (!this.auth || (new Date(this.auth.expires) > new Date())) {
if (!this.auth || (new Date(this.auth.expires) < new Date())) {
const authRequest: AuthenticationRequest = {
clientId: this.appPassword.clientId,
secret: this.appPassword.secretKey
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class AdminClient {
}

/// Returns the JSON Web Key Set (JWKS) from the well known endpoint: `/.well-known/jwks.json`
async getJwks() {
private async getJwks() {
const client = jwksClient({
jwksUri: this.jwksEndpoint
});
Expand All @@ -78,7 +78,7 @@ export default class AdminClient {

/// Verifies the JWT signature using a JWK from the well-known endpoint and
/// returns the user claims.
async getClaims() {
private async getClaims() {
console.log("[AdminClient]", "Getting Token.");
const token = await this.getToken();

Expand Down
8 changes: 4 additions & 4 deletions src/clients/sql.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Pool, QueryResult } from "pg";
import AdminClient from "./admin";
import CloudClient from "./cloud";
import { Context, EventType } from "../context";
import { Profile } from "../context/config";
import AsyncContext from "../context/asyncContext";

export default class SqlClient {
private pool: Promise<Pool>;
private adminClient: AdminClient;
private cloudClient: CloudClient;
private context: Context;
private context: AsyncContext;
private profile: Profile;

constructor(
adminClient: AdminClient,
cloudClient: CloudClient,
profile: Profile,
context: Context,
context: AsyncContext,
) {
this.adminClient = adminClient;
this.cloudClient = cloudClient;
Expand All @@ -39,7 +39,7 @@ export default class SqlClient {
});
} catch (err) {
console.error("[SqlClient]", "Error creating pool: ", err);
this.context.emit("event", { type: EventType.error, message: err });
rej(err);
}
};

Expand Down
Loading
Loading