@@ -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,70 +82,100 @@ 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 : ( imp : DBConnectionImpl , setReducerFlags : SetReducerFlags ) => {
91
+ reducersConstructor : (
92
+ imp : DBConnectionImpl ,
93
+ setReducerFlags : SetReducerFlags
94
+ ) => {
92
95
return new RemoteReducers ( imp , setReducerFlags ) ;
93
- }
96
+ } ,
94
97
setReducerFlagsConstructor : ( ) => {
95
98
return new SetReducerFlags ( ) ;
96
- }
97
- }
99
+ } ,
100
+ } ;
98
101
99
102
// A type representing all the possible variants of a reducer.
100
- export type Reducer = never
101
- | { name : "CreatePlayer" , args : CreatePlayer }
102
- ;
103
+ export type Reducer = never | { name : 'CreatePlayer' ; args : CreatePlayer } ;
103
104
104
105
export class RemoteReducers {
105
- constructor ( private connection : DBConnectionImpl , private setCallReducerFlags : SetReducerFlags ) { }
106
+ constructor (
107
+ private connection : DBConnectionImpl ,
108
+ private setCallReducerFlags : SetReducerFlags
109
+ ) { }
106
110
107
111
createPlayer ( name : string , location : Point ) {
108
112
const __args = { name, location } ;
109
113
let __writer = new BinaryWriter ( 1024 ) ;
110
114
CreatePlayer . getTypeScriptAlgebraicType ( ) . serialize ( __writer , __args ) ;
111
115
let __argsBuffer = __writer . getBuffer ( ) ;
112
- this . connection . callReducer ( "create_player" , __argsBuffer , this . setCallReducerFlags . createPlayerFlags ) ;
116
+ this . connection . callReducer (
117
+ 'create_player' ,
118
+ __argsBuffer ,
119
+ this . setCallReducerFlags . createPlayerFlags
120
+ ) ;
113
121
}
114
122
115
- onCreatePlayer ( callback : ( ctx : EventContext , name : string , location : Point ) => void ) {
116
- this . connection . onReducer ( "create_player" , callback ) ;
123
+ onCreatePlayer (
124
+ callback : ( ctx : EventContext , name : string , location : Point ) => void
125
+ ) {
126
+ this . connection . onReducer ( 'create_player' , callback ) ;
117
127
}
118
128
119
- removeOnCreatePlayer ( callback : ( ctx : EventContext , name : string , location : Point ) => void ) {
120
- this . connection . offReducer ( "create_player" , callback ) ;
129
+ removeOnCreatePlayer (
130
+ callback : ( ctx : EventContext , name : string , location : Point ) => void
131
+ ) {
132
+ this . connection . offReducer ( 'create_player' , callback ) ;
121
133
}
122
-
123
134
}
124
135
125
136
export class SetReducerFlags {
126
- createPlayerFlags : CallReducerFlags ;
137
+ createPlayerFlags : CallReducerFlags = 'FullUpdate' ;
127
138
createPlayer ( flags : CallReducerFlags ) {
128
139
this . createPlayerFlags = flags ;
129
140
}
130
-
131
141
}
132
142
133
143
export class RemoteTables {
134
144
constructor ( private connection : DBConnectionImpl ) { }
135
145
136
146
get player ( ) : PlayerTableHandle {
137
- return new PlayerTableHandle ( this . connection . clientCache . getOrCreateTable < Player > ( REMOTE_MODULE . tables . player ) ) ;
147
+ return new PlayerTableHandle (
148
+ this . connection . clientCache . getOrCreateTable < Player > (
149
+ REMOTE_MODULE . tables . player
150
+ )
151
+ ) ;
138
152
}
139
153
140
154
get user ( ) : UserTableHandle {
141
- return new UserTableHandle ( this . connection . clientCache . getOrCreateTable < User > ( REMOTE_MODULE . tables . user ) ) ;
155
+ return new UserTableHandle (
156
+ this . connection . clientCache . getOrCreateTable < User > (
157
+ REMOTE_MODULE . tables . user
158
+ )
159
+ ) ;
142
160
}
143
161
}
144
162
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
- }
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
+ } ;
149
174
}
150
175
151
- export type EventContext = EventContextInterface < RemoteTables , RemoteReducers , SetReducerFlags , Reducer > ;
176
+ export type EventContext = EventContextInterface <
177
+ RemoteTables ,
178
+ RemoteReducers ,
179
+ SetReducerFlags ,
180
+ Reducer
181
+ > ;
0 commit comments