diff --git a/examples/quickstart-chat/src/App.tsx b/examples/quickstart-chat/src/App.tsx index 755a4de..d6b229d 100644 --- a/examples/quickstart-chat/src/App.tsx +++ b/examples/quickstart-chat/src/App.tsx @@ -97,6 +97,9 @@ function App() { 'Connected to SpacetimeDB with identity:', identity.toHexString() ); + conn.reducers.onSendMessage(() => { + console.log('Message sent.'); + }); conn .subscriptionBuilder() .onApplied(() => { diff --git a/examples/quickstart-chat/src/module_bindings/identity_connected_reducer.ts b/examples/quickstart-chat/src/module_bindings/identity_connected_reducer.ts index c5ffa05..6df7d05 100644 --- a/examples/quickstart-chat/src/module_bindings/identity_connected_reducer.ts +++ b/examples/quickstart-chat/src/module_bindings/identity_connected_reducer.ts @@ -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'; diff --git a/examples/quickstart-chat/src/module_bindings/identity_disconnected_reducer.ts b/examples/quickstart-chat/src/module_bindings/identity_disconnected_reducer.ts index 787659d..95b001f 100644 --- a/examples/quickstart-chat/src/module_bindings/identity_disconnected_reducer.ts +++ b/examples/quickstart-chat/src/module_bindings/identity_disconnected_reducer.ts @@ -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'; diff --git a/examples/quickstart-chat/src/module_bindings/index.ts b/examples/quickstart-chat/src/module_bindings/index.ts index a7f038a..59a762c 100644 --- a/examples/quickstart-chat/src/module_bindings/index.ts +++ b/examples/quickstart-chat/src/module_bindings/index.ts @@ -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'; @@ -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) => { return { ...(imp as DBConnection), @@ -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); } @@ -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); } @@ -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); } } @@ -217,6 +213,12 @@ export class RemoteTables { } } +export class SubscriptionBuilder extends SubscriptionBuilderImpl< + RemoteTables, + RemoteReducers, + SetReducerFlags +> {} + export class DBConnection extends DBConnectionImpl< RemoteTables, RemoteReducers, @@ -228,6 +230,9 @@ export class DBConnection extends DBConnectionImpl< (imp: DBConnectionImpl) => imp as DBConnection ); }; + subscriptionBuilder = (): SubscriptionBuilder => { + return new SubscriptionBuilder(this); + }; } export type EventContext = EventContextInterface< @@ -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 +>; diff --git a/examples/quickstart-chat/src/module_bindings/message_table.ts b/examples/quickstart-chat/src/module_bindings/message_table.ts index efb4abf..d1674c6 100644 --- a/examples/quickstart-chat/src/module_bindings/message_table.ts +++ b/examples/quickstart-chat/src/module_bindings/message_table.ts @@ -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 '.'; /** diff --git a/examples/quickstart-chat/src/module_bindings/message_type.ts b/examples/quickstart-chat/src/module_bindings/message_type.ts index 9b10b84..5fe84e1 100644 --- a/examples/quickstart-chat/src/module_bindings/message_type.ts +++ b/examples/quickstart-chat/src/module_bindings/message_type.ts @@ -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 = { diff --git a/examples/quickstart-chat/src/module_bindings/send_message_reducer.ts b/examples/quickstart-chat/src/module_bindings/send_message_reducer.ts index eb665e3..92c232a 100644 --- a/examples/quickstart-chat/src/module_bindings/send_message_reducer.ts +++ b/examples/quickstart-chat/src/module_bindings/send_message_reducer.ts @@ -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'; diff --git a/examples/quickstart-chat/src/module_bindings/set_name_reducer.ts b/examples/quickstart-chat/src/module_bindings/set_name_reducer.ts index 163997c..970dfa9 100644 --- a/examples/quickstart-chat/src/module_bindings/set_name_reducer.ts +++ b/examples/quickstart-chat/src/module_bindings/set_name_reducer.ts @@ -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'; diff --git a/examples/quickstart-chat/src/module_bindings/user_table.ts b/examples/quickstart-chat/src/module_bindings/user_table.ts index 404beca..0634ed0 100644 --- a/examples/quickstart-chat/src/module_bindings/user_table.ts +++ b/examples/quickstart-chat/src/module_bindings/user_table.ts @@ -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 { User } from './user_type'; -// @ts-ignore import { EventContext, Reducer, RemoteReducers, RemoteTables } from '.'; /** diff --git a/examples/quickstart-chat/src/module_bindings/user_type.ts b/examples/quickstart-chat/src/module_bindings/user_type.ts index 55fb75a..7843649 100644 --- a/examples/quickstart-chat/src/module_bindings/user_type.ts +++ b/examples/quickstart-chat/src/module_bindings/user_type.ts @@ -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 User = { diff --git a/packages/sdk/src/client_api/bsatn_row_list_type.ts b/packages/sdk/src/client_api/bsatn_row_list_type.ts index cf4b2df..70527ff 100644 --- a/packages/sdk/src/client_api/bsatn_row_list_type.ts +++ b/packages/sdk/src/client_api/bsatn_row_list_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { RowSizeHint as __RowSizeHint } from './row_size_hint_type'; export type BsatnRowList = { diff --git a/packages/sdk/src/client_api/call_reducer_type.ts b/packages/sdk/src/client_api/call_reducer_type.ts index 887f3eb..3bcea7b 100644 --- a/packages/sdk/src/client_api/call_reducer_type.ts +++ b/packages/sdk/src/client_api/call_reducer_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type CallReducer = { reducer: string; args: Uint8Array; diff --git a/packages/sdk/src/client_api/client_message_type.ts b/packages/sdk/src/client_api/client_message_type.ts index 5935dff..7b99296 100644 --- a/packages/sdk/src/client_api/client_message_type.ts +++ b/packages/sdk/src/client_api/client_message_type.ts @@ -1,48 +1,38 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { CallReducer as __CallReducer } from './call_reducer_type'; -// @ts-ignore import { Subscribe as __Subscribe } from './subscribe_type'; -// @ts-ignore import { OneOffQuery as __OneOffQuery } from './one_off_query_type'; +import { SubscribeSingle as __SubscribeSingle } from './subscribe_single_type'; +import { Unsubscribe as __Unsubscribe } from './unsubscribe_type'; // A namespace for generated variants and helper functions. export namespace ClientMessage { @@ -52,6 +42,11 @@ export namespace ClientMessage { export type CallReducer = { tag: 'CallReducer'; value: __CallReducer }; export type Subscribe = { tag: 'Subscribe'; value: __Subscribe }; export type OneOffQuery = { tag: 'OneOffQuery'; value: __OneOffQuery }; + export type SubscribeSingle = { + tag: 'SubscribeSingle'; + value: __SubscribeSingle; + }; + export type Unsubscribe = { tag: 'Unsubscribe'; value: __Unsubscribe }; // Helper functions for constructing each variant of the tagged union. // ``` @@ -71,6 +66,14 @@ export namespace ClientMessage { tag: 'OneOffQuery', value, }); + export const SubscribeSingle = (value: __SubscribeSingle): ClientMessage => ({ + tag: 'SubscribeSingle', + value, + }); + export const Unsubscribe = (value: __Unsubscribe): ClientMessage => ({ + tag: 'Unsubscribe', + value, + }); export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ @@ -83,6 +86,14 @@ export namespace ClientMessage { 'OneOffQuery', __OneOffQuery.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'SubscribeSingle', + __SubscribeSingle.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'Unsubscribe', + __Unsubscribe.getTypeScriptAlgebraicType() + ), ]); } @@ -99,6 +110,8 @@ export namespace ClientMessage { export type ClientMessage = | ClientMessage.CallReducer | ClientMessage.Subscribe - | ClientMessage.OneOffQuery; + | ClientMessage.OneOffQuery + | ClientMessage.SubscribeSingle + | ClientMessage.Unsubscribe; export default ClientMessage; diff --git a/packages/sdk/src/client_api/compressable_query_update_type.ts b/packages/sdk/src/client_api/compressable_query_update_type.ts index 3a24364..2bcc968 100644 --- a/packages/sdk/src/client_api/compressable_query_update_type.ts +++ b/packages/sdk/src/client_api/compressable_query_update_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { QueryUpdate as __QueryUpdate } from './query_update_type'; // A namespace for generated variants and helper functions. diff --git a/packages/sdk/src/client_api/database_update_type.ts b/packages/sdk/src/client_api/database_update_type.ts index f0ff9d6..1dcefd4 100644 --- a/packages/sdk/src/client_api/database_update_type.ts +++ b/packages/sdk/src/client_api/database_update_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { TableUpdate as __TableUpdate } from './table_update_type'; export type DatabaseUpdate = { diff --git a/packages/sdk/src/client_api/energy_quanta_type.ts b/packages/sdk/src/client_api/energy_quanta_type.ts index 7556883..5906682 100644 --- a/packages/sdk/src/client_api/energy_quanta_type.ts +++ b/packages/sdk/src/client_api/energy_quanta_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type EnergyQuanta = { quanta: bigint; }; diff --git a/packages/sdk/src/client_api/identity_token_type.ts b/packages/sdk/src/client_api/identity_token_type.ts index cc42522..fdcb08a 100644 --- a/packages/sdk/src/client_api/identity_token_type.ts +++ b/packages/sdk/src/client_api/identity_token_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type IdentityToken = { identity: Identity; token: string; diff --git a/packages/sdk/src/client_api/index.ts b/packages/sdk/src/client_api/index.ts index 1e16e88..b8f3a9c 100644 --- a/packages/sdk/src/client_api/index.ts +++ b/packages/sdk/src/client_api/index.ts @@ -1,44 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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 '..'; +} from '../index'; // Import and reexport all reducer arg types @@ -67,6 +56,8 @@ import { OneOffQueryResponse } from './one_off_query_response_type.ts'; export { OneOffQueryResponse }; import { OneOffTable } from './one_off_table_type.ts'; export { OneOffTable }; +import { QueryId } from './query_id_type.ts'; +export { QueryId }; import { QueryUpdate } from './query_update_type.ts'; export { QueryUpdate }; import { ReducerCallInfo } from './reducer_call_info_type.ts'; @@ -77,6 +68,14 @@ import { ServerMessage } from './server_message_type.ts'; export { ServerMessage }; import { Subscribe } from './subscribe_type.ts'; export { Subscribe }; +import { SubscribeApplied } from './subscribe_applied_type.ts'; +export { SubscribeApplied }; +import { SubscribeRows } from './subscribe_rows_type.ts'; +export { SubscribeRows }; +import { SubscribeSingle } from './subscribe_single_type.ts'; +export { SubscribeSingle }; +import { SubscriptionError } from './subscription_error_type.ts'; +export { SubscriptionError }; import { TableUpdate } from './table_update_type.ts'; export { TableUpdate }; import { Timestamp } from './timestamp_type.ts'; @@ -85,6 +84,10 @@ import { TransactionUpdate } from './transaction_update_type.ts'; export { TransactionUpdate }; import { TransactionUpdateLight } from './transaction_update_light_type.ts'; export { TransactionUpdateLight }; +import { Unsubscribe } from './unsubscribe_type.ts'; +export { Unsubscribe }; +import { UnsubscribeApplied } from './unsubscribe_applied_type.ts'; +export { UnsubscribeApplied }; import { UpdateStatus } from './update_status_type.ts'; export { UpdateStatus }; @@ -93,6 +96,11 @@ const REMOTE_MODULE = { reducers: {}, // 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) => { return { ...(imp as DBConnection), @@ -129,6 +137,12 @@ export class RemoteTables { constructor(private connection: DBConnectionImpl) {} } +export class SubscriptionBuilder extends SubscriptionBuilderImpl< + RemoteTables, + RemoteReducers, + SetReducerFlags +> {} + export class DBConnection extends DBConnectionImpl< RemoteTables, RemoteReducers, @@ -140,6 +154,9 @@ export class DBConnection extends DBConnectionImpl< (imp: DBConnectionImpl) => imp as DBConnection ); }; + subscriptionBuilder = (): SubscriptionBuilder => { + return new SubscriptionBuilder(this); + }; } export type EventContext = EventContextInterface< @@ -148,3 +165,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 +>; diff --git a/packages/sdk/src/client_api/initial_subscription_type.ts b/packages/sdk/src/client_api/initial_subscription_type.ts index 4a3196c..2cfa64c 100644 --- a/packages/sdk/src/client_api/initial_subscription_type.ts +++ b/packages/sdk/src/client_api/initial_subscription_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; export type InitialSubscription = { diff --git a/packages/sdk/src/client_api/one_off_query_response_type.ts b/packages/sdk/src/client_api/one_off_query_response_type.ts index f72d9ff..90138d5 100644 --- a/packages/sdk/src/client_api/one_off_query_response_type.ts +++ b/packages/sdk/src/client_api/one_off_query_response_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { OneOffTable as __OneOffTable } from './one_off_table_type'; export type OneOffQueryResponse = { diff --git a/packages/sdk/src/client_api/one_off_query_type.ts b/packages/sdk/src/client_api/one_off_query_type.ts index 4f81811..4e953ef 100644 --- a/packages/sdk/src/client_api/one_off_query_type.ts +++ b/packages/sdk/src/client_api/one_off_query_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type OneOffQuery = { messageId: Uint8Array; queryString: string; diff --git a/packages/sdk/src/client_api/one_off_table_type.ts b/packages/sdk/src/client_api/one_off_table_type.ts index 4fb6cb2..18089e3 100644 --- a/packages/sdk/src/client_api/one_off_table_type.ts +++ b/packages/sdk/src/client_api/one_off_table_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { BsatnRowList as __BsatnRowList } from './bsatn_row_list_type'; export type OneOffTable = { diff --git a/packages/sdk/src/client_api/query_id_type.ts b/packages/sdk/src/client_api/query_id_type.ts new file mode 100644 index 0000000..8bded14 --- /dev/null +++ b/packages/sdk/src/client_api/query_id_type.ts @@ -0,0 +1,56 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +export type QueryId = { + id: number; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace QueryId { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('id', AlgebraicType.createU32Type()), + ]); + } + + export function serialize(writer: BinaryWriter, value: QueryId): void { + QueryId.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): QueryId { + return QueryId.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/query_update_type.ts b/packages/sdk/src/client_api/query_update_type.ts index 8813286..f308079 100644 --- a/packages/sdk/src/client_api/query_update_type.ts +++ b/packages/sdk/src/client_api/query_update_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { BsatnRowList as __BsatnRowList } from './bsatn_row_list_type'; export type QueryUpdate = { diff --git a/packages/sdk/src/client_api/reducer_call_info_type.ts b/packages/sdk/src/client_api/reducer_call_info_type.ts index 1dc295e..2009f6f 100644 --- a/packages/sdk/src/client_api/reducer_call_info_type.ts +++ b/packages/sdk/src/client_api/reducer_call_info_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type ReducerCallInfo = { reducerName: string; reducerId: number; diff --git a/packages/sdk/src/client_api/row_size_hint_type.ts b/packages/sdk/src/client_api/row_size_hint_type.ts index 15abc5b..8950393 100644 --- a/packages/sdk/src/client_api/row_size_hint_type.ts +++ b/packages/sdk/src/client_api/row_size_hint_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; // A namespace for generated variants and helper functions. export namespace RowSizeHint { // These are the generated variant types for each variant of the tagged union. diff --git a/packages/sdk/src/client_api/server_message_type.ts b/packages/sdk/src/client_api/server_message_type.ts index 54d83cc..128e757 100644 --- a/packages/sdk/src/client_api/server_message_type.ts +++ b/packages/sdk/src/client_api/server_message_type.ts @@ -1,52 +1,41 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { InitialSubscription as __InitialSubscription } from './initial_subscription_type'; -// @ts-ignore import { TransactionUpdate as __TransactionUpdate } from './transaction_update_type'; -// @ts-ignore import { TransactionUpdateLight as __TransactionUpdateLight } from './transaction_update_light_type'; -// @ts-ignore import { IdentityToken as __IdentityToken } from './identity_token_type'; -// @ts-ignore import { OneOffQueryResponse as __OneOffQueryResponse } from './one_off_query_response_type'; +import { SubscribeApplied as __SubscribeApplied } from './subscribe_applied_type'; +import { UnsubscribeApplied as __UnsubscribeApplied } from './unsubscribe_applied_type'; +import { SubscriptionError as __SubscriptionError } from './subscription_error_type'; // A namespace for generated variants and helper functions. export namespace ServerMessage { @@ -70,6 +59,18 @@ export namespace ServerMessage { tag: 'OneOffQueryResponse'; value: __OneOffQueryResponse; }; + export type SubscribeApplied = { + tag: 'SubscribeApplied'; + value: __SubscribeApplied; + }; + export type UnsubscribeApplied = { + tag: 'UnsubscribeApplied'; + value: __UnsubscribeApplied; + }; + export type SubscriptionError = { + tag: 'SubscriptionError'; + value: __SubscriptionError; + }; // Helper functions for constructing each variant of the tagged union. // ``` @@ -93,6 +94,15 @@ export namespace ServerMessage { export const OneOffQueryResponse = ( value: __OneOffQueryResponse ): ServerMessage => ({ tag: 'OneOffQueryResponse', value }); + export const SubscribeApplied = ( + value: __SubscribeApplied + ): ServerMessage => ({ tag: 'SubscribeApplied', value }); + export const UnsubscribeApplied = ( + value: __UnsubscribeApplied + ): ServerMessage => ({ tag: 'UnsubscribeApplied', value }); + export const SubscriptionError = ( + value: __SubscriptionError + ): ServerMessage => ({ tag: 'SubscriptionError', value }); export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ @@ -116,6 +126,18 @@ export namespace ServerMessage { 'OneOffQueryResponse', __OneOffQueryResponse.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'SubscribeApplied', + __SubscribeApplied.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'UnsubscribeApplied', + __UnsubscribeApplied.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'SubscriptionError', + __SubscriptionError.getTypeScriptAlgebraicType() + ), ]); } @@ -134,6 +156,9 @@ export type ServerMessage = | ServerMessage.TransactionUpdate | ServerMessage.TransactionUpdateLight | ServerMessage.IdentityToken - | ServerMessage.OneOffQueryResponse; + | ServerMessage.OneOffQueryResponse + | ServerMessage.SubscribeApplied + | ServerMessage.UnsubscribeApplied + | ServerMessage.SubscriptionError; export default ServerMessage; diff --git a/packages/sdk/src/client_api/subscribe_applied_type.ts b/packages/sdk/src/client_api/subscribe_applied_type.ts new file mode 100644 index 0000000..a09d042 --- /dev/null +++ b/packages/sdk/src/client_api/subscribe_applied_type.ts @@ -0,0 +1,74 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +import { QueryId as __QueryId } from './query_id_type'; +import { SubscribeRows as __SubscribeRows } from './subscribe_rows_type'; + +export type SubscribeApplied = { + requestId: number; + totalHostExecutionDurationMicros: bigint; + queryId: __QueryId; + rows: __SubscribeRows; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace SubscribeApplied { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('requestId', AlgebraicType.createU32Type()), + new ProductTypeElement( + 'totalHostExecutionDurationMicros', + AlgebraicType.createU64Type() + ), + new ProductTypeElement('queryId', __QueryId.getTypeScriptAlgebraicType()), + new ProductTypeElement( + 'rows', + __SubscribeRows.getTypeScriptAlgebraicType() + ), + ]); + } + + export function serialize( + writer: BinaryWriter, + value: SubscribeApplied + ): void { + SubscribeApplied.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): SubscribeApplied { + return SubscribeApplied.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/subscribe_rows_type.ts b/packages/sdk/src/client_api/subscribe_rows_type.ts new file mode 100644 index 0000000..7c65448 --- /dev/null +++ b/packages/sdk/src/client_api/subscribe_rows_type.ts @@ -0,0 +1,65 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +import { TableUpdate as __TableUpdate } from './table_update_type'; + +export type SubscribeRows = { + tableId: number; + tableName: string; + tableRows: __TableUpdate; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace SubscribeRows { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('tableId', AlgebraicType.createU32Type()), + new ProductTypeElement('tableName', AlgebraicType.createStringType()), + new ProductTypeElement( + 'tableRows', + __TableUpdate.getTypeScriptAlgebraicType() + ), + ]); + } + + export function serialize(writer: BinaryWriter, value: SubscribeRows): void { + SubscribeRows.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): SubscribeRows { + return SubscribeRows.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/subscribe_single_type.ts b/packages/sdk/src/client_api/subscribe_single_type.ts new file mode 100644 index 0000000..f0115c9 --- /dev/null +++ b/packages/sdk/src/client_api/subscribe_single_type.ts @@ -0,0 +1,65 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +import { QueryId as __QueryId } from './query_id_type'; + +export type SubscribeSingle = { + query: string; + requestId: number; + queryId: __QueryId; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace SubscribeSingle { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('query', AlgebraicType.createStringType()), + new ProductTypeElement('requestId', AlgebraicType.createU32Type()), + new ProductTypeElement('queryId', __QueryId.getTypeScriptAlgebraicType()), + ]); + } + + export function serialize( + writer: BinaryWriter, + value: SubscribeSingle + ): void { + SubscribeSingle.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): SubscribeSingle { + return SubscribeSingle.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/subscribe_type.ts b/packages/sdk/src/client_api/subscribe_type.ts index 7637646..50db1fa 100644 --- a/packages/sdk/src/client_api/subscribe_type.ts +++ b/packages/sdk/src/client_api/subscribe_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type Subscribe = { queryStrings: string[]; requestId: number; diff --git a/packages/sdk/src/client_api/subscription_error_type.ts b/packages/sdk/src/client_api/subscription_error_type.ts new file mode 100644 index 0000000..d9c4f06 --- /dev/null +++ b/packages/sdk/src/client_api/subscription_error_type.ts @@ -0,0 +1,79 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +export type SubscriptionError = { + totalHostExecutionDurationMicros: bigint; + requestId: number | undefined; + queryId: number | undefined; + tableId: number | undefined; + error: string; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace SubscriptionError { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement( + 'totalHostExecutionDurationMicros', + AlgebraicType.createU64Type() + ), + new ProductTypeElement( + 'requestId', + AlgebraicType.createOptionType(AlgebraicType.createU32Type()) + ), + new ProductTypeElement( + 'queryId', + AlgebraicType.createOptionType(AlgebraicType.createU32Type()) + ), + new ProductTypeElement( + 'tableId', + AlgebraicType.createOptionType(AlgebraicType.createU32Type()) + ), + new ProductTypeElement('error', AlgebraicType.createStringType()), + ]); + } + + export function serialize( + writer: BinaryWriter, + value: SubscriptionError + ): void { + SubscriptionError.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): SubscriptionError { + return SubscriptionError.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/table_update_type.ts b/packages/sdk/src/client_api/table_update_type.ts index 5aacae3..ae5bcd7 100644 --- a/packages/sdk/src/client_api/table_update_type.ts +++ b/packages/sdk/src/client_api/table_update_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { CompressableQueryUpdate as __CompressableQueryUpdate } from './compressable_query_update_type'; export type TableUpdate = { diff --git a/packages/sdk/src/client_api/timestamp_type.ts b/packages/sdk/src/client_api/timestamp_type.ts index e9c5e74..9f37731 100644 --- a/packages/sdk/src/client_api/timestamp_type.ts +++ b/packages/sdk/src/client_api/timestamp_type.ts @@ -1,42 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; +} from '../index'; export type Timestamp = { microseconds: bigint; }; diff --git a/packages/sdk/src/client_api/transaction_update_light_type.ts b/packages/sdk/src/client_api/transaction_update_light_type.ts index d8c4e2a..30b2ee6 100644 --- a/packages/sdk/src/client_api/transaction_update_light_type.ts +++ b/packages/sdk/src/client_api/transaction_update_light_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; export type TransactionUpdateLight = { diff --git a/packages/sdk/src/client_api/transaction_update_type.ts b/packages/sdk/src/client_api/transaction_update_type.ts index 3a4808b..9d22836 100644 --- a/packages/sdk/src/client_api/transaction_update_type.ts +++ b/packages/sdk/src/client_api/transaction_update_type.ts @@ -1,49 +1,36 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { UpdateStatus as __UpdateStatus } from './update_status_type'; -// @ts-ignore import { Timestamp as __Timestamp } from './timestamp_type'; -// @ts-ignore import { ReducerCallInfo as __ReducerCallInfo } from './reducer_call_info_type'; -// @ts-ignore import { EnergyQuanta as __EnergyQuanta } from './energy_quanta_type'; export type TransactionUpdate = { diff --git a/packages/sdk/src/client_api/unsubscribe_applied_type.ts b/packages/sdk/src/client_api/unsubscribe_applied_type.ts new file mode 100644 index 0000000..0b2aad1 --- /dev/null +++ b/packages/sdk/src/client_api/unsubscribe_applied_type.ts @@ -0,0 +1,74 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +import { QueryId as __QueryId } from './query_id_type'; +import { SubscribeRows as __SubscribeRows } from './subscribe_rows_type'; + +export type UnsubscribeApplied = { + requestId: number; + totalHostExecutionDurationMicros: bigint; + queryId: __QueryId; + rows: __SubscribeRows; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace UnsubscribeApplied { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('requestId', AlgebraicType.createU32Type()), + new ProductTypeElement( + 'totalHostExecutionDurationMicros', + AlgebraicType.createU64Type() + ), + new ProductTypeElement('queryId', __QueryId.getTypeScriptAlgebraicType()), + new ProductTypeElement( + 'rows', + __SubscribeRows.getTypeScriptAlgebraicType() + ), + ]); + } + + export function serialize( + writer: BinaryWriter, + value: UnsubscribeApplied + ): void { + UnsubscribeApplied.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): UnsubscribeApplied { + return UnsubscribeApplied.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/unsubscribe_type.ts b/packages/sdk/src/client_api/unsubscribe_type.ts new file mode 100644 index 0000000..1b9f9f4 --- /dev/null +++ b/packages/sdk/src/client_api/unsubscribe_type.ts @@ -0,0 +1,60 @@ +// 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 { + Address, + AlgebraicType, + AlgebraicValue, + BinaryReader, + BinaryWriter, + CallReducerFlags, + DBConnectionBuilder, + DBConnectionImpl, + DBContext, + ErrorContextInterface, + Event, + EventContextInterface, + Identity, + ProductType, + ProductTypeElement, + ReducerEventContextInterface, + SubscriptionBuilderImpl, + SubscriptionEventContextInterface, + SumType, + SumTypeVariant, + TableCache, + deepEqual, +} from '../index'; +import { QueryId as __QueryId } from './query_id_type'; + +export type Unsubscribe = { + requestId: number; + queryId: __QueryId; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace Unsubscribe { + /** + * A function which returns this type represented as an AlgebraicType. + * This function is derived from the AlgebraicType used to generate this type. + */ + export function getTypeScriptAlgebraicType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement('requestId', AlgebraicType.createU32Type()), + new ProductTypeElement('queryId', __QueryId.getTypeScriptAlgebraicType()), + ]); + } + + export function serialize(writer: BinaryWriter, value: Unsubscribe): void { + Unsubscribe.getTypeScriptAlgebraicType().serialize(writer, value); + } + + export function deserialize(reader: BinaryReader): Unsubscribe { + return Unsubscribe.getTypeScriptAlgebraicType().deserialize(reader); + } +} diff --git a/packages/sdk/src/client_api/update_status_type.ts b/packages/sdk/src/client_api/update_status_type.ts index cc8fc90..7da2621 100644 --- a/packages/sdk/src/client_api/update_status_type.ts +++ b/packages/sdk/src/client_api/update_status_type.ts @@ -1,43 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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, 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 '..'; -// @ts-ignore +} from '../index'; import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; // A namespace for generated variants and helper functions. diff --git a/packages/sdk/src/db_connection_impl.ts b/packages/sdk/src/db_connection_impl.ts index 8998ef3..2339393 100644 --- a/packages/sdk/src/db_connection_impl.ts +++ b/packages/sdk/src/db_connection_impl.ts @@ -18,9 +18,14 @@ import BinaryWriter from './binary_writer.ts'; import * as ws from './client_api/index.ts'; import { ClientCache } from './client_cache.ts'; import { DBConnectionBuilder } from './db_connection_builder.ts'; -import { SubscriptionBuilder, type DBContext } from './db_context.ts'; +import { type DBContext } from './db_context.ts'; import type { Event } from './event.ts'; -import { type EventContextInterface } from './event_context.ts'; +import { + type ErrorContextInterface, + type EventContextInterface, + type ReducerEventContextInterface, + type SubscriptionEventContextInterface, +} from './event_context.ts'; import { EventEmitter } from './event_emitter.ts'; import { decompress } from './decompress.ts'; import type { Identity } from './identity.ts'; @@ -31,6 +36,7 @@ import { TableCache, type Operation, type TableUpdate } from './table_cache.ts'; import { deepEqual, toPascalCase } from './utils.ts'; import { WebsocketDecompressAdapter } from './websocket_decompress_adapter.ts'; import type { WebsocketTestAdapter } from './websocket_test_adapter.ts'; +import { SubscriptionBuilderImpl } from './subscription_builder_impl.ts'; export { AlgebraicType, @@ -42,7 +48,7 @@ export { ProductType, ProductTypeElement, ProductValue, - SubscriptionBuilder, + SubscriptionBuilderImpl, SumType, SumTypeVariant, TableCache, @@ -51,12 +57,28 @@ export { type ValueAdapter, }; -export type { DBContext, EventContextInterface, ReducerEvent }; +export type { + DBContext, + EventContextInterface, + ReducerEventContextInterface, + SubscriptionEventContextInterface, + ErrorContextInterface, + ReducerEvent, +}; export type ConnectionEvent = 'connect' | 'disconnect' | 'connectError'; export type CallReducerFlags = 'FullUpdate' | 'NoSuccessNotify'; +type ReducerEventCallback = ( + ctx: ReducerEventContextInterface, + ...args: ReducerArgs +) => void; +type SubscriptionEventCallback = ( + ctx: SubscriptionEventContextInterface +) => void; +type ErrorCallback = (ctx: ErrorContextInterface) => void; + function callReducerFlagsToNumber(flags: CallReducerFlags): number { switch (flags) { case 'FullUpdate': @@ -88,8 +110,8 @@ export class DBConnectionImpl< clientCache: ClientCache; remoteModule: SpacetimeModule; #emitter: EventEmitter; - #reducerEmitter: EventEmitter = new EventEmitter(); - #onApplied?: (ctx: EventContextInterface) => void; + #reducerEmitter: EventEmitter = new EventEmitter(); + #onApplied?: SubscriptionEventCallback; wsPromise!: Promise; ws?: WebsocketDecompressAdapter | WebsocketTestAdapter; @@ -113,10 +135,6 @@ export class DBConnectionImpl< ); } - subscriptionBuilder = (): SubscriptionBuilder => { - return new SubscriptionBuilder(this); - }; - /** * Close the current connection. * @@ -311,8 +329,8 @@ export class DBConnectionImpl< // This is marked private but not # because we need to use it from the builder private subscribe( queryOrQueries: string | string[], - onApplied?: (ctx: EventContextInterface) => void, - _onError?: (ctx: EventContextInterface) => void + onApplied?: SubscriptionEventCallback, + _onError?: ErrorCallback ): void { this.#onApplied = onApplied; const queries = @@ -385,18 +403,22 @@ export class DBConnectionImpl< this.#messageQueue = this.#messageQueue.then(() => this.processMessage(wsMessage.data, message => { if (message.tag === 'InitialSubscription') { - let event: Event = { tag: 'SubscribeApplied' }; + let event: Event = { tag: 'SubscribeApplied' }; + const eventContext = this.remoteModule.eventContextConstructor( this, event ); + // Remove the event from the subscription event context + // It is not a field in the type narrowed SubscriptionEventContext + const { event: _, ...subscriptionEventContext } = eventContext; this.#applyTableUpdates(message.tableUpdates, eventContext); if (this.#emitter) { - this.#onApplied?.(eventContext); + this.#onApplied?.(subscriptionEventContext); } } else if (message.tag === 'TransactionUpdateLight') { - const event: Event = { tag: 'UnknownTransaction' }; + const event: Event = { tag: 'UnknownTransaction' }; const eventContext = this.remoteModule.eventContextConstructor( this, event @@ -406,7 +428,9 @@ export class DBConnectionImpl< const reducerName = message.originalReducerName; const reducerTypeInfo = this.remoteModule.reducers[reducerName]!; - if (reducerName == '') { + // TODO: Can `reducerName` be ''? + // See: https://github.com/clockworklabs/SpacetimeDB/blob/a2a1b5d9b2e0ebaaf753d074db056d319952d442/crates/core/src/client/message_handlers.rs#L155 + if (reducerName === '') { let errorMessage = message.message; console.error( `Received an error from the database: ${errorMessage}` @@ -425,11 +449,18 @@ export class DBConnectionImpl< args: reducerArgs, }, }; - const event: Event = { tag: 'Reducer', value: reducerEvent }; + const event: Event = { + tag: 'Reducer', + value: reducerEvent, + }; const eventContext = this.remoteModule.eventContextConstructor( this, event ); + const reducerEventContext = { + ...eventContext, + event: reducerEvent, + }; this.#applyTableUpdates(message.tableUpdates, eventContext); @@ -439,7 +470,11 @@ export class DBConnectionImpl< argsArray.push(reducerArgs[element.name]); } ); - this.#reducerEmitter.emit(reducerName, eventContext, ...argsArray); + this.#reducerEmitter.emit( + reducerName, + reducerEventContext, + ...argsArray + ); } } else if (message.tag === 'IdentityToken') { this.identity = message.identity; @@ -503,17 +538,11 @@ export class DBConnectionImpl< this.#emitter.off('connectError', callback); } - onReducer( - reducerName: string, - callback: (ctx: any, ...args: ReducerArgs) => void - ): void { + onReducer(reducerName: string, callback: ReducerEventCallback): void { this.#reducerEmitter.on(reducerName, callback); } - offReducer( - reducerName: string, - callback: (ctx: any, ...args: ReducerArgs) => void - ): void { + offReducer(reducerName: string, callback: ReducerEventCallback): void { this.#reducerEmitter.off(reducerName, callback); } } diff --git a/packages/sdk/src/db_context.ts b/packages/sdk/src/db_context.ts index 62ca86d..e2410d0 100644 --- a/packages/sdk/src/db_context.ts +++ b/packages/sdk/src/db_context.ts @@ -1,6 +1,3 @@ -import type { DBConnectionImpl } from './db_connection_impl.ts'; -import type { EventContextInterface } from './event_context.ts'; - type Result = | { tag: 'Ok'; @@ -53,97 +50,6 @@ interface SubscriptionHandle { isActive(): boolean; } -export class SubscriptionBuilder { - #onApplied?: (ctx: EventContextInterface) => void = undefined; - #onError?: (ctx: EventContextInterface) => void = undefined; - - constructor(private db: DBConnectionImpl) {} - - /** - * Registers `callback` to run when this query is successfully added to our subscribed set, - * I.e. when its `SubscriptionApplied` message is received. - * - * The database state exposed via the `&EventContext` argument - * includes all the rows added to the client cache as a result of the new subscription. - * - * The event in the `&EventContext` argument is `Event::SubscribeApplied`. - * - * Multiple `on_applied` callbacks for the same query may coexist. - * No mechanism for un-registering `on_applied` callbacks is exposed. - * - * @param cb - Callback to run when the subscription is applied. - * @returns The current `SubscriptionBuilder` instance. - */ - onApplied(cb: (ctx: EventContextInterface) => void): SubscriptionBuilder { - this.#onApplied = cb; - return this; - } - - /** - * Registers `callback` to run when this query either: - * - Fails to be added to our subscribed set. - * - Is unexpectedly removed from our subscribed set. - * - * If the subscription had previously started and has been unexpectedly removed, - * the database state exposed via the `&EventContext` argument contains no rows - * from any subscriptions removed within the same error event. - * As proposed, it must therefore contain no rows. - * - * The event in the `&EventContext` argument is `Event::SubscribeError`, - * containing a dynamic error object with a human-readable description of the error - * for diagnostic purposes. - * - * Multiple `on_error` callbacks for the same query may coexist. - * No mechanism for un-registering `on_error` callbacks is exposed. - * - * @param cb - Callback to run when there is an error in subscription. - * @returns The current `SubscriptionBuilder` instance. - */ - onError(cb: (ctx: EventContextInterface) => void): SubscriptionBuilder { - this.#onError = cb; - return this; - } - - /** - * Issues a new `Subscribe` message, - * adding `query` to the client's set of subscribed queries. - * - * `query` should be a single SQL `SELECT` statement. - * - * Installs the above callbacks into the new `SubscriptionHandle`, - * before issuing the `Subscribe` message, to avoid race conditions. - * - * Consumes the `SubscriptionBuilder`, - * because the callbacks are not necessarily `Clone`. - * - * @param query_sql - The SQL query to subscribe to. - */ - subscribe(query_sql: string[]): void { - this.db['subscribe'](query_sql, this.#onApplied, this.#onError); - } - - /** - * Subscribes to all rows from all tables. - * - * This method is intended as a convenience - * for applications where client-side memory use and network bandwidth are not concerns. - * Applications where these resources are a constraint - * should register more precise queries via `subscribe` - * in order to replicate only the subset of data which the client needs to function. - * - * This method should not be combined with `subscribe` on the same `DbConnection`. - * A connection may either `subscribe` to particular queries, - * or `subscribeToAllTables`, but not both. - * Attempting to call `subscribe` - * on a `DbConnection` that has previously used `subscribeToAllTables`, - * or vice versa, may misbehave in any number of ways, - * including dropping subscriptions, corrupting the client cache, or throwing errors. - */ - subscribeToAllTables(): void { - this.subscribe(['SELECT * FROM *']); - } -} - /** * Interface representing a database context. * @@ -165,11 +71,4 @@ export interface DBContext< * Disconnects from the database. */ disconnect(): void; - - /** - * Creates a new `SubscriptionBuilder` for building subscription queries. - * - * @returns A new `SubscriptionBuilder` instance. - */ - subscriptionBuilder(): SubscriptionBuilder; } diff --git a/packages/sdk/src/event.ts b/packages/sdk/src/event.ts index 95627fb..8be677e 100644 --- a/packages/sdk/src/event.ts +++ b/packages/sdk/src/event.ts @@ -1,8 +1,6 @@ -import type { ReducerEvent } from './reducer_event'; +import type { ReducerEvent, ReducerInfoType } from './reducer_event'; -export type Event< - Reducer extends { name: string; args?: any } = { name: string; args?: any }, -> = +export type Event = | { tag: 'Reducer'; value: ReducerEvent } | { tag: 'SubscribeApplied' } | { tag: 'UnsubscribeApplied' } diff --git a/packages/sdk/src/event_context.ts b/packages/sdk/src/event_context.ts index 5173d01..2cf39ce 100644 --- a/packages/sdk/src/event_context.ts +++ b/packages/sdk/src/event_context.ts @@ -1,12 +1,40 @@ import type { DBContext } from './db_context'; import type { Event } from './event.ts'; +import type { ReducerEvent, ReducerInfoType } from './reducer_event.ts'; export interface EventContextInterface< DBView = any, Reducers = any, SetReducerFlags = any, - Reducer extends { name: string; args?: any } = { name: string; args?: any }, + Reducer extends ReducerInfoType = never, > extends DBContext { /** Enum with variants for all possible events. */ event: Event; } + +export interface ReducerEventContextInterface< + DBView = any, + Reducers = any, + SetReducerFlags = any, + Reducer extends ReducerInfoType = never, +> extends DBContext { + /** Enum with variants for all possible events. */ + event: ReducerEvent; +} + +export interface SubscriptionEventContextInterface< + DBView = any, + Reducers = any, + SetReducerFlags = any, +> extends DBContext { + /** No event is provided **/ +} + +export interface ErrorContextInterface< + DBView = any, + Reducers = any, + SetReducerFlags = any, +> extends DBContext { + /** Enum with variants for all possible events. */ + event: Error; +} diff --git a/packages/sdk/src/event_emitter.ts b/packages/sdk/src/event_emitter.ts index e515123..3bf048c 100644 --- a/packages/sdk/src/event_emitter.ts +++ b/packages/sdk/src/event_emitter.ts @@ -1,7 +1,7 @@ -export class EventEmitter { - #events: Map> = new Map(); +export class EventEmitter { + #events: Map> = new Map(); - on(event: string, callback: Function): void { + on(event: string, callback: Callback): void { let callbacks = this.#events.get(event); if (!callbacks) { callbacks = new Set(); @@ -10,7 +10,7 @@ export class EventEmitter { callbacks.add(callback); } - off(event: string, callback: Function): void { + off(event: string, callback: Callback): void { let callbacks = this.#events.get(event); if (!callbacks) { return; diff --git a/packages/sdk/src/reducer_event.ts b/packages/sdk/src/reducer_event.ts index d3d674c..7bd419a 100644 --- a/packages/sdk/src/reducer_event.ts +++ b/packages/sdk/src/reducer_event.ts @@ -1,8 +1,10 @@ import { Address } from './address.ts'; -import type { Timestamp, UpdateStatus } from './client_api/index.ts'; +import type { Reducer, Timestamp, UpdateStatus } from './client_api/index.ts'; import { Identity } from './identity.ts'; -export type ReducerEvent = { +export type ReducerInfoType = { name: string; args?: any } | never; + +export type ReducerEvent = { /** * The time when the reducer started running. * diff --git a/packages/sdk/src/spacetime_module.ts b/packages/sdk/src/spacetime_module.ts index a8952dc..1888295 100644 --- a/packages/sdk/src/spacetime_module.ts +++ b/packages/sdk/src/spacetime_module.ts @@ -1,6 +1,5 @@ import type { AlgebraicType } from './algebraic_type'; import type { DBConnectionImpl } from './db_connection_impl'; -import type { Event } from './event'; export interface TableRuntimeTypeInfo { tableName: string; diff --git a/packages/sdk/src/subscription_builder_impl.ts b/packages/sdk/src/subscription_builder_impl.ts new file mode 100644 index 0000000..3b7171e --- /dev/null +++ b/packages/sdk/src/subscription_builder_impl.ts @@ -0,0 +1,90 @@ +import type { DBConnectionImpl } from './db_connection_impl'; +import type { + ErrorContextInterface, + SubscriptionEventContextInterface, +} from './event_context'; + +export class SubscriptionBuilderImpl< + DBView = any, + Reducers = any, + SetReducerFlags = any, +> { + #onApplied?: ( + ctx: SubscriptionEventContextInterface + ) => void = undefined; + #onError?: ( + ctx: ErrorContextInterface + ) => void = undefined; + constructor( + private db: DBConnectionImpl + ) {} + + /** + * Registers `callback` to run when this query is successfully added to our subscribed set, + * I.e. when its `SubscriptionApplied` message is received. + * + * The database state exposed via the `&EventContext` argument + * includes all the rows added to the client cache as a result of the new subscription. + * + * The event in the `&EventContext` argument is `Event::SubscribeApplied`. + * + * Multiple `on_applied` callbacks for the same query may coexist. + * No mechanism for un-registering `on_applied` callbacks is exposed. + * + * @param cb - Callback to run when the subscription is applied. + * @returns The current `SubscriptionBuilder` instance. + */ + onApplied( + cb: ( + ctx: SubscriptionEventContextInterface + ) => void + ): SubscriptionBuilderImpl { + this.#onApplied = cb; + return this; + } + + /** + * Registers `callback` to run when this query either: + * - Fails to be added to our subscribed set. + * - Is unexpectedly removed from our subscribed set. + * + * If the subscription had previously started and has been unexpectedly removed, + * the database state exposed via the `&EventContext` argument contains no rows + * from any subscriptions removed within the same error event. + * As proposed, it must therefore contain no rows. + * + * The event in the `&EventContext` argument is `Event::SubscribeError`, + * containing a dynamic error object with a human-readable description of the error + * for diagnostic purposes. + * + * Multiple `on_error` callbacks for the same query may coexist. + * No mechanism for un-registering `on_error` callbacks is exposed. + * + * @param cb - Callback to run when there is an error in subscription. + * @returns The current `SubscriptionBuilder` instance. + */ + onError( + cb: (ctx: ErrorContextInterface) => void + ): SubscriptionBuilderImpl { + this.#onError = cb; + return this; + } + + /** + * Issues a new `Subscribe` message, + * adding `query` to the client's set of subscribed queries. + * + * `query` should be a single SQL `SELECT` statement. + * + * Installs the above callbacks into the new `SubscriptionHandle`, + * before issuing the `Subscribe` message, to avoid race conditions. + * + * Consumes the `SubscriptionBuilder`, + * because the callbacks are not necessarily `Clone`. + * + * @param query_sql - The SQL query to subscribe to. + */ + subscribe(query_sql: string[]): void { + this.db['subscribe'](query_sql, this.#onApplied, this.#onError); + } +} diff --git a/packages/test-app/src/App.tsx b/packages/test-app/src/App.tsx index e3e5b88..9505555 100644 --- a/packages/test-app/src/App.tsx +++ b/packages/test-app/src/App.tsx @@ -1,7 +1,6 @@ import { DBConnection } from './module_bindings'; import { useEffect, useState } from 'react'; import './App.css'; -import { Identity } from '@clockworklabs/spacetimedb-sdk'; function App() { const [connection] = useState(() => diff --git a/packages/test-app/src/module_bindings/create_player_reducer.ts b/packages/test-app/src/module_bindings/create_player_reducer.ts index 9304afa..7636245 100644 --- a/packages/test-app/src/module_bindings/create_player_reducer.ts +++ b/packages/test-app/src/module_bindings/create_player_reducer.ts @@ -1,46 +1,34 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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'; -// @ts-ignore import { Point as __Point } from './point_type'; export type CreatePlayer = { diff --git a/packages/test-app/src/module_bindings/index.ts b/packages/test-app/src/module_bindings/index.ts index 25ef6f3..6cc09b5 100644 --- a/packages/test-app/src/module_bindings/index.ts +++ b/packages/test-app/src/module_bindings/index.ts @@ -1,42 +1,31 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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'; @@ -79,6 +68,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) => { return { ...(imp as DBConnection), @@ -121,13 +115,13 @@ export class RemoteReducers { } onCreatePlayer( - callback: (ctx: EventContext, name: string, location: Point) => void + callback: (ctx: ReducerEventContext, name: string, location: Point) => void ) { this.connection.onReducer('create_player', callback); } removeOnCreatePlayer( - callback: (ctx: EventContext, name: string, location: Point) => void + callback: (ctx: ReducerEventContext, name: string, location: Point) => void ) { this.connection.offReducer('create_player', callback); } @@ -160,6 +154,12 @@ export class RemoteTables { } } +export class SubscriptionBuilder extends SubscriptionBuilderImpl< + RemoteTables, + RemoteReducers, + SetReducerFlags +> {} + export class DBConnection extends DBConnectionImpl< RemoteTables, RemoteReducers, @@ -171,6 +171,9 @@ export class DBConnection extends DBConnectionImpl< (imp: DBConnectionImpl) => imp as DBConnection ); }; + subscriptionBuilder = (): SubscriptionBuilder => { + return new SubscriptionBuilder(this); + }; } export type EventContext = EventContextInterface< @@ -179,3 +182,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 +>; diff --git a/packages/test-app/src/module_bindings/player_table.ts b/packages/test-app/src/module_bindings/player_table.ts index ecc6260..ebfe85b 100644 --- a/packages/test-app/src/module_bindings/player_table.ts +++ b/packages/test-app/src/module_bindings/player_table.ts @@ -1,49 +1,36 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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 { Player } from './player_type'; -// @ts-ignore import { Point as __Point } from './point_type'; -// @ts-ignore import { EventContext, Reducer, RemoteReducers, RemoteTables } from '.'; /** diff --git a/packages/test-app/src/module_bindings/player_type.ts b/packages/test-app/src/module_bindings/player_type.ts index beda259..6fa5127 100644 --- a/packages/test-app/src/module_bindings/player_type.ts +++ b/packages/test-app/src/module_bindings/player_type.ts @@ -1,45 +1,33 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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'; -// @ts-ignore import { Point as __Point } from './point_type'; export type Player = { diff --git a/packages/test-app/src/module_bindings/point_type.ts b/packages/test-app/src/module_bindings/point_type.ts index 56b82a7..d2454ec 100644 --- a/packages/test-app/src/module_bindings/point_type.ts +++ b/packages/test-app/src/module_bindings/point_type.ts @@ -1,42 +1,31 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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 Point = { diff --git a/packages/test-app/src/module_bindings/user_table.ts b/packages/test-app/src/module_bindings/user_table.ts index e509ac1..0634ed0 100644 --- a/packages/test-app/src/module_bindings/user_table.ts +++ b/packages/test-app/src/module_bindings/user_table.ts @@ -1,46 +1,34 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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 { User } from './user_type'; -// @ts-ignore import { EventContext, Reducer, RemoteReducers, RemoteTables } from '.'; /** diff --git a/packages/test-app/src/module_bindings/user_type.ts b/packages/test-app/src/module_bindings/user_type.ts index 7d9f7ef..2e60bbb 100644 --- a/packages/test-app/src/module_bindings/user_type.ts +++ b/packages/test-app/src/module_bindings/user_type.ts @@ -1,42 +1,31 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. +// 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 User = {