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 all commits
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
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ jobs:
sudo apt-get install -y libnss3-dev libasound2 libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev libatk1.0-0

- run: npm install
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- name: Run Tests on Linux
if: runner.os == 'Linux'
run: |
export MZ_CONFIG_PATH=$HOME/.config/materialize/test
xvfb-run -a npm test
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "${defaultBuildTask}",
"env": {
"MZ_CONFIG_PATH": "${env:HOME}/.config/materialize/test"
}
}
]
}
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
1 change: 0 additions & 1 deletion src/clients/cloud.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fetch from "node-fetch";
import AdminClient from "./admin";
import * as vscode from 'vscode';
import { Errors } from "../utilities/error";

const DEFAULT_API_CLOUD_ENDPOINT = 'https://api.cloud.materialize.com';
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