Skip to content

Commit b62ca68

Browse files
committed
Run generate
1 parent 608a522 commit b62ca68

File tree

8 files changed

+120
-135
lines changed

8 files changed

+120
-135
lines changed

packages/test-app/src/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ function App() {
2626
Identity.fromString(
2727
'93dda09db9a56d8fa6c024d843e805d8262191db3b4ba84c5efcd1ad451fed4e'
2828
),
29-
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiI5M2RkYTA5ZGI5YTU2ZDhmYTZjMDI0ZDg0M2U4MDVkODI2MjE5MWRiM2I0YmE4NGM1ZWZjZDFhZDQ1MWZlZDRlIiwiaWF0IjoxNzI4Mzc5MjE2LCJleHAiOm51bGx9.dKanuJu7xKg_g3toOBO09Po3ZgxnHnUwZYpwbEwjrHWGkRzNSL9sLRNjKatUR7OXmwd9b0pCTray4GUt0VlCGg',
29+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiI5M2RkYTA5ZGI5YTU2ZDhmYTZjMDI0ZDg0M2U4MDVkODI2MjE5MWRiM2I0YmE4NGM1ZWZjZDFhZDQ1MWZlZDRlIiwiaWF0IjoxNzI4MzY3NDk0LCJleHAiOm51bGx9.ua3DQaiXo5i3Ye0okughs84PV9uZLCnov26zvCMG-3ibqGg6vH0uDDY6L-zDf8XiFgUqEIcvnJvuKLThPDipjQ',
3030
])
3131
.build()
3232
);
3333

3434
useEffect(() => {
35-
connection.db.player.onInsert((ctx, player) => {
36-
console.log(ctx, player);
35+
connection.db.player.onInsert(player => {
36+
console.log(player);
3737
});
3838

3939
setTimeout(() => {

packages/test-app/src/module_bindings/create_player_reducer.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
// @ts-ignore
1414
BinaryWriter,
1515
// @ts-ignore
16+
CallReducerFlags,
17+
// @ts-ignore
1618
DBConnectionBuilder,
1719
// @ts-ignore
1820
DBConnectionImpl,
@@ -36,28 +38,28 @@ import {
3638
TableCache,
3739
// @ts-ignore
3840
deepEqual,
39-
} from '@clockworklabs/spacetimedb-sdk';
41+
} from "@clockworklabs/spacetimedb-sdk";
4042

4143
// @ts-ignore
42-
import { Point as __Point } from './point_type';
44+
import { Point as __Point } from "./point_type";
4345

4446
export type CreatePlayer = {
45-
name: string;
46-
location: __Point;
47+
name: string,
48+
location: __Point,
4749
};
4850

4951
/**
5052
* A namespace for generated helper functions.
5153
*/
5254
export namespace CreatePlayer {
5355
/**
54-
* A function which returns this type represented as an AlgebraicType.
55-
* This function is derived from the AlgebraicType used to generate this type.
56-
*/
56+
* A function which returns this type represented as an AlgebraicType.
57+
* This function is derived from the AlgebraicType used to generate this type.
58+
*/
5759
export function getTypeScriptAlgebraicType(): AlgebraicType {
5860
return AlgebraicType.createProductType([
59-
new ProductTypeElement('name', AlgebraicType.createStringType()),
60-
new ProductTypeElement('location', __Point.getTypeScriptAlgebraicType()),
61+
new ProductTypeElement("name", AlgebraicType.createStringType()),
62+
new ProductTypeElement("location", __Point.getTypeScriptAlgebraicType()),
6163
]);
6264
}
6365

@@ -68,4 +70,6 @@ export namespace CreatePlayer {
6870
export function deserialize(reader: BinaryReader): CreatePlayer {
6971
return CreatePlayer.getTypeScriptAlgebraicType().deserialize(reader);
7072
}
73+
7174
}
75+

packages/test-app/src/module_bindings/index.ts

+36-66
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,42 @@ import {
3838
TableCache,
3939
// @ts-ignore
4040
deepEqual,
41-
} from '@clockworklabs/spacetimedb-sdk';
41+
} from "@clockworklabs/spacetimedb-sdk";
4242

4343
// Import and reexport all reducer arg types
44-
import { CreatePlayer } from './create_player_reducer.ts';
44+
import { CreatePlayer } from "./create_player_reducer.ts";
4545
export { CreatePlayer };
4646

4747
// Import and reexport all table handle types
48-
import { PlayerTableHandle } from './player_table.ts';
48+
import { PlayerTableHandle } from "./player_table.ts";
4949
export { PlayerTableHandle };
50-
import { UserTableHandle } from './user_table.ts';
50+
import { UserTableHandle } from "./user_table.ts";
5151
export { UserTableHandle };
5252

5353
// Import and reexport all types
54-
import { Player } from './player_type.ts';
54+
import { Player } from "./player_type.ts";
5555
export { Player };
56-
import { Point } from './point_type.ts';
56+
import { Point } from "./point_type.ts";
5757
export { Point };
58-
import { User } from './user_type.ts';
58+
import { User } from "./user_type.ts";
5959
export { User };
6060

6161
const REMOTE_MODULE = {
6262
tables: {
6363
player: {
64-
tableName: 'player',
64+
tableName: "player",
6565
rowType: Player.getTypeScriptAlgebraicType(),
66-
primaryKey: 'owner_id',
66+
primaryKey: "owner_id",
6767
},
6868
user: {
69-
tableName: 'user',
69+
tableName: "user",
7070
rowType: User.getTypeScriptAlgebraicType(),
71-
primaryKey: 'identity',
71+
primaryKey: "identity",
7272
},
7373
},
7474
reducers: {
7575
create_player: {
76-
reducerName: 'create_player',
76+
reducerName: "create_player",
7777
argsType: CreatePlayer.getTypeScriptAlgebraicType(),
7878
},
7979
},
@@ -82,100 +82,70 @@ const REMOTE_MODULE = {
8282
eventContextConstructor: (imp: DBConnectionImpl, event: Event<Reducer>) => {
8383
return {
8484
...(imp as DBConnection),
85-
event,
86-
};
85+
event
86+
}
8787
},
8888
dbViewConstructor: (imp: DBConnectionImpl) => {
8989
return new RemoteTables(imp);
9090
},
91-
reducersConstructor: (
92-
imp: DBConnectionImpl,
93-
setReducerFlags: SetReducerFlags
94-
) => {
91+
reducersConstructor: (imp: DBConnectionImpl, setReducerFlags: SetReducerFlags) => {
9592
return new RemoteReducers(imp, setReducerFlags);
96-
},
93+
}
9794
setReducerFlagsConstructor: () => {
9895
return new SetReducerFlags();
99-
},
100-
};
96+
}
97+
}
10198

10299
// 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+
;
104103

105104
export class RemoteReducers {
106-
constructor(
107-
private connection: DBConnectionImpl,
108-
private setCallReducerFlags: SetReducerFlags
109-
) {}
105+
constructor(private connection: DBConnectionImpl, private setCallReducerFlags: SetReducerFlags) {}
110106

111107
createPlayer(name: string, location: Point) {
112108
const __args = { name, location };
113109
let __writer = new BinaryWriter(1024);
114110
CreatePlayer.getTypeScriptAlgebraicType().serialize(__writer, __args);
115111
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);
121113
}
122114

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);
127117
}
128118

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);
133121
}
122+
134123
}
135124

136125
export class SetReducerFlags {
137126
createPlayerFlags: CallReducerFlags;
138127
createPlayer(flags: CallReducerFlags) {
139128
this.createPlayerFlags = flags;
140129
}
130+
141131
}
142132

143133
export class RemoteTables {
144134
constructor(private connection: DBConnectionImpl) {}
145135

146136
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));
152138
}
153139

154140
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));
160142
}
161143
}
162144

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+
}
174149
}
175150

176-
export type EventContext = EventContextInterface<
177-
RemoteTables,
178-
RemoteReducers,
179-
SetReducerFlags,
180-
Reducer
181-
>;
151+
export type EventContext = EventContextInterface<RemoteTables, RemoteReducers, SetReducerFlags, Reducer>;

packages/test-app/src/module_bindings/player_table.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
// @ts-ignore
1414
BinaryWriter,
1515
// @ts-ignore
16+
CallReducerFlags,
17+
// @ts-ignore
1618
DBConnectionBuilder,
1719
// @ts-ignore
1820
DBConnectionImpl,
@@ -36,13 +38,13 @@ import {
3638
TableCache,
3739
// @ts-ignore
3840
deepEqual,
39-
} from '@clockworklabs/spacetimedb-sdk';
40-
import { Player } from './player_type';
41+
} from "@clockworklabs/spacetimedb-sdk";
42+
import { Player } from "./player_type";
4143
// @ts-ignore
42-
import { Point as __Point } from './point_type';
44+
import { Point as __Point } from "./point_type";
4345

4446
// @ts-ignore
45-
import { EventContext, Reducer, RemoteReducers, RemoteTables } from '.';
47+
import { EventContext, Reducer, RemoteReducers, RemoteTables } from ".";
4648

4749
/**
4850
* Table handle for the table `player`.
@@ -93,30 +95,25 @@ export class PlayerTableHandle {
9395

9496
onInsert = (cb: (ctx: EventContext, row: Player) => void) => {
9597
return this.tableCache.onInsert(cb);
96-
};
98+
}
9799

98100
removeOnInsert = (cb: (ctx: EventContext, row: Player) => void) => {
99101
return this.tableCache.removeOnInsert(cb);
100-
};
102+
}
101103

102104
onDelete = (cb: (ctx: EventContext, row: Player) => void) => {
103105
return this.tableCache.onDelete(cb);
104-
};
106+
}
105107

106108
removeOnDelete = (cb: (ctx: EventContext, row: Player) => void) => {
107109
return this.tableCache.removeOnDelete(cb);
108-
};
110+
}
109111

110112
// Updates are only defined for tables with primary keys.
111-
onUpdate = (
112-
cb: (ctx: EventContext, oldRow: Player, newRow: Player) => void
113-
) => {
113+
onUpdate = (cb: (ctx: EventContext, oldRow: Player, newRow: Player) => void) => {
114114
return this.tableCache.onUpdate(cb);
115-
};
115+
}
116116

117-
removeOnUpdate = (
118-
cb: (ctx: EventContext, onRow: Player, newRow: Player) => void
119-
) => {
117+
removeOnUpdate = (cb: (ctx: EventContext, onRow: Player, newRow: Player) => void) => {
120118
return this.tableCache.removeOnUpdate(cb);
121-
};
122-
}
119+
}}

packages/test-app/src/module_bindings/player_type.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
// @ts-ignore
1414
BinaryWriter,
1515
// @ts-ignore
16+
CallReducerFlags,
17+
// @ts-ignore
1618
DBConnectionBuilder,
1719
// @ts-ignore
1820
DBConnectionImpl,
@@ -36,29 +38,29 @@ import {
3638
TableCache,
3739
// @ts-ignore
3840
deepEqual,
39-
} from '@clockworklabs/spacetimedb-sdk';
41+
} from "@clockworklabs/spacetimedb-sdk";
4042
// @ts-ignore
41-
import { Point as __Point } from './point_type';
43+
import { Point as __Point } from "./point_type";
4244

4345
export type Player = {
44-
ownerId: string;
45-
name: string;
46-
location: __Point;
46+
ownerId: string,
47+
name: string,
48+
location: __Point,
4749
};
4850

4951
/**
5052
* A namespace for generated helper functions.
5153
*/
5254
export namespace Player {
5355
/**
54-
* A function which returns this type represented as an AlgebraicType.
55-
* This function is derived from the AlgebraicType used to generate this type.
56-
*/
56+
* A function which returns this type represented as an AlgebraicType.
57+
* This function is derived from the AlgebraicType used to generate this type.
58+
*/
5759
export function getTypeScriptAlgebraicType(): AlgebraicType {
5860
return AlgebraicType.createProductType([
59-
new ProductTypeElement('ownerId', AlgebraicType.createStringType()),
60-
new ProductTypeElement('name', AlgebraicType.createStringType()),
61-
new ProductTypeElement('location', __Point.getTypeScriptAlgebraicType()),
61+
new ProductTypeElement("ownerId", AlgebraicType.createStringType()),
62+
new ProductTypeElement("name", AlgebraicType.createStringType()),
63+
new ProductTypeElement("location", __Point.getTypeScriptAlgebraicType()),
6264
]);
6365
}
6466

@@ -69,4 +71,7 @@ export namespace Player {
6971
export function deserialize(reader: BinaryReader): Player {
7072
return Player.getTypeScriptAlgebraicType().deserialize(reader);
7173
}
74+
7275
}
76+
77+

0 commit comments

Comments
 (0)