Skip to content

Commit

Permalink
DBConnection -> DbConnection + some comments (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutiertyler authored Feb 11, 2025
1 parent dd34adf commit 066b92d
Show file tree
Hide file tree
Showing 54 changed files with 268 additions and 250 deletions.
14 changes: 7 additions & 7 deletions examples/quickstart-chat/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import './App.css';
import {
DBConnection,
DbConnection,
ErrorContext,
EventContext,
Message,
Expand All @@ -14,7 +14,7 @@ export type PrettyMessage = {
text: string;
};

function useMessages(conn: DBConnection | null): Message[] {
function useMessages(conn: DbConnection | null): Message[] {
const [messages, setMessages] = useState<Message[]>([]);

useEffect(() => {
Expand Down Expand Up @@ -45,7 +45,7 @@ function useMessages(conn: DBConnection | null): Message[] {
return messages;
}

function useUsers(conn: DBConnection | null): Map<string, User> {
function useUsers(conn: DbConnection | null): Map<string, User> {
const [users, setUsers] = useState<Map<string, User>>(new Map());

useEffect(() => {
Expand Down Expand Up @@ -88,10 +88,10 @@ function App() {
const [newMessage, setNewMessage] = useState('');
const [connected, setConnected] = useState<boolean>(false);
const [identity, setIdentity] = useState<Identity | null>(null);
const [conn, setConn] = useState<DBConnection | null>(null);
const [conn, setConn] = useState<DbConnection | null>(null);

useEffect(() => {
const subscribeToQueries = (conn: DBConnection, queries: string[]) => {
const subscribeToQueries = (conn: DbConnection, queries: string[]) => {
let count = 0;
for (const query of queries) {
conn
Expand All @@ -107,7 +107,7 @@ function App() {
};

const onConnect = (
conn: DBConnection,
conn: DbConnection,
identity: Identity,
token: string
) => {
Expand Down Expand Up @@ -135,7 +135,7 @@ function App() {
};

setConn(
DBConnection.builder()
DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('quickstart-chat')
.withToken(localStorage.getItem('auth_token') || '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
32 changes: 16 additions & 16 deletions examples/quickstart-chat/src/module_bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down Expand Up @@ -81,24 +81,24 @@ const REMOTE_MODULE = {
argsType: SetName.getTypeScriptAlgebraicType(),
},
},
// Constructors which are used by the DBConnectionImpl to
// Constructors which are used by the DbConnectionImpl to
// extract type information from the generated RemoteModule.
//
// NOTE: This is not strictly necessary for `eventContextConstructor` because
// all we do is build a TypeScript object which we could have done inside the
// SDK, but if in the future we wanted to create a class this would be
// necessary because classes have methods, so we'll keep it.
eventContextConstructor: (imp: DBConnectionImpl, event: Event<Reducer>) => {
eventContextConstructor: (imp: DbConnectionImpl, event: Event<Reducer>) => {
return {
...(imp as DBConnection),
...(imp as DbConnection),
event,
};
},
dbViewConstructor: (imp: DBConnectionImpl) => {
dbViewConstructor: (imp: DbConnectionImpl) => {
return new RemoteTables(imp);
},
reducersConstructor: (
imp: DBConnectionImpl,
imp: DbConnectionImpl,
setReducerFlags: SetReducerFlags
) => {
return new RemoteReducers(imp, setReducerFlags);
Expand All @@ -118,7 +118,7 @@ export type Reducer =

export class RemoteReducers {
constructor(
private connection: DBConnectionImpl,
private connection: DbConnectionImpl,
private setCallReducerFlags: SetReducerFlags
) {}

Expand Down Expand Up @@ -194,7 +194,7 @@ export class SetReducerFlags {
}

export class RemoteTables {
constructor(private connection: DBConnectionImpl) {}
constructor(private connection: DbConnectionImpl) {}

get message(): MessageTableHandle {
return new MessageTableHandle(
Expand All @@ -219,21 +219,21 @@ export class SubscriptionBuilder extends SubscriptionBuilderImpl<
SetReducerFlags
> {}

export class DBConnection extends DBConnectionImpl<
export class DbConnection extends DbConnectionImpl<
RemoteTables,
RemoteReducers,
SetReducerFlags
> {
static builder = (): DBConnectionBuilder<
DBConnection,
static builder = (): DbConnectionBuilder<
DbConnection,
ErrorContext,
SubscriptionEventContex
> => {
return new DBConnectionBuilder<
DBConnection,
return new DbConnectionBuilder<
DbConnection,
ErrorContext,
SubscriptionEventContex
>(REMOTE_MODULE, (imp: DBConnectionImpl) => imp as DBConnection);
>(REMOTE_MODULE, (imp: DbConnectionImpl) => imp as DbConnection);
};
subscriptionBuilder = (): SubscriptionBuilder => {
return new SubscriptionBuilder(this);
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart-chat/src/module_bindings/message_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart-chat/src/module_bindings/message_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart-chat/src/module_bindings/user_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart-chat/src/module_bindings/user_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryReader,
BinaryWriter,
CallReducerFlags,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ You can use the package in the browser, using a bundler like vite/parcel/rsbuild
In order to connect to a database you have to generate module bindings for your database.

```ts
import { DBConnection } from './module_bindings';
import { DbConnection } from './module_bindings';

const connection = DBConnection.builder()
const connection = DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('MODULE_NAME')
.onDisconnect(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/bsatn_row_list_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/call_reducer_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/client_message_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/compressable_query_update_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/database_update_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/energy_quanta_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/client_api/identity_token_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
BinaryWriter,
CallReducerFlags,
ConnectionId,
DBConnectionBuilder,
DBConnectionImpl,
DBContext,
DbConnectionBuilder,
DbConnectionImpl,
DbContext,
ErrorContextInterface,
Event,
EventContextInterface,
Expand Down
Loading

0 comments on commit 066b92d

Please sign in to comment.