Skip to content

Commit 240d4fe

Browse files
authored
Client address support for TypeScript SDK (#23)
See clockworklabs/SpacetimeDB#299
1 parent 1764040 commit 240d4fe

File tree

10 files changed

+1060
-212
lines changed

10 files changed

+1060
-212
lines changed

examples/quickstart/client/src/module_bindings/message.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AlgebraicValue,
1515
ReducerEvent,
1616
Identity,
17+
Address,
1718
} from "@clockworklabs/spacetimedb-sdk";
1819

1920
export class Message extends IDatabaseTable {
@@ -36,7 +37,7 @@ export class Message extends IDatabaseTable {
3637
public static getAlgebraicType(): AlgebraicType {
3738
return AlgebraicType.createProductType([
3839
new ProductTypeElement(
39-
"Sender",
40+
"sender",
4041
AlgebraicType.createProductType([
4142
new ProductTypeElement(
4243
"__identity_bytes",
@@ -47,24 +48,24 @@ export class Message extends IDatabaseTable {
4748
])
4849
),
4950
new ProductTypeElement(
50-
"Sent",
51-
AlgebraicType.createPrimitiveType(BuiltinType.Type.I64)
51+
"sent",
52+
AlgebraicType.createPrimitiveType(BuiltinType.Type.U64)
5253
),
5354
new ProductTypeElement(
54-
"Text",
55+
"text",
5556
AlgebraicType.createPrimitiveType(BuiltinType.Type.String)
5657
),
5758
]);
5859
}
5960

6061
public static fromValue(value: AlgebraicValue): Message {
6162
let productValue = value.asProductValue();
62-
let __Sender = new Identity(
63+
let __sender = new Identity(
6364
productValue.elements[0].asProductValue().elements[0].asBytes()
6465
);
65-
let __Sent = productValue.elements[1].asNumber();
66-
let __Text = productValue.elements[2].asString();
67-
return new this(__Sender, __Sent, __Text);
66+
let __sent = productValue.elements[1].asNumber();
67+
let __text = productValue.elements[2].asString();
68+
return new this(__sender, __sent, __text);
6869
}
6970

7071
public static count(): number {

examples/quickstart/client/src/module_bindings/send_message_reducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SumTypeVariant,
1515
Serializer,
1616
Identity,
17+
Address,
1718
ReducerEvent,
1819
} from "@clockworklabs/spacetimedb-sdk";
1920

@@ -25,7 +26,7 @@ export class SendMessageReducer {
2526
BuiltinType.Type.String
2627
);
2728
serializer.write(_textType, _text);
28-
__SPACETIMEDB__.spacetimeDBClient.call("SendMessage", serializer);
29+
__SPACETIMEDB__.spacetimeDBClient.call("send_message", serializer);
2930
}
3031
}
3132

examples/quickstart/client/src/module_bindings/set_name_reducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SumTypeVariant,
1515
Serializer,
1616
Identity,
17+
Address,
1718
ReducerEvent,
1819
} from "@clockworklabs/spacetimedb-sdk";
1920

@@ -25,7 +26,7 @@ export class SetNameReducer {
2526
BuiltinType.Type.String
2627
);
2728
serializer.write(_nameType, _name);
28-
__SPACETIMEDB__.spacetimeDBClient.call("SetName", serializer);
29+
__SPACETIMEDB__.spacetimeDBClient.call("set_name", serializer);
2930
}
3031
}
3132

examples/quickstart/client/src/module_bindings/user.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AlgebraicValue,
1515
ReducerEvent,
1616
Identity,
17+
Address,
1718
} from "@clockworklabs/spacetimedb-sdk";
1819

1920
export class User extends IDatabaseTable {
@@ -42,7 +43,7 @@ export class User extends IDatabaseTable {
4243
public static getAlgebraicType(): AlgebraicType {
4344
return AlgebraicType.createProductType([
4445
new ProductTypeElement(
45-
"Identity",
46+
"identity",
4647
AlgebraicType.createProductType([
4748
new ProductTypeElement(
4849
"__identity_bytes",
@@ -53,7 +54,7 @@ export class User extends IDatabaseTable {
5354
])
5455
),
5556
new ProductTypeElement(
56-
"Name",
57+
"name",
5758
AlgebraicType.createSumType([
5859
new SumTypeVariant(
5960
"some",
@@ -63,23 +64,23 @@ export class User extends IDatabaseTable {
6364
])
6465
),
6566
new ProductTypeElement(
66-
"Online",
67+
"online",
6768
AlgebraicType.createPrimitiveType(BuiltinType.Type.Bool)
6869
),
6970
]);
7071
}
7172

7273
public static fromValue(value: AlgebraicValue): User {
7374
let productValue = value.asProductValue();
74-
let __Identity = new Identity(
75+
let __identity = new Identity(
7576
productValue.elements[0].asProductValue().elements[0].asBytes()
7677
);
77-
let __Name =
78+
let __name =
7879
productValue.elements[1].asSumValue().tag == 1
7980
? null
8081
: productValue.elements[1].asSumValue().value.asString();
81-
let __Online = productValue.elements[2].asBoolean();
82-
return new this(__Identity, __Name, __Online);
82+
let __online = productValue.elements[2].asBoolean();
83+
return new this(__identity, __name, __online);
8384
}
8485

8586
public static count(): number {

0 commit comments

Comments
 (0)