Skip to content

Updates the TypesScript SDK to use the new EventContext variants #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions examples/quickstart-chat/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function App() {
'Connected to SpacetimeDB with identity:',
identity.toHexString()
);
conn.reducers.onSendMessage(() => {
console.log('Message sent.');
});
conn
.subscriptionBuilder()
.onApplied(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import {
// @ts-ignore
Address,
// @ts-ignore
AlgebraicType,
// @ts-ignore
AlgebraicValue,
// @ts-ignore
BinaryReader,
// @ts-ignore
BinaryWriter,
// @ts-ignore
CallReducerFlags,
// @ts-ignore
DBConnectionBuilder,
// @ts-ignore
DBConnectionImpl,
// @ts-ignore
DBContext,
// @ts-ignore
ErrorContextInterface,
Event,
// @ts-ignore
EventContextInterface,
// @ts-ignore
Identity,
// @ts-ignore
ProductType,
// @ts-ignore
ProductTypeElement,
// @ts-ignore
ReducerEventContextInterface,
SubscriptionBuilderImpl,
SubscriptionEventContextInterface,
SumType,
// @ts-ignore
SumTypeVariant,
// @ts-ignore
TableCache,
// @ts-ignore
deepEqual,
} from '@clockworklabs/spacetimedb-sdk';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import {
// @ts-ignore
Address,
// @ts-ignore
AlgebraicType,
// @ts-ignore
AlgebraicValue,
// @ts-ignore
BinaryReader,
// @ts-ignore
BinaryWriter,
// @ts-ignore
CallReducerFlags,
// @ts-ignore
DBConnectionBuilder,
// @ts-ignore
DBConnectionImpl,
// @ts-ignore
DBContext,
// @ts-ignore
ErrorContextInterface,
Event,
// @ts-ignore
EventContextInterface,
// @ts-ignore
Identity,
// @ts-ignore
ProductType,
// @ts-ignore
ProductTypeElement,
// @ts-ignore
ReducerEventContextInterface,
SubscriptionBuilderImpl,
SubscriptionEventContextInterface,
SumType,
// @ts-ignore
SumTypeVariant,
// @ts-ignore
TableCache,
// @ts-ignore
deepEqual,
} from '@clockworklabs/spacetimedb-sdk';

Expand Down
73 changes: 47 additions & 26 deletions examples/quickstart-chat/src/module_bindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import {
// @ts-ignore
Address,
// @ts-ignore
AlgebraicType,
// @ts-ignore
AlgebraicValue,
// @ts-ignore
BinaryReader,
// @ts-ignore
BinaryWriter,
// @ts-ignore
CallReducerFlags,
// @ts-ignore
DBConnectionBuilder,
// @ts-ignore
DBConnectionImpl,
// @ts-ignore
DBContext,
// @ts-ignore
ErrorContextInterface,
Event,
// @ts-ignore
EventContextInterface,
// @ts-ignore
Identity,
// @ts-ignore
ProductType,
// @ts-ignore
ProductTypeElement,
// @ts-ignore
ReducerEventContextInterface,
SubscriptionBuilderImpl,
SubscriptionEventContextInterface,
SumType,
// @ts-ignore
SumTypeVariant,
// @ts-ignore
TableCache,
// @ts-ignore
deepEqual,
} from '@clockworklabs/spacetimedb-sdk';

Expand Down Expand Up @@ -94,6 +83,11 @@ const REMOTE_MODULE = {
},
// Constructors which are used by the DBConnectionImpl to
// extract type information from the generated RemoteModule.
//
// NOTE: This is not strictly necessary for `eventContextConstructor` because
// all we do is build a TypeScript object which we could have done inside the
// SDK, but if in the future we wanted to create a class this would be
// necessary because classes have methods, so we'll keep it.
eventContextConstructor: (imp: DBConnectionImpl, event: Event<Reducer>) => {
return {
...(imp as DBConnection),
Expand Down Expand Up @@ -128,19 +122,19 @@ export class RemoteReducers {
private setCallReducerFlags: SetReducerFlags
) {}

onIdentityConnected(callback: (ctx: EventContext) => void) {
onIdentityConnected(callback: (ctx: ReducerEventContext) => void) {
this.connection.onReducer('identity_connected', callback);
}

removeOnIdentityConnected(callback: (ctx: EventContext) => void) {
removeOnIdentityConnected(callback: (ctx: ReducerEventContext) => void) {
this.connection.offReducer('identity_connected', callback);
}

onIdentityDisconnected(callback: (ctx: EventContext) => void) {
onIdentityDisconnected(callback: (ctx: ReducerEventContext) => void) {
this.connection.onReducer('identity_disconnected', callback);
}

removeOnIdentityDisconnected(callback: (ctx: EventContext) => void) {
removeOnIdentityDisconnected(callback: (ctx: ReducerEventContext) => void) {
this.connection.offReducer('identity_disconnected', callback);
}

Expand All @@ -156,11 +150,13 @@ export class RemoteReducers {
);
}

onSendMessage(callback: (ctx: EventContext, text: string) => void) {
onSendMessage(callback: (ctx: ReducerEventContext, text: string) => void) {
this.connection.onReducer('send_message', callback);
}

removeOnSendMessage(callback: (ctx: EventContext, text: string) => void) {
removeOnSendMessage(
callback: (ctx: ReducerEventContext, text: string) => void
) {
this.connection.offReducer('send_message', callback);
}

Expand All @@ -176,11 +172,11 @@ export class RemoteReducers {
);
}

onSetName(callback: (ctx: EventContext, name: string) => void) {
onSetName(callback: (ctx: ReducerEventContext, name: string) => void) {
this.connection.onReducer('set_name', callback);
}

removeOnSetName(callback: (ctx: EventContext, name: string) => void) {
removeOnSetName(callback: (ctx: ReducerEventContext, name: string) => void) {
this.connection.offReducer('set_name', callback);
}
}
Expand Down Expand Up @@ -217,6 +213,12 @@ export class RemoteTables {
}
}

export class SubscriptionBuilder extends SubscriptionBuilderImpl<
RemoteTables,
RemoteReducers,
SetReducerFlags
> {}

export class DBConnection extends DBConnectionImpl<
RemoteTables,
RemoteReducers,
Expand All @@ -228,6 +230,9 @@ export class DBConnection extends DBConnectionImpl<
(imp: DBConnectionImpl) => imp as DBConnection
);
};
subscriptionBuilder = (): SubscriptionBuilder => {
return new SubscriptionBuilder(this);
};
}

export type EventContext = EventContextInterface<
Expand All @@ -236,3 +241,19 @@ export type EventContext = EventContextInterface<
SetReducerFlags,
Reducer
>;
export type ReducerEventContext = ReducerEventContextInterface<
RemoteTables,
RemoteReducers,
SetReducerFlags,
Reducer
>;
export type SubscriptionEventContext = SubscriptionEventContextInterface<
RemoteTables,
RemoteReducers,
SetReducerFlags
>;
export type ErrorContext = ErrorContextInterface<
RemoteTables,
RemoteReducers,
SetReducerFlags
>;
26 changes: 7 additions & 19 deletions examples/quickstart-chat/src/module_bindings/message_table.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import {
// @ts-ignore
Address,
// @ts-ignore
AlgebraicType,
// @ts-ignore
AlgebraicValue,
// @ts-ignore
BinaryReader,
// @ts-ignore
BinaryWriter,
// @ts-ignore
CallReducerFlags,
// @ts-ignore
DBConnectionBuilder,
// @ts-ignore
DBConnectionImpl,
// @ts-ignore
DBContext,
// @ts-ignore
ErrorContextInterface,
Event,
// @ts-ignore
EventContextInterface,
// @ts-ignore
Identity,
// @ts-ignore
ProductType,
// @ts-ignore
ProductTypeElement,
// @ts-ignore
ReducerEventContextInterface,
SubscriptionBuilderImpl,
SubscriptionEventContextInterface,
SumType,
// @ts-ignore
SumTypeVariant,
// @ts-ignore
TableCache,
// @ts-ignore
deepEqual,
} from '@clockworklabs/spacetimedb-sdk';
import { Message } from './message_type';
// @ts-ignore
import { EventContext, Reducer, RemoteReducers, RemoteTables } from '.';

/**
Expand Down
25 changes: 7 additions & 18 deletions examples/quickstart-chat/src/module_bindings/message_type.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import {
// @ts-ignore
Address,
// @ts-ignore
AlgebraicType,
// @ts-ignore
AlgebraicValue,
// @ts-ignore
BinaryReader,
// @ts-ignore
BinaryWriter,
// @ts-ignore
CallReducerFlags,
// @ts-ignore
DBConnectionBuilder,
// @ts-ignore
DBConnectionImpl,
// @ts-ignore
DBContext,
// @ts-ignore
ErrorContextInterface,
Event,
// @ts-ignore
EventContextInterface,
// @ts-ignore
Identity,
// @ts-ignore
ProductType,
// @ts-ignore
ProductTypeElement,
// @ts-ignore
ReducerEventContextInterface,
SubscriptionBuilderImpl,
SubscriptionEventContextInterface,
SumType,
// @ts-ignore
SumTypeVariant,
// @ts-ignore
TableCache,
// @ts-ignore
deepEqual,
} from '@clockworklabs/spacetimedb-sdk';
export type Message = {
Expand Down
Loading
Loading