diff --git a/.changeset/long-laws-mix.md b/.changeset/long-laws-mix.md new file mode 100644 index 0000000..803735e --- /dev/null +++ b/.changeset/long-laws-mix.md @@ -0,0 +1,5 @@ +--- +'@clockworklabs/spacetimedb-sdk': minor +--- + +Support light tx updates via builder.with*light_mode(*) and the call flag NoSuccessNotify diff --git a/examples/quickstart/src/module_bindings/index.ts b/examples/quickstart/src/module_bindings/index.ts index c86f1a5..fbdeac0 100644 --- a/examples/quickstart/src/module_bindings/index.ts +++ b/examples/quickstart/src/module_bindings/index.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, @@ -105,8 +107,14 @@ const REMOTE_MODULE = { dbViewConstructor: (imp: DBConnectionImpl) => { return new RemoteTables(imp); }, - reducersConstructor: (imp: DBConnectionImpl) => { - return new RemoteReducers(imp); + reducersConstructor: ( + imp: DBConnectionImpl, + setReducerFlags: SetReducerFlags + ) => { + return new RemoteReducers(imp, setReducerFlags); + }, + setReducerFlagsConstructor: () => { + return new SetReducerFlags(); }, }; @@ -120,10 +128,17 @@ export type Reducer = | { name: 'SetName'; args: SetName }; export class RemoteReducers { - constructor(private connection: DBConnectionImpl) {} + constructor( + private connection: DBConnectionImpl, + private setCallReducerFlags: SetReducerFlags + ) {} identityConnected() { - this.connection.callReducer('__identity_connected__', new Uint8Array(0)); + this.connection.callReducer( + '__identity_connected__', + new Uint8Array(0), + this.setCallReducerFlags.identityConnectedFlags + ); } onIdentityConnected(callback: (ctx: EventContext) => void) { @@ -135,7 +150,11 @@ export class RemoteReducers { } identityDisconnected() { - this.connection.callReducer('__identity_disconnected__', new Uint8Array(0)); + this.connection.callReducer( + '__identity_disconnected__', + new Uint8Array(0), + this.setCallReducerFlags.identityDisconnectedFlags + ); } onIdentityDisconnected(callback: (ctx: EventContext) => void) { @@ -147,7 +166,11 @@ export class RemoteReducers { } init() { - this.connection.callReducer('__init__', new Uint8Array(0)); + this.connection.callReducer( + '__init__', + new Uint8Array(0), + this.setCallReducerFlags.initFlags + ); } onInit(callback: (ctx: EventContext) => void) { @@ -163,7 +186,11 @@ export class RemoteReducers { let __writer = new BinaryWriter(1024); SendMessage.getAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); - this.connection.callReducer('send_message', __argsBuffer); + this.connection.callReducer( + 'send_message', + __argsBuffer, + this.setCallReducerFlags.sendMessageFlags + ); } onSendMessage(callback: (ctx: EventContext, text: string) => void) { @@ -179,7 +206,11 @@ export class RemoteReducers { let __writer = new BinaryWriter(1024); SetName.getAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); - this.connection.callReducer('set_name', __argsBuffer); + this.connection.callReducer( + 'set_name', + __argsBuffer, + this.setCallReducerFlags.setNameFlags + ); } onSetName(callback: (ctx: EventContext, name: string) => void) { @@ -191,6 +222,29 @@ export class RemoteReducers { } } +export class SetReducerFlags { + identityConnectedFlags: CallReducerFlags; + identityConnected(flags: CallReducerFlags) { + this.identityConnectedFlags = flags; + } + identityDisconnectedFlags: CallReducerFlags; + identityDisconnected(flags: CallReducerFlags) { + this.identityDisconnectedFlags = flags; + } + initFlags: CallReducerFlags; + init(flags: CallReducerFlags) { + this.initFlags = flags; + } + sendMessageFlags: CallReducerFlags; + sendMessage(flags: CallReducerFlags) { + this.sendMessageFlags = flags; + } + setNameFlags: CallReducerFlags; + setName(flags: CallReducerFlags) { + this.setNameFlags = flags; + } +} + export class RemoteTables { constructor(private connection: DBConnectionImpl) {} @@ -211,7 +265,8 @@ export class RemoteTables { export class DBConnection extends DBConnectionImpl< RemoteTables, - RemoteReducers + RemoteReducers, + SetReducerFlags > { static builder = (): DBConnectionBuilder => { return new DBConnectionBuilder( @@ -224,5 +279,6 @@ export class DBConnection extends DBConnectionImpl< export type EventContext = EventContextInterface< RemoteTables, RemoteReducers, + SetReducerFlags, Reducer >; diff --git a/packages/sdk/src/client_api/call_reducer_type.ts b/packages/sdk/src/client_api/call_reducer_type.ts index 9e8fa67..887f3eb 100644 --- a/packages/sdk/src/client_api/call_reducer_type.ts +++ b/packages/sdk/src/client_api/call_reducer_type.ts @@ -41,6 +41,7 @@ export type CallReducer = { reducer: string; args: Uint8Array; requestId: number; + flags: number; }; /** @@ -59,6 +60,7 @@ export namespace CallReducer { AlgebraicType.createArrayType(AlgebraicType.createU8Type()) ), new ProductTypeElement('requestId', AlgebraicType.createU32Type()), + new ProductTypeElement('flags', AlgebraicType.createU8Type()), ]); } diff --git a/packages/sdk/src/client_api/index.ts b/packages/sdk/src/client_api/index.ts index 6699e1e..1e16e88 100644 --- a/packages/sdk/src/client_api/index.ts +++ b/packages/sdk/src/client_api/index.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, @@ -81,6 +83,8 @@ import { Timestamp } from './timestamp_type.ts'; export { Timestamp }; import { TransactionUpdate } from './transaction_update_type.ts'; export { TransactionUpdate }; +import { TransactionUpdateLight } from './transaction_update_light_type.ts'; +export { TransactionUpdateLight }; import { UpdateStatus } from './update_status_type.ts'; export { UpdateStatus }; @@ -98,8 +102,14 @@ const REMOTE_MODULE = { dbViewConstructor: (imp: DBConnectionImpl) => { return new RemoteTables(imp); }, - reducersConstructor: (imp: DBConnectionImpl) => { - return new RemoteReducers(imp); + reducersConstructor: ( + imp: DBConnectionImpl, + setReducerFlags: SetReducerFlags + ) => { + return new RemoteReducers(imp, setReducerFlags); + }, + setReducerFlagsConstructor: () => { + return new SetReducerFlags(); }, }; @@ -107,16 +117,22 @@ const REMOTE_MODULE = { export type Reducer = never; export class RemoteReducers { - constructor(private connection: DBConnectionImpl) {} + constructor( + private connection: DBConnectionImpl, + private setCallReducerFlags: SetReducerFlags + ) {} } +export class SetReducerFlags {} + export class RemoteTables { constructor(private connection: DBConnectionImpl) {} } export class DBConnection extends DBConnectionImpl< RemoteTables, - RemoteReducers + RemoteReducers, + SetReducerFlags > { static builder = (): DBConnectionBuilder => { return new DBConnectionBuilder( @@ -129,5 +145,6 @@ export class DBConnection extends DBConnectionImpl< export type EventContext = EventContextInterface< RemoteTables, RemoteReducers, + SetReducerFlags, Reducer >; diff --git a/packages/sdk/src/client_api/server_message_type.ts b/packages/sdk/src/client_api/server_message_type.ts index 0cd48b4..54d83cc 100644 --- a/packages/sdk/src/client_api/server_message_type.ts +++ b/packages/sdk/src/client_api/server_message_type.ts @@ -42,6 +42,8 @@ import { InitialSubscription as __InitialSubscription } from './initial_subscrip // @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'; @@ -59,6 +61,10 @@ export namespace ServerMessage { tag: 'TransactionUpdate'; value: __TransactionUpdate; }; + export type TransactionUpdateLight = { + tag: 'TransactionUpdateLight'; + value: __TransactionUpdateLight; + }; export type IdentityToken = { tag: 'IdentityToken'; value: __IdentityToken }; export type OneOffQueryResponse = { tag: 'OneOffQueryResponse'; @@ -77,6 +83,9 @@ export namespace ServerMessage { export const TransactionUpdate = ( value: __TransactionUpdate ): ServerMessage => ({ tag: 'TransactionUpdate', value }); + export const TransactionUpdateLight = ( + value: __TransactionUpdateLight + ): ServerMessage => ({ tag: 'TransactionUpdateLight', value }); export const IdentityToken = (value: __IdentityToken): ServerMessage => ({ tag: 'IdentityToken', value, @@ -95,6 +104,10 @@ export namespace ServerMessage { 'TransactionUpdate', __TransactionUpdate.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'TransactionUpdateLight', + __TransactionUpdateLight.getTypeScriptAlgebraicType() + ), new SumTypeVariant( 'IdentityToken', __IdentityToken.getTypeScriptAlgebraicType() @@ -119,6 +132,7 @@ export namespace ServerMessage { export type ServerMessage = | ServerMessage.InitialSubscription | ServerMessage.TransactionUpdate + | ServerMessage.TransactionUpdateLight | ServerMessage.IdentityToken | ServerMessage.OneOffQueryResponse; diff --git a/packages/sdk/src/client_api/transaction_update_light_type.ts b/packages/sdk/src/client_api/transaction_update_light_type.ts new file mode 100644 index 0000000..d8c4e2a --- /dev/null +++ b/packages/sdk/src/client_api/transaction_update_light_type.ts @@ -0,0 +1,81 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. + +import { + // @ts-ignore + Address, + // @ts-ignore + AlgebraicType, + // @ts-ignore + AlgebraicValue, + // @ts-ignore + BinaryReader, + // @ts-ignore + BinaryWriter, + // @ts-ignore + DBConnectionBuilder, + // @ts-ignore + DBConnectionImpl, + // @ts-ignore + DBContext, + // @ts-ignore + Event, + // @ts-ignore + EventContextInterface, + // @ts-ignore + Identity, + // @ts-ignore + ProductType, + // @ts-ignore + ProductTypeElement, + // @ts-ignore + SumType, + // @ts-ignore + SumTypeVariant, + // @ts-ignore + TableCache, + // @ts-ignore + deepEqual, +} from '..'; +// @ts-ignore +import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; + +export type TransactionUpdateLight = { + requestId: number; + update: __DatabaseUpdate; +}; + +/** + * A namespace for generated helper functions. + */ +export namespace TransactionUpdateLight { + /** + * 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( + 'update', + __DatabaseUpdate.getTypeScriptAlgebraicType() + ), + ]); + } + + export function serialize( + writer: BinaryWriter, + value: TransactionUpdateLight + ): void { + TransactionUpdateLight.getTypeScriptAlgebraicType().serialize( + writer, + value + ); + } + + export function deserialize(reader: BinaryReader): TransactionUpdateLight { + return TransactionUpdateLight.getTypeScriptAlgebraicType().deserialize( + reader + ); + } +} diff --git a/packages/sdk/src/db_connection_builder.ts b/packages/sdk/src/db_connection_builder.ts index 54e94e8..cfecea3 100644 --- a/packages/sdk/src/db_connection_builder.ts +++ b/packages/sdk/src/db_connection_builder.ts @@ -16,6 +16,7 @@ export class DBConnectionBuilder { #emitter: EventEmitter = new EventEmitter(); #createWSFn: typeof WebsocketDecompressAdapter.createWebSocketFn; #compression: 'gzip' | 'none' = 'gzip'; + #light_mode: boolean = false; /** * Creates a new `SpacetimeDBClient` database client and set the initial parameters. @@ -78,6 +79,11 @@ export class DBConnectionBuilder { return this; } + withLightMode(light_mode: boolean): DBConnectionBuilder { + this.#light_mode = light_mode; + return this; + } + /** * Connect to The SpacetimeDB Websocket For Your Module. By default, this will use a secure websocket connection. The parameters are optional, and if not provided, will use the values provided on construction of the client. * @@ -127,6 +133,7 @@ export class DBConnectionBuilder { wsProtocol: 'v1.bsatn.spacetimedb', authToken: connection.token, compression: this.#compression, + light_mode: this.#light_mode, }) .then(v => { connection.ws = v; diff --git a/packages/sdk/src/db_connection_impl.ts b/packages/sdk/src/db_connection_impl.ts index 8b99d73..8998ef3 100644 --- a/packages/sdk/src/db_connection_impl.ts +++ b/packages/sdk/src/db_connection_impl.ts @@ -55,8 +55,22 @@ export type { DBContext, EventContextInterface, ReducerEvent }; export type ConnectionEvent = 'connect' | 'disconnect' | 'connectError'; -export class DBConnectionImpl - implements DBContext +export type CallReducerFlags = 'FullUpdate' | 'NoSuccessNotify'; + +function callReducerFlagsToNumber(flags: CallReducerFlags): number { + switch (flags) { + case 'FullUpdate': + return 0; + case 'NoSuccessNotify': + return 1; + } +} + +export class DBConnectionImpl< + DBView = any, + Reducers = any, + SetReducerFlags = any, +> implements DBContext { isActive = false; /** @@ -81,6 +95,7 @@ export class DBConnectionImpl ws?: WebsocketDecompressAdapter | WebsocketTestAdapter; db: DBView; reducers: Reducers; + setReducerFlags: SetReducerFlags; clientAddress: Address = Address.random(); @@ -91,7 +106,11 @@ export class DBConnectionImpl this.#emitter = emitter; this.remoteModule = remoteModule; this.db = this.remoteModule.dbViewConstructor(this); - this.reducers = this.remoteModule.reducersConstructor(this); + this.setReducerFlags = this.remoteModule.setReducerFlagsConstructor(); + this.reducers = this.remoteModule.reducersConstructor( + this, + this.setReducerFlags + ); } subscriptionBuilder = (): SubscriptionBuilder => { @@ -195,6 +214,17 @@ export class DBConnectionImpl break; } + case 'TransactionUpdateLight': { + const dbUpdate = message.value.update; + const tableUpdates = await parseDatabaseUpdate(dbUpdate); + const subscriptionUpdate: Message = { + tag: 'TransactionUpdateLight', + tableUpdates, + }; + callback(subscriptionUpdate); + break; + } + case 'TransactionUpdate': { const txUpdate = message.value; const identity = txUpdate.callerIdentity; @@ -311,24 +341,42 @@ export class DBConnectionImpl * @param reducerName The name of the reducer to call * @param argsSerializer The arguments to pass to the reducer */ - callReducer(reducerName: string, argsBuffer: Uint8Array): void { + callReducer( + reducerName: string, + argsBuffer: Uint8Array, + flags: CallReducerFlags + ): void { const message = ws.ClientMessage.CallReducer({ reducer: reducerName, args: argsBuffer, // The TypeScript SDK doesn't currently track `request_id`s, // so always use 0. requestId: 0, + flags: callReducerFlagsToNumber(flags), }); this.#sendMessage(message); } - /** + /**s * Handles WebSocket onOpen event. */ handleOnOpen(): void { this.isActive = true; } + #applyTableUpdates( + tableUpdates: TableUpdate[], + eventContext: EventContextInterface + ): void { + for (let tableUpdate of tableUpdates) { + // Get table information for the table being updated + const tableName = tableUpdate.tableName; + const tableTypeInfo = this.remoteModule.tables[tableName]!; + const table = this.clientCache.getOrCreateTable(tableTypeInfo); + table.applyOperations(tableUpdate.operations, eventContext); + } + } + /** * Handles WebSocket onMessage event. * @param wsMessage MessageEvent object. @@ -342,17 +390,18 @@ export class DBConnectionImpl this, event ); - for (let tableUpdate of message.tableUpdates) { - // Get table information for the table being updated - const tableName = tableUpdate.tableName; - const tableTypeInfo = this.remoteModule.tables[tableName]!; - const table = this.clientCache.getOrCreateTable(tableTypeInfo); - table.applyOperations(tableUpdate.operations, eventContext); - } + this.#applyTableUpdates(message.tableUpdates, eventContext); if (this.#emitter) { this.#onApplied?.(eventContext); } + } else if (message.tag === 'TransactionUpdateLight') { + const event: Event = { tag: 'UnknownTransaction' }; + const eventContext = this.remoteModule.eventContextConstructor( + this, + event + ); + this.#applyTableUpdates(message.tableUpdates, eventContext); } else if (message.tag === 'TransactionUpdate') { const reducerName = message.originalReducerName; const reducerTypeInfo = this.remoteModule.reducers[reducerName]!; @@ -382,13 +431,7 @@ export class DBConnectionImpl event ); - for (let tableUpdate of message.tableUpdates) { - // Get table information for the table being updated - const tableName = tableUpdate.tableName; - const tableTypeInfo = this.remoteModule.tables[tableName]!; - const table = this.clientCache.getOrCreateTable(tableTypeInfo); - table.applyOperations(tableUpdate.operations, eventContext); - } + this.#applyTableUpdates(message.tableUpdates, eventContext); const argsArray: any[] = []; reducerTypeInfo.argsType.product.elements.forEach( diff --git a/packages/sdk/src/db_context.ts b/packages/sdk/src/db_context.ts index b28836c..21059e5 100644 --- a/packages/sdk/src/db_context.ts +++ b/packages/sdk/src/db_context.ts @@ -128,10 +128,16 @@ export class SubscriptionBuilder { * * @template DBView - Type representing the database view. * @template Reducers - Type representing the reducers. + * @template SetReducerFlags - Type representing the reducer flags collection. */ -export interface DBContext { +export interface DBContext< + DBView = any, + Reducers = any, + SetReducerFlags = any, +> { db: DBView; reducers: Reducers; + setReducerFlags: SetReducerFlags; isActive: boolean; /** diff --git a/packages/sdk/src/event_context.ts b/packages/sdk/src/event_context.ts index 3a20c20..5173d01 100644 --- a/packages/sdk/src/event_context.ts +++ b/packages/sdk/src/event_context.ts @@ -4,8 +4,9 @@ import type { Event } from './event.ts'; export interface EventContextInterface< DBView = any, Reducers = any, + SetReducerFlags = any, Reducer extends { name: string; args?: any } = { name: string; args?: any }, -> extends DBContext { +> extends DBContext { /** Enum with variants for all possible events. */ event: Event; } diff --git a/packages/sdk/src/message_types.ts b/packages/sdk/src/message_types.ts index 027e631..13f5fb2 100644 --- a/packages/sdk/src/message_types.ts +++ b/packages/sdk/src/message_types.ts @@ -22,6 +22,11 @@ export type TransactionUpdateMessage = { energyConsumed: bigint; }; +export type TransactionUpdateLightMessage = { + tag: 'TransactionUpdateLight'; + tableUpdates: TableUpdate[]; +}; + export type IdentityTokenMessage = { tag: 'IdentityToken'; identity: Identity; @@ -32,4 +37,5 @@ export type IdentityTokenMessage = { export type Message = | InitialSubscriptionMessage | TransactionUpdateMessage + | TransactionUpdateLightMessage | IdentityTokenMessage; diff --git a/packages/sdk/src/spacetime_module.ts b/packages/sdk/src/spacetime_module.ts index 3eb3244..a8952dc 100644 --- a/packages/sdk/src/spacetime_module.ts +++ b/packages/sdk/src/spacetime_module.ts @@ -18,5 +18,9 @@ export default interface SpacetimeModule { reducers: { [name: string]: ReducerRuntimeTypeInfo }; eventContextConstructor: (imp: DBConnectionImpl, event: any) => any; dbViewConstructor: (connection: DBConnectionImpl) => any; - reducersConstructor: (connection: DBConnectionImpl) => any; + reducersConstructor: ( + connection: DBConnectionImpl, + setReducerFlags: any + ) => any; + setReducerFlagsConstructor: () => any; } diff --git a/packages/sdk/src/websocket_decompress_adapter.ts b/packages/sdk/src/websocket_decompress_adapter.ts index 74e1136..d5ab7b0 100644 --- a/packages/sdk/src/websocket_decompress_adapter.ts +++ b/packages/sdk/src/websocket_decompress_adapter.ts @@ -66,11 +66,13 @@ export class WebsocketDecompressAdapter { wsProtocol, authToken, compression, + light_mode, }: { url: URL; wsProtocol: string; authToken?: string; compression: 'gzip' | 'none'; + light_mode: boolean; }): Promise { const headers = new Headers(); if (authToken) { @@ -100,6 +102,9 @@ export class WebsocketDecompressAdapter { 'compression', compression === 'gzip' ? 'Gzip' : 'None' ); + if (light_mode) { + url.searchParams.set('light', 'true'); + } } const ws = new WS(url, wsProtocol); diff --git a/packages/test-app/src/App.tsx b/packages/test-app/src/App.tsx index 2fa9a35..9efb733 100644 --- a/packages/test-app/src/App.tsx +++ b/packages/test-app/src/App.tsx @@ -8,6 +8,7 @@ function App() { DBConnection.builder() .withUri('ws://localhost:3000') .withModuleName('game') + .withLightMode(true) .onDisconnect(() => { console.log('disconnected'); }) @@ -24,16 +25,16 @@ function App() { }) .withCredentials([ Identity.fromString( - 'c200f95df78dfd9cf328791c9fa8dcd60525d7fe361e29cf13454a6c71d91ef1' + 'c200b22f7f282b8e44b908a9b020eabb2a7e554dd225461346603ab79255cffa' ), - 'eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwMUpCQkNIV0pWMUpHNVg4Uk42S1E5N05GUCIsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTE3MyIsImlhdCI6MTczMDQ2NDgxNywiZXhwIjoxNzkzNTM2ODE3fQ.aQjAg_aIa5UTr3CFTJY06_TtNLsCya_JXA3zfPlgeUm4DNXlFiTpRqnDtAtSRrArAb3WNk5LRX3XVuu23ulZzUZfq9tnHpG3ogd8-8ZmjtHB7mIAbaHUsKQs5cKRPrjvMvg6-hUdLnbLqBuMz4l2A1kl9d-XyYExXcZSl3GvvwkfoxxDAZkB7GVX557EofKCT-w8NCa3HE-1d9PEeQneVRwKh1pEKFtJcXGVAdppnp5fDTtjUKXk4uTdvWRK_psZRitwSDfE2Ikuna95c1_dtxG1MTfGQF6QyI5aHpZYnWYVtwikPZ87XiRVE41hNmQmuv9fbeG6UHNsWM7MeBA4yg', + 'eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwMUpCQTBYRzRESFpIWUdQQk5GRFk5RDQ2SiIsImlzcyI6Imh0dHBzOi8vYXV0aC5zdGFnaW5nLnNwYWNldGltZWRiLmNvbSIsImlhdCI6MTczMDgwODUwNSwiZXhwIjoxNzkzODgwNTA1fQ.kGM4HGX0c0twL8NJoSQowzSZa8dc2Ogc-fsvaDK7otUrcdGFsZ3KsNON2eNkFh73FER0hl55_eJStr2tgoPwfTyl_v_TqkY45iUOUlLmHfB-X42cMzpE7PXbR_PKYcp-P-Wa4jGtVl4oF7CvdGKxlhIYEk3e0ElQlA9ThnZN4IEciYV0vwAXGqbaO9SOG8jbrmlmfN7oKgl02EgpodEAHTrnB2mD1qf1YyOw7_9n_EkxJxWLkJf9-nFCVRrbfSLqSJBeE6OKNAu2VLLYrSFE7GkVXNCFVugoCDM2oVJogX75AgzWimrp75QRmLsXbvB-YvvRkQ8Gfb2RZnqCj9kiYg', ]) .build() ); useEffect(() => { - connection.db.player.onInsert((ctx, player) => { - console.log(ctx, player); + connection.db.player.onInsert(player => { + console.log(player); }); setTimeout(() => { 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 17206c0..9304afa 100644 --- a/packages/test-app/src/module_bindings/create_player_reducer.ts +++ b/packages/test-app/src/module_bindings/create_player_reducer.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, diff --git a/packages/test-app/src/module_bindings/index.ts b/packages/test-app/src/module_bindings/index.ts index 9b04fa5..25ef6f3 100644 --- a/packages/test-app/src/module_bindings/index.ts +++ b/packages/test-app/src/module_bindings/index.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, @@ -86,8 +88,14 @@ const REMOTE_MODULE = { dbViewConstructor: (imp: DBConnectionImpl) => { return new RemoteTables(imp); }, - reducersConstructor: (imp: DBConnectionImpl) => { - return new RemoteReducers(imp); + reducersConstructor: ( + imp: DBConnectionImpl, + setReducerFlags: SetReducerFlags + ) => { + return new RemoteReducers(imp, setReducerFlags); + }, + setReducerFlagsConstructor: () => { + return new SetReducerFlags(); }, }; @@ -95,14 +103,21 @@ const REMOTE_MODULE = { export type Reducer = never | { name: 'CreatePlayer'; args: CreatePlayer }; export class RemoteReducers { - constructor(private connection: DBConnectionImpl) {} + constructor( + private connection: DBConnectionImpl, + private setCallReducerFlags: SetReducerFlags + ) {} createPlayer(name: string, location: Point) { const __args = { name, location }; let __writer = new BinaryWriter(1024); CreatePlayer.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); - this.connection.callReducer('create_player', __argsBuffer); + this.connection.callReducer( + 'create_player', + __argsBuffer, + this.setCallReducerFlags.createPlayerFlags + ); } onCreatePlayer( @@ -118,6 +133,13 @@ export class RemoteReducers { } } +export class SetReducerFlags { + createPlayerFlags: CallReducerFlags = 'FullUpdate'; + createPlayer(flags: CallReducerFlags) { + this.createPlayerFlags = flags; + } +} + export class RemoteTables { constructor(private connection: DBConnectionImpl) {} @@ -140,7 +162,8 @@ export class RemoteTables { export class DBConnection extends DBConnectionImpl< RemoteTables, - RemoteReducers + RemoteReducers, + SetReducerFlags > { static builder = (): DBConnectionBuilder => { return new DBConnectionBuilder( @@ -153,5 +176,6 @@ export class DBConnection extends DBConnectionImpl< export type EventContext = EventContextInterface< RemoteTables, RemoteReducers, + SetReducerFlags, Reducer >; diff --git a/packages/test-app/src/module_bindings/player_table.ts b/packages/test-app/src/module_bindings/player_table.ts index 679f802..ecc6260 100644 --- a/packages/test-app/src/module_bindings/player_table.ts +++ b/packages/test-app/src/module_bindings/player_table.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, diff --git a/packages/test-app/src/module_bindings/player_type.ts b/packages/test-app/src/module_bindings/player_type.ts index af3cd6c..beda259 100644 --- a/packages/test-app/src/module_bindings/player_type.ts +++ b/packages/test-app/src/module_bindings/player_type.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, diff --git a/packages/test-app/src/module_bindings/point_type.ts b/packages/test-app/src/module_bindings/point_type.ts index 87fe8f9..56b82a7 100644 --- a/packages/test-app/src/module_bindings/point_type.ts +++ b/packages/test-app/src/module_bindings/point_type.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, diff --git a/packages/test-app/src/module_bindings/user_table.ts b/packages/test-app/src/module_bindings/user_table.ts index 64cd12c..e509ac1 100644 --- a/packages/test-app/src/module_bindings/user_table.ts +++ b/packages/test-app/src/module_bindings/user_table.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl, diff --git a/packages/test-app/src/module_bindings/user_type.ts b/packages/test-app/src/module_bindings/user_type.ts index 83f0d53..7d9f7ef 100644 --- a/packages/test-app/src/module_bindings/user_type.ts +++ b/packages/test-app/src/module_bindings/user_type.ts @@ -13,6 +13,8 @@ import { // @ts-ignore BinaryWriter, // @ts-ignore + CallReducerFlags, + // @ts-ignore DBConnectionBuilder, // @ts-ignore DBConnectionImpl,