Skip to content

Commit

Permalink
chore(react): clean out unused deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Apr 5, 2024
1 parent c0f9747 commit b9af518
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
8 changes: 2 additions & 6 deletions packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ Consolidates the API and DB for working with Nile.
```ts
import Nile from '@niledatabase/server';

const nile = new Nile({
const nile = await Nile({
user: 'username',
password: 'password',
});

await nile.init();

await nile.api.createTenant({ name: 'name' });

await nile.db.query('select * from todo');
Expand All @@ -31,9 +29,7 @@ NILEDB_PASSWORD=password
```ts
import Nile from '@niledatabase/server';

const nile = new Nile();

await nile.init();
const nile = await Nile();

await nile.api.createTenant({ name: 'name' });

Expand Down
10 changes: 5 additions & 5 deletions packages/server/src/Server.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Nile from './Server';
import { Server } from './Server';

describe('server', () => {
fit('has reasonable defaults', () => {
Expand All @@ -8,7 +8,7 @@ describe('server', () => {
user: 'username',
password: 'password',
};
const server = new Nile(config);
const server = new Server(config);
expect(server.config.db).toEqual({
host: 'db.thenile.dev',
port: 5432,
Expand All @@ -24,7 +24,7 @@ describe('server', () => {
user: 'username',
password: 'password',
};
const nile = new Nile(config);
const nile = new Server(config);
nile.tenantId = 'tenantId';
nile.userId = 'userId';
for (const api in nile.api) {
Expand All @@ -39,7 +39,7 @@ describe('server', () => {
user: 'username',
password: 'password',
};
const nile = new Nile(config);
const nile = new Server(config);

const another = nile.getInstance({
databaseId: 'somethingelse?!',
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('server', () => {
user: 'username',
password: 'password',
};
const nile = new Nile(config);
const nile = new Server(config);

const another = nile.getInstance({
databaseId: 'somethingelse?!',
Expand Down
10 changes: 8 additions & 2 deletions packages/server/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const init = (config: Config): Api => {
};
};

class Server {
export class Server {
config: Config;
api: Api;
private manager: DbManager;
Expand Down Expand Up @@ -63,6 +63,7 @@ class Server {
this.setConfig(updatedConfig);
this.manager = new DbManager(this.config);
this.api = init(updatedConfig);
return this;
}

set databaseId(val: string | void) {
Expand Down Expand Up @@ -156,4 +157,9 @@ class Server {
}
}

export default Server;
export async function create(config?: ServerConfig): Promise<Server> {
const server = new Server(config);
return await server.init();
}

export default create;
19 changes: 11 additions & 8 deletions packages/server/src/db/PoolProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export function createProxyForPool(pool: Pool, config: Config): Pool {
return new Proxy<Pool>(pool, {
get(target: AllowAny, property) {
if (property === 'query') {
if (!config.user || !config.password) {
error(
'Cannot connect to the database. User and/or password are missing. Generate them at https://console.thenile.dev'
);
} else if (!config.db.database) {
error(
'Database id is missing from the config. Either call `nile.init()` when you create the NileDB server or set NILEDB_ID in your .env'
);
// give connection string a pass for these problems
if (!config.db.connectionString) {
if (!config.user || !config.password) {
error(
'Cannot connect to the database. User and/or password are missing. Generate them at https://console.thenile.dev'
);
} else if (!config.db.database) {
error(
'Database name is missing from the config. Call `nile.init()` or set NILEDB_ID in your .env'
);
}
}
const caller = target[property];
return function query(...args: AllowAny) {
Expand Down
8 changes: 5 additions & 3 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './types';
import { default as Server } from './Server';
import create from './Server';

export default Server;
export { Server } from './Server';

module.exports = Server;
export default create;

module.exports = create;
5 changes: 2 additions & 3 deletions packages/server/src/utils/Config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ export class Config {
}

constructor(config: ServerConfig) {
const envVarConfig: EnvConfig = {
config,
};
const envVarConfig: EnvConfig = { config };

this.databaseId = getDatbaseId(envVarConfig) as string;
this.user = getUsername(envVarConfig) as string;
this.password = getPassword(envVarConfig) as string;
Expand Down
5 changes: 2 additions & 3 deletions packages/server/test/integration/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Server from '../../src/Server';
import Nile, { Server } from '../../src/Server';
import { ServerConfig } from '../../src/types';

async function toJSON(body: BodyInit) {
Expand Down Expand Up @@ -58,8 +58,7 @@ describe.skip('api integration', () => {

describe.skip('db integration', () => {
it('queries', async () => {
const nile = new Server(config);
await nile.init();
const nile = await Nile(config);
const res = await nile.db.query('select * from tenants');
expect(res.rowCount).toBeGreaterThan(0);
});
Expand Down

0 comments on commit b9af518

Please sign in to comment.