From 038059b4d26bbe8591c9271466c311f6efb58c28 Mon Sep 17 00:00:00 2001 From: Puru Vijay Date: Wed, 23 Oct 2024 00:49:10 +0530 Subject: [PATCH] Push creds --- packages/test-app/src/App.tsx | 4 +- .../test-app/src/module_bindings/index.ts | 104 +++++++++++------- 2 files changed, 69 insertions(+), 39 deletions(-) diff --git a/packages/test-app/src/App.tsx b/packages/test-app/src/App.tsx index 599a057..c4a1008 100644 --- a/packages/test-app/src/App.tsx +++ b/packages/test-app/src/App.tsx @@ -24,9 +24,9 @@ function App() { }) .withCredentials([ Identity.fromString( - '93dda09db9a56d8fa6c024d843e805d8262191db3b4ba84c5efcd1ad451fed4e' + 'c200c4018ee1d21bb54b0379bedb68643ca1dd209710e504fac2a41d43567fb2' ), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiI5M2RkYTA5ZGI5YTU2ZDhmYTZjMDI0ZDg0M2U4MDVkODI2MjE5MWRiM2I0YmE4NGM1ZWZjZDFhZDQ1MWZlZDRlIiwiaWF0IjoxNzI4MzY3NDk0LCJleHAiOm51bGx9.ua3DQaiXo5i3Ye0okughs84PV9uZLCnov26zvCMG-3ibqGg6vH0uDDY6L-zDf8XiFgUqEIcvnJvuKLThPDipjQ', + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiJjMjAwYzQwMThlZTFkMjFiYjU0YjAzNzliZWRiNjg2NDNjYTFkZDIwOTcxMGU1MDRmYWMyYTQxZDQzNTY3ZmIyIiwic3ViIjoiYjNhZWRmNDgtZDExNC00MmVjLWI0Y2EtNmY5MjAwNjk2OGJmIiwiaXNzIjoibG9jYWxob3N0IiwiYXVkIjpbInNwYWNldGltZWRiIl0sImlhdCI6MTcyOTYyMTI2NiwiZXhwIjpudWxsfQ.TIJGisLeX3SuN8_9horfk2NifEGjCutq4wh7Fm5Qfp1-vhpKWmFCtAY0MRuYdalQtaWXT0bQ2seHlXA4PkOGbg', ]) .build() ); diff --git a/packages/test-app/src/module_bindings/index.ts b/packages/test-app/src/module_bindings/index.ts index 12b6b9b..25ef6f3 100644 --- a/packages/test-app/src/module_bindings/index.ts +++ b/packages/test-app/src/module_bindings/index.ts @@ -38,42 +38,42 @@ import { TableCache, // @ts-ignore deepEqual, -} from "@clockworklabs/spacetimedb-sdk"; +} from '@clockworklabs/spacetimedb-sdk'; // Import and reexport all reducer arg types -import { CreatePlayer } from "./create_player_reducer.ts"; +import { CreatePlayer } from './create_player_reducer.ts'; export { CreatePlayer }; // Import and reexport all table handle types -import { PlayerTableHandle } from "./player_table.ts"; +import { PlayerTableHandle } from './player_table.ts'; export { PlayerTableHandle }; -import { UserTableHandle } from "./user_table.ts"; +import { UserTableHandle } from './user_table.ts'; export { UserTableHandle }; // Import and reexport all types -import { Player } from "./player_type.ts"; +import { Player } from './player_type.ts'; export { Player }; -import { Point } from "./point_type.ts"; +import { Point } from './point_type.ts'; export { Point }; -import { User } from "./user_type.ts"; +import { User } from './user_type.ts'; export { User }; const REMOTE_MODULE = { tables: { player: { - tableName: "player", + tableName: 'player', rowType: Player.getTypeScriptAlgebraicType(), - primaryKey: "owner_id", + primaryKey: 'owner_id', }, user: { - tableName: "user", + tableName: 'user', rowType: User.getTypeScriptAlgebraicType(), - primaryKey: "identity", + primaryKey: 'identity', }, }, reducers: { create_player: { - reducerName: "create_player", + reducerName: 'create_player', argsType: CreatePlayer.getTypeScriptAlgebraicType(), }, }, @@ -82,70 +82,100 @@ const REMOTE_MODULE = { eventContextConstructor: (imp: DBConnectionImpl, event: Event) => { return { ...(imp as DBConnection), - event - } + event, + }; }, dbViewConstructor: (imp: DBConnectionImpl) => { return new RemoteTables(imp); }, - reducersConstructor: (imp: DBConnectionImpl, setReducerFlags: SetReducerFlags) => { + reducersConstructor: ( + imp: DBConnectionImpl, + setReducerFlags: SetReducerFlags + ) => { return new RemoteReducers(imp, setReducerFlags); - } + }, setReducerFlagsConstructor: () => { return new SetReducerFlags(); - } -} + }, +}; // A type representing all the possible variants of a reducer. -export type Reducer = never -| { name: "CreatePlayer", args: CreatePlayer } -; +export type Reducer = never | { name: 'CreatePlayer'; args: CreatePlayer }; export class RemoteReducers { - constructor(private connection: DBConnectionImpl, private setCallReducerFlags: SetReducerFlags) {} + constructor( + private connection: DBConnectionImpl, + private setCallReducerFlags: SetReducerFlags + ) {} createPlayer(name: string, location: Point) { const __args = { name, location }; let __writer = new BinaryWriter(1024); CreatePlayer.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); - this.connection.callReducer("create_player", __argsBuffer, this.setCallReducerFlags.createPlayerFlags); + this.connection.callReducer( + 'create_player', + __argsBuffer, + this.setCallReducerFlags.createPlayerFlags + ); } - onCreatePlayer(callback: (ctx: EventContext, name: string, location: Point) => void) { - this.connection.onReducer("create_player", callback); + onCreatePlayer( + callback: (ctx: EventContext, name: string, location: Point) => void + ) { + this.connection.onReducer('create_player', callback); } - removeOnCreatePlayer(callback: (ctx: EventContext, name: string, location: Point) => void) { - this.connection.offReducer("create_player", callback); + removeOnCreatePlayer( + callback: (ctx: EventContext, name: string, location: Point) => void + ) { + this.connection.offReducer('create_player', callback); } - } export class SetReducerFlags { - createPlayerFlags: CallReducerFlags; + createPlayerFlags: CallReducerFlags = 'FullUpdate'; createPlayer(flags: CallReducerFlags) { this.createPlayerFlags = flags; } - } export class RemoteTables { constructor(private connection: DBConnectionImpl) {} get player(): PlayerTableHandle { - return new PlayerTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.player)); + return new PlayerTableHandle( + this.connection.clientCache.getOrCreateTable( + REMOTE_MODULE.tables.player + ) + ); } get user(): UserTableHandle { - return new UserTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.user)); + return new UserTableHandle( + this.connection.clientCache.getOrCreateTable( + REMOTE_MODULE.tables.user + ) + ); } } -export class DBConnection extends DBConnectionImpl { - static builder = (): DBConnectionBuilder => { - return new DBConnectionBuilder(REMOTE_MODULE, (imp: DBConnectionImpl) => imp as DBConnection); - } +export class DBConnection extends DBConnectionImpl< + RemoteTables, + RemoteReducers, + SetReducerFlags +> { + static builder = (): DBConnectionBuilder => { + return new DBConnectionBuilder( + REMOTE_MODULE, + (imp: DBConnectionImpl) => imp as DBConnection + ); + }; } -export type EventContext = EventContextInterface; +export type EventContext = EventContextInterface< + RemoteTables, + RemoteReducers, + SetReducerFlags, + Reducer +>;