Skip to content

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

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 29 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0c36b82
Updated the quickstart to use the new 1.0 API
cloutiertyler Jan 22, 2025
a1b85c1
Ran prettier
cloutiertyler Jan 22, 2025
cee497f
Updated CSS
cloutiertyler Jan 24, 2025
667c0fc
Removed server code
cloutiertyler Jan 28, 2025
145e818
Moved out of the client dir
cloutiertyler Jan 28, 2025
d6a03d7
Updated lockfile
cloutiertyler Jan 28, 2025
f2a8ac8
Added new workflow
cloutiertyler Jan 28, 2025
56120e8
Small fixes
cloutiertyler Jan 28, 2025
4102fd3
Updated PR template
cloutiertyler Jan 28, 2025
9c099fe
Ran prettier
cloutiertyler Jan 28, 2025
5ba8bf3
Fixes to workflwo
cloutiertyler Jan 28, 2025
40f7cb4
Workflow fixes
cloutiertyler Jan 28, 2025
8a1d28b
Fixes the toolchain thing
cloutiertyler Jan 28, 2025
4d308ca
Added SpacetimeDB integration test
cloutiertyler Jan 28, 2025
2a1f7ce
Fix workflow hopefully
cloutiertyler Jan 28, 2025
4aa5bcc
Fix workflow
cloutiertyler Jan 28, 2025
1422830
Prettier
cloutiertyler Jan 28, 2025
2a84f67
Updated pull request template to better reflect the reality
cloutiertyler Jan 28, 2025
f409b64
Fixed path in workflow
cloutiertyler Jan 28, 2025
40901c1
Prettier after codegen
cloutiertyler Jan 28, 2025
422f8b0
Regenerate
cloutiertyler Jan 28, 2025
340ec7f
Say yes to deleting data
cloutiertyler Jan 28, 2025
e06824d
Updated codegen to latest master of SpacetimeDB
cloutiertyler Feb 6, 2025
5224d68
debug actions
cloutiertyler Feb 6, 2025
b549cce
Formatting
cloutiertyler Feb 6, 2025
09df431
Implemented EventContext update
cloutiertyler Feb 7, 2025
71062c8
Removed unused imports
cloutiertyler Feb 7, 2025
1970fc7
Merge main
cloutiertyler Feb 8, 2025
3e921af
Fix merge marker
cloutiertyler Feb 8, 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
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