Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6529827
Big prototype
cloutiertyler Nov 3, 2025
e9c0a6f
RemoteModule-ify
cloutiertyler Nov 3, 2025
541f493
Smaller fixes
cloutiertyler Nov 3, 2025
5da15d8
Cleaning up where code lives
cloutiertyler Nov 3, 2025
269ad2f
Small fixes
cloutiertyler Nov 3, 2025
051fb27
About to try new code gen
cloutiertyler Nov 4, 2025
83a23f9
Almost there, just in a bit of a pickle
cloutiertyler Nov 4, 2025
ae3556e
Fixed many small issues, now begin the AlgebraicType stuff
cloutiertyler Nov 5, 2025
05e663f
clusterfuck
cloutiertyler Nov 5, 2025
55fba2e
Sweet jesus it builds
cloutiertyler Nov 5, 2025
7099b65
Sweet heavens I think it's alive
cloutiertyler Nov 5, 2025
0bb2976
It finally builds successfully
cloutiertyler Nov 6, 2025
0b0b06d
Small comment
cloutiertyler Nov 6, 2025
08dba2f
Living the dream
cloutiertyler Nov 8, 2025
3f3e6a6
Progress!
cloutiertyler Nov 8, 2025
ac4e15a
It is magnifico
cloutiertyler Nov 9, 2025
16814cb
Small adjustments
cloutiertyler Nov 9, 2025
384f8b0
pnpm format
cloutiertyler Nov 9, 2025
cb16789
Removed generation of variant types since they can now be derived fro…
cloutiertyler Nov 9, 2025
6782e5e
merge master
cloutiertyler Nov 9, 2025
d398d25
pnpm format
cloutiertyler Nov 9, 2025
c61fae7
cargo fmt
cloutiertyler Nov 9, 2025
64b3404
misconfigured import
cloutiertyler Nov 9, 2025
31243a7
Fixed broken type tests
cloutiertyler Nov 9, 2025
57bd49b
Fixed up the API a bit to have fewer breaking changes
cloutiertyler Nov 10, 2025
dadd620
Implemented all the index stuff
cloutiertyler Nov 11, 2025
ffa5336
Good Heavens all the tests pass
cloutiertyler Nov 11, 2025
4d2aff4
pnpm format
cloutiertyler Nov 11, 2025
6d5e575
cargo fmt
cloutiertyler Nov 11, 2025
487d5a3
formatting
cloutiertyler Nov 11, 2025
256d04f
Builds, tests, works
cloutiertyler Nov 11, 2025
181e50f
Formatting
cloutiertyler Nov 11, 2025
fe91e78
Merged master
cloutiertyler Nov 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ function App() {
const [settingName, setSettingName] = useState(false);
const [systemMessages, setSystemMessages] = useState([] as Message[]);
const [newMessage, setNewMessage] = useState('');

const conn = useSpacetimeDB<DbConnection>();

conn.setReducerFlags();
const { identity, isActive: connected } = conn;

// Subscribe to all messages in the chat
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bindings-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export { default as BinaryWriter } from './lib/binary_writer';
export * from './lib/schedule_at';
export * from './lib/time_duration';
export * from './lib/timestamp';
export * from './lib/utils';
export * from './lib/util';
export * from './lib/identity';
export * from './lib/option';
export * from './sdk';
198 changes: 80 additions & 118 deletions crates/bindings-typescript/src/lib/algebraic_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ import { ConnectionId } from './connection_id';
import type BinaryReader from './binary_reader';
import BinaryWriter from './binary_writer';
import { Identity } from './identity';
import { Option } from './option';
import {
AlgebraicType as AlgebraicTypeType,
AlgebraicType as AlgebraicTypeValue,
} from './autogen/algebraic_type_type';
import {
type ProductType as ProductTypeType,
ProductType as ProductTypeValue,
} from './autogen/product_type_type';
import {
type SumType as SumTypeType,
SumType as SumTypeValue,
} from './autogen/sum_type_type';
import ScheduleAt from './schedule_at';
import type Typespace from './autogen/typespace_type';
import * as AlgebraicTypeVariants from './algebraic_type_variants';

type TypespaceType = {
types: AlgebraicTypeType[];
};

export type ProductTypeType = {
elements: ProductTypeElement[];
};

/**
* A factor / element of a product type.
Expand All @@ -28,101 +22,96 @@ import type Typespace from './autogen/typespace_type';
* NOTE: Each element has an implicit element tag based on its order.
* Uniquely identifies an element similarly to protobuf tags.
*/
export * from './autogen/product_type_element_type';
export type ProductTypeElement = {
name: string | undefined;
algebraicType: AlgebraicTypeType;
};

export type SumTypeType = {
variants: SumTypeVariant[];
};

/**
* A variant of a sum type.
*
* NOTE: Each element has an implicit element tag based on its order.
* Uniquely identifies an element similarly to protobuf tags.
*/
export * from './autogen/sum_type_variant_type';
export type SumTypeVariant = {
name: string | undefined;
algebraicType: AlgebraicTypeType;
};

/**
* The variant types of the Algebraic Type tagged union.
*/
export type * as AlgebraicTypeVariants from './autogen/algebraic_type_variants';
export type AlgebraicTypeType =
| AlgebraicTypeVariants.Ref
| AlgebraicTypeVariants.Sum
| AlgebraicTypeVariants.Product
| AlgebraicTypeVariants.Array
| AlgebraicTypeVariants.String
| AlgebraicTypeVariants.Bool
| AlgebraicTypeVariants.I8
| AlgebraicTypeVariants.U8
| AlgebraicTypeVariants.I16
| AlgebraicTypeVariants.U16
| AlgebraicTypeVariants.I32
| AlgebraicTypeVariants.U32
| AlgebraicTypeVariants.I64
| AlgebraicTypeVariants.U64
| AlgebraicTypeVariants.I128
| AlgebraicTypeVariants.U128
| AlgebraicTypeVariants.I256
| AlgebraicTypeVariants.U256
| AlgebraicTypeVariants.F32
| AlgebraicTypeVariants.F64;

/**
* The SpacetimeDB Algebraic Type System (SATS) is a structural type system in
* which a nominal type system can be constructed.
*
* The type system unifies the concepts sum types, product types, and built-in
* primitive types into a single type system.
*/
export type AlgebraicType = AlgebraicTypeType;

/**
* Algebraic Type utilities.
* The variant types of the Algebraic Type tagged union.
*/
export const AlgebraicType: {
Sum<T extends SumType>(value: T): { tag: 'Sum'; value: T };
Product<T extends ProductType>(value: T): { tag: 'Product'; value: T };
Array<T extends AlgebraicType>(value: T): { tag: 'Array'; value: T };
export { AlgebraicTypeVariants };

createOptionType(innerType: AlgebraicTypeType): AlgebraicTypeType;
createIdentityType(): AlgebraicTypeType;
createConnectionIdType(): AlgebraicTypeType;
createScheduleAtType(): AlgebraicTypeType;
createTimestampType(): AlgebraicTypeType;
createTimeDurationType(): AlgebraicTypeType;
serializeValue(
writer: BinaryWriter,
ty: AlgebraicTypeType,
value: any,
typespace?: Typespace
): void;
deserializeValue(
reader: BinaryReader,
ty: AlgebraicTypeType,
typespace?: Typespace
): any;
/**
* Convert a value of the algebraic type into something that can be used as a key in a map.
* There are no guarantees about being able to order it.
* This is only guaranteed to be comparable to other values of the same type.
* @param value A value of the algebraic type
* @returns Something that can be used as a key in a map.
*/
intoMapKey(ty: AlgebraicTypeType, value: any): ComparablePrimitive;
} & typeof AlgebraicTypeValue = {
...AlgebraicTypeValue,
Sum: <T extends SumType>(value: T): { tag: 'Sum'; value: T } => ({
// A value with helper functions to construct the type.
export const AlgebraicType = {
Ref: (value: number): AlgebraicTypeVariants.Ref => ({ tag: 'Ref', value }),
Sum: <T extends SumTypeType>(value: T): { tag: 'Sum'; value: T } => ({
tag: 'Sum',
value,
}),
Product: <T extends ProductType>(value: T): { tag: 'Product'; value: T } => ({
Product: <T extends ProductTypeType>(
value: T
): { tag: 'Product'; value: T } => ({
tag: 'Product',
value,
}),
Array: <T extends AlgebraicType>(value: T): { tag: 'Array'; value: T } => ({
Array: <T extends AlgebraicTypeType>(
value: T
): { tag: 'Array'; value: T } => ({
tag: 'Array',
value,
}),
createOptionType: function (innerType: AlgebraicTypeType): AlgebraicTypeType {
return Option.getAlgebraicType(innerType);
},
createIdentityType: function (): AlgebraicTypeType {
return Identity.getAlgebraicType();
},
createConnectionIdType: function (): AlgebraicTypeType {
return ConnectionId.getAlgebraicType();
},
createScheduleAtType: function (): AlgebraicTypeType {
return ScheduleAt.getAlgebraicType();
},
createTimestampType: function (): AlgebraicTypeType {
return Timestamp.getAlgebraicType();
},
createTimeDurationType: function (): AlgebraicTypeType {
return TimeDuration.getAlgebraicType();
},
serializeValue: function (
String: { tag: 'String' } as const,
Bool: { tag: 'Bool' } as const,
I8: { tag: 'I8' } as const,
U8: { tag: 'U8' } as const,
I16: { tag: 'I16' } as const,
U16: { tag: 'U16' } as const,
I32: { tag: 'I32' } as const,
U32: { tag: 'U32' } as const,
I64: { tag: 'I64' } as const,
U64: { tag: 'U64' } as const,
I128: { tag: 'I128' } as const,
U128: { tag: 'U128' } as const,
I256: { tag: 'I256' } as const,
U256: { tag: 'U256' } as const,
F32: { tag: 'F32' } as const,
F64: { tag: 'F64' } as const,
serializeValue(
writer: BinaryWriter,
ty: AlgebraicTypeType,
value: any,
typespace?: Typespace
): void {
typespace?: TypespaceType
) {
if (ty.tag === 'Ref') {
if (!typespace)
throw new Error('cannot serialize refs without a typespace');
Expand Down Expand Up @@ -199,7 +188,7 @@ export const AlgebraicType: {
deserializeValue: function (
reader: BinaryReader,
ty: AlgebraicTypeType,
typespace?: Typespace
typespace?: TypespaceType
): any {
if (ty.tag === 'Ref') {
if (!typespace)
Expand Down Expand Up @@ -327,26 +316,12 @@ export const AlgebraicType: {
*/
export type ProductType = ProductTypeType;

export const ProductType: {
serializeValue(
writer: BinaryWriter,
ty: ProductTypeType,
value: any,
typespace?: Typespace
): void;
deserializeValue(
reader: BinaryReader,
ty: ProductTypeType,
typespace?: Typespace
): any;
intoMapKey(ty: ProductTypeType, value: any): ComparablePrimitive;
} = {
...ProductTypeValue,
export const ProductType = {
serializeValue(
writer: BinaryWriter,
ty: ProductTypeType,
value: any,
typespace?: Typespace
typespace?: TypespaceType
): void {
for (const element of ty.elements) {
AlgebraicType.serializeValue(
Expand All @@ -360,7 +335,7 @@ export const ProductType: {
deserializeValue(
reader: BinaryReader,
ty: ProductTypeType,
typespace?: Typespace
typespace?: TypespaceType
): any {
const result: { [key: string]: any } = {};
if (ty.elements.length === 1) {
Expand Down Expand Up @@ -441,25 +416,12 @@ export type SumType = SumTypeType;
*
* [structural]: https://en.wikipedia.org/wiki/Structural_type_system
*/
export const SumType: {
serializeValue(
writer: BinaryWriter,
ty: SumTypeType,
value: any,
typespace?: Typespace
): void;
deserializeValue(
reader: BinaryReader,
ty: SumTypeType,
typespace?: Typespace
): any;
} = {
...SumTypeValue,
export const SumType = {
serializeValue: function (
writer: BinaryWriter,
ty: SumTypeType,
value: any,
typespace?: Typespace
typespace?: TypespaceType
): void {
if (
ty.variants.length == 2 &&
Expand Down Expand Up @@ -495,7 +457,7 @@ export const SumType: {
deserializeValue: function (
reader: BinaryReader,
ty: SumTypeType,
typespace?: Typespace
typespace?: TypespaceType
): any {
const tag = reader.readU8();
// In TypeScript we handle Option values as a special case
Expand Down
26 changes: 26 additions & 0 deletions crates/bindings-typescript/src/lib/algebraic_type_variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type {
AlgebraicTypeType,
ProductTypeType,
SumTypeType,
} from './algebraic_type';

export type Ref = { tag: 'Ref'; value: number };
export type Sum = { tag: 'Sum'; value: SumTypeType };
export type Product = { tag: 'Product'; value: ProductTypeType };
export type Array = { tag: 'Array'; value: AlgebraicTypeType };
export type String = { tag: 'String' };
export type Bool = { tag: 'Bool' };
export type I8 = { tag: 'I8' };
export type U8 = { tag: 'U8' };
export type I16 = { tag: 'I16' };
export type U16 = { tag: 'U16' };
export type I32 = { tag: 'I32' };
export type U32 = { tag: 'U32' };
export type I64 = { tag: 'I64' };
export type U64 = { tag: 'U64' };
export type I128 = { tag: 'I128' };
export type U128 = { tag: 'U128' };
export type I256 = { tag: 'I256' };
export type U256 = { tag: 'U256' };
export type F32 = { tag: 'F32' };
export type F64 = { tag: 'F64' };
Loading
Loading