Skip to content

Commit

Permalink
flatten SATS + convenience APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 19, 2023
1 parent b1c04c4 commit 0a95252
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 491 deletions.
9 changes: 3 additions & 6 deletions examples/quickstart/client/src/module_bindings/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__SPACETIMEDB__,
AlgebraicType,
ProductType,
BuiltinType,
ProductTypeElement,
SumType,
SumTypeVariant,
Expand Down Expand Up @@ -41,19 +40,17 @@ export class Message extends IDatabaseTable {
AlgebraicType.createProductType([
new ProductTypeElement(
"__identity_bytes",
AlgebraicType.createArrayType(
AlgebraicType.createPrimitiveType(BuiltinType.Type.U8)
)
AlgebraicType.createBytesType()
),
])
),
new ProductTypeElement(
"sent",
AlgebraicType.createPrimitiveType(BuiltinType.Type.U64)
AlgebraicType.createU64Type()
),
new ProductTypeElement(
"text",
AlgebraicType.createPrimitiveType(BuiltinType.Type.String)
AlgebraicType.createStringType()
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__SPACETIMEDB__,
AlgebraicType,
ProductType,
BuiltinType,
ProductTypeElement,
IDatabaseTable,
AlgebraicValue,
Expand All @@ -22,16 +21,14 @@ export class SendMessageReducer {
public static call(_text: string) {
if (__SPACETIMEDB__.spacetimeDBClient) {
const serializer = __SPACETIMEDB__.spacetimeDBClient.getSerializer();
let _textType = AlgebraicType.createPrimitiveType(
BuiltinType.Type.String
);
let _textType = AlgebraicType.createStringType();
serializer.write(_textType, _text);
__SPACETIMEDB__.spacetimeDBClient.call("send_message", serializer);
}
}

public static deserializeArgs(adapter: ReducerArgsAdapter): any[] {
let textType = AlgebraicType.createPrimitiveType(BuiltinType.Type.String);
let textType = AlgebraicType.createStringType();
let textValue = AlgebraicValue.deserialize(textType, adapter.next());
let text = textValue.asString();
return [text];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__SPACETIMEDB__,
AlgebraicType,
ProductType,
BuiltinType,
ProductTypeElement,
IDatabaseTable,
AlgebraicValue,
Expand All @@ -22,16 +21,14 @@ export class SetNameReducer {
public static call(_name: string) {
if (__SPACETIMEDB__.spacetimeDBClient) {
const serializer = __SPACETIMEDB__.spacetimeDBClient.getSerializer();
let _nameType = AlgebraicType.createPrimitiveType(
BuiltinType.Type.String
);
let _nameType = AlgebraicType.createStringType();
serializer.write(_nameType, _name);
__SPACETIMEDB__.spacetimeDBClient.call("set_name", serializer);
}
}

public static deserializeArgs(adapter: ReducerArgsAdapter): any[] {
let nameType = AlgebraicType.createPrimitiveType(BuiltinType.Type.String);
let nameType = AlgebraicType.createStringType();
let nameValue = AlgebraicValue.deserialize(nameType, adapter.next());
let name = nameValue.asString();
return [name];
Expand Down
9 changes: 3 additions & 6 deletions examples/quickstart/client/src/module_bindings/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__SPACETIMEDB__,
AlgebraicType,
ProductType,
BuiltinType,
ProductTypeElement,
SumType,
SumTypeVariant,
Expand Down Expand Up @@ -47,9 +46,7 @@ export class User extends IDatabaseTable {
AlgebraicType.createProductType([
new ProductTypeElement(
"__identity_bytes",
AlgebraicType.createArrayType(
AlgebraicType.createPrimitiveType(BuiltinType.Type.U8)
)
AlgebraicType.createBytesType()
),
])
),
Expand All @@ -58,14 +55,14 @@ export class User extends IDatabaseTable {
AlgebraicType.createSumType([
new SumTypeVariant(
"some",
AlgebraicType.createPrimitiveType(BuiltinType.Type.String)
AlgebraicType.createStringType()
),
new SumTypeVariant("none", AlgebraicType.createProductType([])),
])
),
new ProductTypeElement(
"online",
AlgebraicType.createPrimitiveType(BuiltinType.Type.Bool)
AlgebraicType.createBoolType()
),
]);
}
Expand Down
Loading

0 comments on commit 0a95252

Please sign in to comment.