Skip to content

Commit

Permalink
fix: Load env variables (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
JigarJoshi authored Oct 31, 2022
1 parent 1732b27 commit 9925d22
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/proto
Submodule proto updated from ec2709 to 452d3c
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-unused-imports": "^2.0.0",
"grpc_tools_node_protoc_ts": "^5.3.2",
"grpc-tools": "^1.11.2",
"grpc-tools": "^1.11.3",
"jest": "^28.1.3",
"prettier": "2.7.1",
"ts-jest": "^28.0.8",
Expand All @@ -106,6 +106,7 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.6.10",
"dotenv": "^16.0.3",
"google-protobuf": "^3.21.0",
"json-bigint": "^1.0.0",
"typescript": "^4.7.2"
Expand Down
19 changes: 10 additions & 9 deletions src/tigris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from "./proto/server/v1/api_pb";
import { GetInfoRequest as ProtoGetInfoRequest } from "./proto/server/v1/observability_pb";

import * as dotenv from "dotenv";

import {
DatabaseInfo,
DatabaseMetadata,
Expand Down Expand Up @@ -119,13 +121,14 @@ const DEST_NAME_KEY = "destination-name";
export class Tigris {
private readonly grpcClient: TigrisClient;
private readonly observabilityClient: ObservabilityClient;
private readonly config: TigrisClientConfig;
private readonly _config: TigrisClientConfig;

/**
*
* @param {TigrisClientConfig} config configuration
*/
constructor(config?: TigrisClientConfig) {
dotenv.config();
if (typeof config === "undefined") {
config = {};
}
Expand Down Expand Up @@ -158,7 +161,7 @@ export class Tigris {
config.serverUrl = config.serverUrl + ":" + DEFAULT_GRPC_PORT;
}

this.config = config;
this._config = config;
const defaultMetadata: Metadata = new Metadata();
defaultMetadata.set(USER_AGENT_KEY, USER_AGENT_VAL);
defaultMetadata.set(DEST_NAME_KEY, config.serverUrl);
Expand All @@ -171,11 +174,9 @@ export class Tigris {
config.clientSecret === undefined
) {
// no auth - generate insecure channel
this.grpcClient = new TigrisClient(config.serverUrl, grpc.credentials.createInsecure());
this.observabilityClient = new ObservabilityClient(
config.serverUrl,
grpc.credentials.createInsecure()
);
const insecureCreds: ChannelCredentials = grpc.credentials.createInsecure();
this.grpcClient = new TigrisClient(config.serverUrl, insecureCreds);
this.observabilityClient = new ObservabilityClient(config.serverUrl, insecureCreds);
} else if (config.clientId === undefined || config.clientSecret === undefined) {
throw new Error("Both `clientId` and `clientSecret` are required");
} else {
Expand Down Expand Up @@ -235,7 +236,7 @@ export class Tigris {
if (error && error.code != status.ALREADY_EXISTS) {
reject(error);
} else {
resolve(new DB(db, this.grpcClient, this.config));
resolve(new DB(db, this.grpcClient, this._config));
}
}
);
Expand All @@ -259,7 +260,7 @@ export class Tigris {
}

public getDatabase(db: string): DB {
return new DB(db, this.grpcClient, this.config);
return new DB(db, this.grpcClient, this._config);
}

public getServerMetadata(): Promise<ServerMetadata> {
Expand Down

0 comments on commit 9925d22

Please sign in to comment.