@@ -38,42 +38,42 @@ import {
38
38
TableCache ,
39
39
// @ts -ignore
40
40
deepEqual ,
41
- } from ' @clockworklabs/spacetimedb-sdk' ;
41
+ } from " @clockworklabs/spacetimedb-sdk" ;
42
42
43
43
// Import and reexport all reducer arg types
44
- import { CreatePlayer } from ' ./create_player_reducer.ts' ;
44
+ import { CreatePlayer } from " ./create_player_reducer.ts" ;
45
45
export { CreatePlayer } ;
46
46
47
47
// Import and reexport all table handle types
48
- import { PlayerTableHandle } from ' ./player_table.ts' ;
48
+ import { PlayerTableHandle } from " ./player_table.ts" ;
49
49
export { PlayerTableHandle } ;
50
- import { UserTableHandle } from ' ./user_table.ts' ;
50
+ import { UserTableHandle } from " ./user_table.ts" ;
51
51
export { UserTableHandle } ;
52
52
53
53
// Import and reexport all types
54
- import { Player } from ' ./player_type.ts' ;
54
+ import { Player } from " ./player_type.ts" ;
55
55
export { Player } ;
56
- import { Point } from ' ./point_type.ts' ;
56
+ import { Point } from " ./point_type.ts" ;
57
57
export { Point } ;
58
- import { User } from ' ./user_type.ts' ;
58
+ import { User } from " ./user_type.ts" ;
59
59
export { User } ;
60
60
61
61
const REMOTE_MODULE = {
62
62
tables : {
63
63
player : {
64
- tableName : ' player' ,
64
+ tableName : " player" ,
65
65
rowType : Player . getTypeScriptAlgebraicType ( ) ,
66
- primaryKey : ' owner_id' ,
66
+ primaryKey : " owner_id" ,
67
67
} ,
68
68
user : {
69
- tableName : ' user' ,
69
+ tableName : " user" ,
70
70
rowType : User . getTypeScriptAlgebraicType ( ) ,
71
- primaryKey : ' identity' ,
71
+ primaryKey : " identity" ,
72
72
} ,
73
73
} ,
74
74
reducers : {
75
75
create_player : {
76
- reducerName : ' create_player' ,
76
+ reducerName : " create_player" ,
77
77
argsType : CreatePlayer . getTypeScriptAlgebraicType ( ) ,
78
78
} ,
79
79
} ,
@@ -82,100 +82,70 @@ const REMOTE_MODULE = {
82
82
eventContextConstructor : ( imp : DBConnectionImpl , event : Event < Reducer > ) => {
83
83
return {
84
84
...( imp as DBConnection ) ,
85
- event,
86
- } ;
85
+ event
86
+ }
87
87
} ,
88
88
dbViewConstructor : ( imp : DBConnectionImpl ) => {
89
89
return new RemoteTables ( imp ) ;
90
90
} ,
91
- reducersConstructor : (
92
- imp : DBConnectionImpl ,
93
- setReducerFlags : SetReducerFlags
94
- ) => {
91
+ reducersConstructor : ( imp : DBConnectionImpl , setReducerFlags : SetReducerFlags ) => {
95
92
return new RemoteReducers ( imp , setReducerFlags ) ;
96
- } ,
93
+ }
97
94
setReducerFlagsConstructor : ( ) = > {
98
95
return new SetReducerFlags ( ) ;
99
- } ,
100
- } ;
96
+ }
97
+ }
101
98
102
99
// A type representing all the possible variants of a reducer.
103
- export type Reducer = never | { name : 'CreatePlayer' ; args : CreatePlayer } ;
100
+ export type Reducer = never
101
+ | { name : "CreatePlayer" , args : CreatePlayer }
102
+ ;
104
103
105
104
export class RemoteReducers {
106
- constructor (
107
- private connection : DBConnectionImpl ,
108
- private setCallReducerFlags : SetReducerFlags
109
- ) { }
105
+ constructor ( private connection : DBConnectionImpl , private setCallReducerFlags : SetReducerFlags ) { }
110
106
111
107
createPlayer ( name : string , location : Point ) {
112
108
const __args = { name, location } ;
113
109
let __writer = new BinaryWriter ( 1024 ) ;
114
110
CreatePlayer . getTypeScriptAlgebraicType ( ) . serialize ( __writer , __args ) ;
115
111
let __argsBuffer = __writer . getBuffer ( ) ;
116
- this . connection . callReducer (
117
- 'create_player' ,
118
- __argsBuffer ,
119
- this . setCallReducerFlags . createPlayerFlags
120
- ) ;
112
+ this . connection . callReducer ( "create_player" , __argsBuffer , this . setCallReducerFlags . createPlayerFlags ) ;
121
113
}
122
114
123
- onCreatePlayer (
124
- callback : ( ctx : EventContext , name : string , location : Point ) => void
125
- ) {
126
- this . connection . onReducer ( 'create_player' , callback ) ;
115
+ onCreatePlayer ( callback : ( ctx : EventContext , name : string , location : Point ) => void ) {
116
+ this . connection . onReducer ( "create_player" , callback ) ;
127
117
}
128
118
129
- removeOnCreatePlayer (
130
- callback : ( ctx : EventContext , name : string , location : Point ) => void
131
- ) {
132
- this . connection . offReducer ( 'create_player' , callback ) ;
119
+ removeOnCreatePlayer ( callback : ( ctx : EventContext , name : string , location : Point ) => void ) {
120
+ this . connection . offReducer ( "create_player" , callback ) ;
133
121
}
122
+
134
123
}
135
124
136
125
export class SetReducerFlags {
137
126
createPlayerFlags : CallReducerFlags ;
138
127
createPlayer ( flags : CallReducerFlags ) {
139
128
this . createPlayerFlags = flags ;
140
129
}
130
+
141
131
}
142
132
143
133
export class RemoteTables {
144
134
constructor ( private connection : DBConnectionImpl ) { }
145
135
146
136
get player ( ) : PlayerTableHandle {
147
- return new PlayerTableHandle (
148
- this . connection . clientCache . getOrCreateTable < Player > (
149
- REMOTE_MODULE . tables . player
150
- )
151
- ) ;
137
+ return new PlayerTableHandle ( this . connection . clientCache . getOrCreateTable < Player > ( REMOTE_MODULE . tables . player ) ) ;
152
138
}
153
139
154
140
get user ( ) : UserTableHandle {
155
- return new UserTableHandle (
156
- this . connection . clientCache . getOrCreateTable < User > (
157
- REMOTE_MODULE . tables . user
158
- )
159
- ) ;
141
+ return new UserTableHandle ( this . connection . clientCache . getOrCreateTable < User > ( REMOTE_MODULE . tables . user ) ) ;
160
142
}
161
143
}
162
144
163
- export class DBConnection extends DBConnectionImpl <
164
- RemoteTables ,
165
- RemoteReducers ,
166
- SetReducerFlags
167
- > {
168
- static builder = ( ) : DBConnectionBuilder < DBConnection > => {
169
- return new DBConnectionBuilder < DBConnection > (
170
- REMOTE_MODULE ,
171
- ( imp : DBConnectionImpl ) => imp as DBConnection
172
- ) ;
173
- } ;
145
+ export class DBConnection extends DBConnectionImpl < RemoteTables , RemoteReducers , SetReducerFlags > {
146
+ static builder = ( ) : DBConnectionBuilder < DBConnection > => {
147
+ return new DBConnectionBuilder < DBConnection > ( REMOTE_MODULE , ( imp : DBConnectionImpl ) => imp as DBConnection ) ;
148
+ }
174
149
}
175
150
176
- export type EventContext = EventContextInterface <
177
- RemoteTables ,
178
- RemoteReducers ,
179
- SetReducerFlags ,
180
- Reducer
181
- > ;
151
+ export type EventContext = EventContextInterface < RemoteTables , RemoteReducers , SetReducerFlags , Reducer > ;
0 commit comments