From 3369cfa3f2904420e33002acdf2d47d5d964fd7b Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Wed, 16 Oct 2024 12:44:06 -0400 Subject: [PATCH 1/9] Add `Timestamp` to the SDK, moving it out of `client_api` Companion to SpacetimeDB#1836 --- DEVELOP.md | 1 + packages/sdk/src/algebraic_type.ts | 8 ++ .../sdk/src/client_api/bsatn_row_list_type.ts | 32 ++++--- .../sdk/src/client_api/call_reducer_type.ts | 33 ++++--- .../sdk/src/client_api/client_message_type.ts | 61 ++++++------- .../compressable_query_update_type.ts | 32 ++++--- .../src/client_api/database_update_type.ts | 32 ++++--- .../sdk/src/client_api/energy_quanta_type.ts | 31 ++++--- .../sdk/src/client_api/identity_token_type.ts | 31 ++++--- packages/sdk/src/client_api/index.ts | 2 - .../client_api/initial_subscription_type.ts | 32 ++++--- .../client_api/one_off_query_response_type.ts | 32 ++++--- .../sdk/src/client_api/one_off_query_type.ts | 31 ++++--- .../sdk/src/client_api/one_off_table_type.ts | 32 ++++--- .../sdk/src/client_api/query_update_type.ts | 32 ++++--- .../src/client_api/reducer_call_info_type.ts | 31 ++++--- .../sdk/src/client_api/row_size_hint_type.ts | 31 ++++--- .../sdk/src/client_api/server_message_type.ts | 89 ++++++------------- packages/sdk/src/client_api/subscribe_type.ts | 31 ++++--- .../sdk/src/client_api/table_update_type.ts | 32 ++++--- packages/sdk/src/client_api/timestamp_type.ts | 56 ------------ .../src/client_api/transaction_update_type.ts | 42 +++++---- .../sdk/src/client_api/update_status_type.ts | 32 ++++--- packages/sdk/src/index.ts | 1 + packages/sdk/src/message_types.ts | 3 +- packages/sdk/src/reducer_event.ts | 5 ++ packages/sdk/src/timestamp.ts | 57 ++++++++++++ packages/sdk/tests/spacetimedb_client.test.ts | 21 +++++ 28 files changed, 517 insertions(+), 336 deletions(-) delete mode 100644 packages/sdk/src/client_api/timestamp_type.ts create mode 100644 packages/sdk/src/timestamp.ts diff --git a/DEVELOP.md b/DEVELOP.md index e8cf62d..7db8ee0 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -6,6 +6,7 @@ Whenever the `client-api-messages` crate changes, you'll have to manually re-gen See that crate's DEVELOP.md for how to do this. The generated files must be manually modified to fix their imports from the rest of the SDK. + Within each generated file: - Change the import from `"@clockworklabs/spacetimedb-sdk"` to `"../index"`. diff --git a/packages/sdk/src/algebraic_type.ts b/packages/sdk/src/algebraic_type.ts index c6fb23c..d82d3d9 100644 --- a/packages/sdk/src/algebraic_type.ts +++ b/packages/sdk/src/algebraic_type.ts @@ -358,6 +358,14 @@ export class AlgebraicType { new SumTypeVariant('Time', AlgebraicType.createU64Type()), ]); } + static createTimestampType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement( + '__timestamp_nanos_since_unix_epoch', + AlgebraicType.createI64Type() + ), + ]); + } isProductType(): boolean { return this.type === Type.ProductType; 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 70527ff..054b37f 100644 --- a/packages/sdk/src/client_api/bsatn_row_list_type.ts +++ b/packages/sdk/src/client_api/bsatn_row_list_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 3bcea7b..bcd96ee 100644 --- a/packages/sdk/src/client_api/call_reducer_type.ts +++ b/packages/sdk/src/client_api/call_reducer_type.ts @@ -1,38 +1,48 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; export type CallReducer = { reducer: string; args: Uint8Array; requestId: number; - flags: number; }; /** @@ -51,7 +61,6 @@ 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/client_message_type.ts b/packages/sdk/src/client_api/client_message_type.ts index 7b99296..c833783 100644 --- a/packages/sdk/src/client_api/client_message_type.ts +++ b/packages/sdk/src/client_api/client_message_type.ts @@ -1,38 +1,50 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 { @@ -42,11 +54,6 @@ 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. // ``` @@ -66,14 +73,6 @@ 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([ @@ -86,14 +85,6 @@ export namespace ClientMessage { 'OneOffQuery', __OneOffQuery.getTypeScriptAlgebraicType() ), - new SumTypeVariant( - 'SubscribeSingle', - __SubscribeSingle.getTypeScriptAlgebraicType() - ), - new SumTypeVariant( - 'Unsubscribe', - __Unsubscribe.getTypeScriptAlgebraicType() - ), ]); } @@ -110,8 +101,6 @@ export namespace ClientMessage { export type ClientMessage = | ClientMessage.CallReducer | ClientMessage.Subscribe - | ClientMessage.OneOffQuery - | ClientMessage.SubscribeSingle - | ClientMessage.Unsubscribe; + | ClientMessage.OneOffQuery; 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 2bcc968..380878a 100644 --- a/packages/sdk/src/client_api/compressable_query_update_type.ts +++ b/packages/sdk/src/client_api/compressable_query_update_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 1dcefd4..c6dfbe4 100644 --- a/packages/sdk/src/client_api/database_update_type.ts +++ b/packages/sdk/src/client_api/database_update_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 5906682..c71a9c8 100644 --- a/packages/sdk/src/client_api/energy_quanta_type.ts +++ b/packages/sdk/src/client_api/energy_quanta_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; 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 fdcb08a..d77e7b5 100644 --- a/packages/sdk/src/client_api/identity_token_type.ts +++ b/packages/sdk/src/client_api/identity_token_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; 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 b8f3a9c..69e3260 100644 --- a/packages/sdk/src/client_api/index.ts +++ b/packages/sdk/src/client_api/index.ts @@ -78,8 +78,6 @@ import { SubscriptionError } from './subscription_error_type.ts'; export { SubscriptionError }; import { TableUpdate } from './table_update_type.ts'; export { TableUpdate }; -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'; diff --git a/packages/sdk/src/client_api/initial_subscription_type.ts b/packages/sdk/src/client_api/initial_subscription_type.ts index 2cfa64c..52bae89 100644 --- a/packages/sdk/src/client_api/initial_subscription_type.ts +++ b/packages/sdk/src/client_api/initial_subscription_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 90138d5..2db2ce2 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,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 4e953ef..5d41a11 100644 --- a/packages/sdk/src/client_api/one_off_query_type.ts +++ b/packages/sdk/src/client_api/one_off_query_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; 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 18089e3..f12c6e3 100644 --- a/packages/sdk/src/client_api/one_off_table_type.ts +++ b/packages/sdk/src/client_api/one_off_table_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore import { BsatnRowList as __BsatnRowList } from './bsatn_row_list_type'; export type OneOffTable = { diff --git a/packages/sdk/src/client_api/query_update_type.ts b/packages/sdk/src/client_api/query_update_type.ts index f308079..42189a6 100644 --- a/packages/sdk/src/client_api/query_update_type.ts +++ b/packages/sdk/src/client_api/query_update_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 2009f6f..8d0bd32 100644 --- a/packages/sdk/src/client_api/reducer_call_info_type.ts +++ b/packages/sdk/src/client_api/reducer_call_info_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; 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 8950393..df36c83 100644 --- a/packages/sdk/src/client_api/row_size_hint_type.ts +++ b/packages/sdk/src/client_api/row_size_hint_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; // 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 128e757..8b207a7 100644 --- a/packages/sdk/src/client_api/server_message_type.ts +++ b/packages/sdk/src/client_api/server_message_type.ts @@ -1,41 +1,52 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore import { InitialSubscription as __InitialSubscription } from './initial_subscription_type'; +// @ts-ignore import { TransactionUpdate as __TransactionUpdate } from './transaction_update_type'; -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 { @@ -50,27 +61,11 @@ 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'; 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. // ``` @@ -84,9 +79,6 @@ 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, @@ -94,15 +86,6 @@ 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([ @@ -114,10 +97,6 @@ export namespace ServerMessage { 'TransactionUpdate', __TransactionUpdate.getTypeScriptAlgebraicType() ), - new SumTypeVariant( - 'TransactionUpdateLight', - __TransactionUpdateLight.getTypeScriptAlgebraicType() - ), new SumTypeVariant( 'IdentityToken', __IdentityToken.getTypeScriptAlgebraicType() @@ -126,18 +105,6 @@ export namespace ServerMessage { 'OneOffQueryResponse', __OneOffQueryResponse.getTypeScriptAlgebraicType() ), - new SumTypeVariant( - 'SubscribeApplied', - __SubscribeApplied.getTypeScriptAlgebraicType() - ), - new SumTypeVariant( - 'UnsubscribeApplied', - __UnsubscribeApplied.getTypeScriptAlgebraicType() - ), - new SumTypeVariant( - 'SubscriptionError', - __SubscriptionError.getTypeScriptAlgebraicType() - ), ]); } @@ -154,11 +121,7 @@ export namespace ServerMessage { export type ServerMessage = | ServerMessage.InitialSubscription | ServerMessage.TransactionUpdate - | ServerMessage.TransactionUpdateLight | ServerMessage.IdentityToken - | ServerMessage.OneOffQueryResponse - | ServerMessage.SubscribeApplied - | ServerMessage.UnsubscribeApplied - | ServerMessage.SubscriptionError; + | ServerMessage.OneOffQueryResponse; export default ServerMessage; diff --git a/packages/sdk/src/client_api/subscribe_type.ts b/packages/sdk/src/client_api/subscribe_type.ts index 50db1fa..e784dae 100644 --- a/packages/sdk/src/client_api/subscribe_type.ts +++ b/packages/sdk/src/client_api/subscribe_type.ts @@ -1,33 +1,44 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; export type Subscribe = { queryStrings: string[]; requestId: number; diff --git a/packages/sdk/src/client_api/table_update_type.ts b/packages/sdk/src/client_api/table_update_type.ts index ae5bcd7..5a8a7bc 100644 --- a/packages/sdk/src/client_api/table_update_type.ts +++ b/packages/sdk/src/client_api/table_update_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore 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 deleted file mode 100644 index 9f37731..0000000 --- a/packages/sdk/src/client_api/timestamp_type.ts +++ /dev/null @@ -1,56 +0,0 @@ -// 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 Timestamp = { - microseconds: bigint; -}; - -/** - * A namespace for generated helper functions. - */ -export namespace Timestamp { - /** - * 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('microseconds', AlgebraicType.createU64Type()), - ]); - } - - export function serialize(writer: BinaryWriter, value: Timestamp): void { - Timestamp.getTypeScriptAlgebraicType().serialize(writer, value); - } - - export function deserialize(reader: BinaryReader): Timestamp { - return Timestamp.getTypeScriptAlgebraicType().deserialize(reader); - } -} diff --git a/packages/sdk/src/client_api/transaction_update_type.ts b/packages/sdk/src/client_api/transaction_update_type.ts index 9d22836..04ba3ea 100644 --- a/packages/sdk/src/client_api/transaction_update_type.ts +++ b/packages/sdk/src/client_api/transaction_update_type.ts @@ -1,41 +1,54 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore import { UpdateStatus as __UpdateStatus } from './update_status_type'; -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 = { status: __UpdateStatus; - timestamp: __Timestamp; + timestamp: Timestamp; callerIdentity: Identity; callerAddress: Address; reducerCall: __ReducerCallInfo; @@ -57,10 +70,7 @@ export namespace TransactionUpdate { 'status', __UpdateStatus.getTypeScriptAlgebraicType() ), - new ProductTypeElement( - 'timestamp', - __Timestamp.getTypeScriptAlgebraicType() - ), + new ProductTypeElement('timestamp', AlgebraicType.createTimestampType()), new ProductTypeElement( 'callerIdentity', AlgebraicType.createIdentityType() diff --git a/packages/sdk/src/client_api/update_status_type.ts b/packages/sdk/src/client_api/update_status_type.ts index 7da2621..1e145ad 100644 --- a/packages/sdk/src/client_api/update_status_type.ts +++ b/packages/sdk/src/client_api/update_status_type.ts @@ -1,33 +1,45 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. +// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD. -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck import { + // @ts-ignore Address, + // @ts-ignore AlgebraicType, + // @ts-ignore AlgebraicValue, + // @ts-ignore BinaryReader, + // @ts-ignore BinaryWriter, - CallReducerFlags, + // @ts-ignore DBConnectionBuilder, + // @ts-ignore DBConnectionImpl, + // @ts-ignore DBContext, - ErrorContextInterface, + // @ts-ignore Event, + // @ts-ignore EventContextInterface, + // @ts-ignore Identity, + // @ts-ignore ProductType, + // @ts-ignore ProductTypeElement, - ReducerEventContextInterface, - SubscriptionBuilderImpl, - SubscriptionEventContextInterface, + // @ts-ignore SumType, + // @ts-ignore SumTypeVariant, + // @ts-ignore TableCache, + // @ts-ignore + Timestamp, + // @ts-ignore deepEqual, -} from '../index'; +} from '..'; +// @ts-ignore import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; // A namespace for generated variants and helper functions. diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index b8ffb12..cbce22c 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -5,3 +5,4 @@ export * from './address.ts'; export * from './client_cache.ts'; export * from './identity.ts'; export * from './message_types.ts'; +export * from './timestamp.ts'; diff --git a/packages/sdk/src/message_types.ts b/packages/sdk/src/message_types.ts index 13f5fb2..ffdfe0e 100644 --- a/packages/sdk/src/message_types.ts +++ b/packages/sdk/src/message_types.ts @@ -1,7 +1,8 @@ import { Address } from './address.ts'; -import type { Timestamp, UpdateStatus } from './client_api/index.ts'; +import type { UpdateStatus } from './client_api/index.ts'; import { Identity } from './identity.ts'; import type { TableUpdate } from './table_cache.ts'; +import { Timestamp } from './timestamp.ts'; export type InitialSubscriptionMessage = { tag: 'InitialSubscription'; diff --git a/packages/sdk/src/reducer_event.ts b/packages/sdk/src/reducer_event.ts index 7bd419a..a72e385 100644 --- a/packages/sdk/src/reducer_event.ts +++ b/packages/sdk/src/reducer_event.ts @@ -1,5 +1,10 @@ import { Address } from './address.ts'; +<<<<<<< HEAD import type { Reducer, Timestamp, UpdateStatus } from './client_api/index.ts'; +======= +import { Timestamp } from './timestamp.ts'; +import type { UpdateStatus } from './client_api/index.ts'; +>>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) import { Identity } from './identity.ts'; export type ReducerInfoType = { name: string; args?: any } | never; diff --git a/packages/sdk/src/timestamp.ts b/packages/sdk/src/timestamp.ts new file mode 100644 index 0000000..e04a289 --- /dev/null +++ b/packages/sdk/src/timestamp.ts @@ -0,0 +1,57 @@ +/** + * A point in time, represented as a number of nanoseconds since the Unix epoch. + */ +export class Timestamp { + __timestamp_nanos_since_unix_epoch: bigint; + + private static NANOS_PER_MILLIS: bigint = 1000000n; + + get nanosSinceUnixEpoch(): bigint { + return this.__timestamp_nanos_since_unix_epoch; + } + + constructor(nanos: bigint) { + this.__timestamp_nanos_since_unix_epoch = nanos; + } + + /** + * The Unix epoch, the midnight at the beginning of January 1, 1970, UTC. + */ + static UNIX_EPOCH: Timestamp = new Timestamp(0n); + + /** + * Get a `Timestamp` representing the execution environment's belief of the current moment in time. + */ + static now(): Timestamp { + return Timestamp.fromDate(new Date()); + } + + /** + * Get a `Timestamp` representing the same point in time as `date`. + */ + static fromDate(date: Date): Timestamp { + const millis = date.getTime(); + const nanos = BigInt(millis) * Timestamp.NANOS_PER_MILLIS; + return new Timestamp(nanos); + } + + /** + * Get a `Date` representing approximately the same point in time as `this`. + * + * This method truncates to millisecond precision, + * and throws `RangeError` if the `Timestamp` is outside the range representable as a `Date`. + */ + toDate(): Date { + const nanos = this.__timestamp_nanos_since_unix_epoch; + const millis = nanos / Timestamp.NANOS_PER_MILLIS; + if ( + millis > BigInt(Number.MAX_SAFE_INTEGER) || + millis < BigInt(Number.MIN_SAFE_INTEGER) + ) { + throw new RangeError( + "Timestamp is outside of the representable range of JS's Date" + ); + } + return new Date(Number(millis)); + } +} diff --git a/packages/sdk/tests/spacetimedb_client.test.ts b/packages/sdk/tests/spacetimedb_client.test.ts index 81c3c33..f8a9153 100644 --- a/packages/sdk/tests/spacetimedb_client.test.ts +++ b/packages/sdk/tests/spacetimedb_client.test.ts @@ -7,6 +7,7 @@ import { } from '@clockworklabs/test-app/src/module_bindings'; import { beforeEach, describe, expect, test } from 'vitest'; import { Address } from '../src/address'; +import { Timestamp } from '../src/timestamp'; import { AlgebraicType } from '../src/algebraic_type'; import { parseValue } from '../src/algebraic_value'; import BinaryWriter from '../src/binary_writer'; @@ -284,8 +285,13 @@ describe('SpacetimeDBClient', () => { }, ], }), +<<<<<<< HEAD timestamp: { microseconds: BigInt(1681391805281203) }, callerIdentity: anIdentity, +======= + timestamp: new Timestamp(1681391805281203n), + callerIdentity: new Identity('00ff01'), +>>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -432,8 +438,13 @@ describe('SpacetimeDBClient', () => { }, ], }), +<<<<<<< HEAD timestamp: { microseconds: BigInt(1681391805281203) }, callerIdentity: anIdentity, +======= + timestamp: new Timestamp(1681391805281203n), + callerIdentity: new Identity('00ff01'), +>>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -514,8 +525,13 @@ describe('SpacetimeDBClient', () => { }, ], }), +<<<<<<< HEAD timestamp: { microseconds: BigInt(1681391805281203) }, callerIdentity: anIdentity, +======= + timestamp: new Timestamp(1681391805281203n), + callerIdentity: new Identity('00ff01'), +>>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -661,8 +677,13 @@ describe('SpacetimeDBClient', () => { }, ], }), +<<<<<<< HEAD timestamp: { microseconds: BigInt(1681391805281203) }, callerIdentity: anIdentity, +======= + timestamp: new Timestamp(1681391805281203n), + callerIdentity: new Identity('00ff01'), +>>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', From 49d23be1ae53db0613e68cc890785e82ae9e12d8 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Thu, 17 Oct 2024 10:04:39 -0400 Subject: [PATCH 2/9] Add `TimeDuration` class --- packages/sdk/src/algebraic_type.ts | 29 +++++++++++++++++++++++++++-- packages/sdk/src/index.ts | 1 + packages/sdk/src/time_duration.ts | 24 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 packages/sdk/src/time_duration.ts diff --git a/packages/sdk/src/algebraic_type.ts b/packages/sdk/src/algebraic_type.ts index d82d3d9..6c53c4e 100644 --- a/packages/sdk/src/algebraic_type.ts +++ b/packages/sdk/src/algebraic_type.ts @@ -354,8 +354,8 @@ export class AlgebraicType { } static createScheduleAtType(): AlgebraicType { return AlgebraicType.createSumType([ - new SumTypeVariant('Interval', AlgebraicType.createU64Type()), - new SumTypeVariant('Time', AlgebraicType.createU64Type()), + new SumTypeVariant('Interval', AlgebraicType.createTimeDurationType()), + new SumTypeVariant('Time', AlgebraicType.createTimestampType()), ]); } static createTimestampType(): AlgebraicType { @@ -366,6 +366,14 @@ export class AlgebraicType { ), ]); } + static createTimeDurationType(): AlgebraicType { + return AlgebraicType.createProductType([ + new ProductTypeElement( + '__time_duration_nanos', + AlgebraicType.createI64Type() + ), + ]) + } isProductType(): boolean { return this.type === Type.ProductType; @@ -397,6 +405,15 @@ export class AlgebraicType { ); } + #isI64Newtype(tag: string): boolean { + return ( + this.isProductType() && + this.product.elements.length === 1 && + this.product.elements[0].algebraicType.type === Type.I64 && + this.product.elements[0].name === tag + ) + } + isIdentity(): boolean { return this.#isBytesNewtype('__identity__'); } @@ -405,6 +422,14 @@ export class AlgebraicType { return this.#isBytesNewtype('__address__'); } + isTimestamp(): boolean { + return this.#isI64Newtype('__timestamp_nanos_since_unix_epoch'); + } + + isTimeDuration(): boolean { + return this.#isI64Newtype('__time_duration_nanos'); + } + serialize(writer: BinaryWriter, value: any): void { switch (this.type) { case Type.ProductType: diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index cbce22c..88e20da 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -6,3 +6,4 @@ export * from './client_cache.ts'; export * from './identity.ts'; export * from './message_types.ts'; export * from './timestamp.ts'; +export * from './time_duration.ts' diff --git a/packages/sdk/src/time_duration.ts b/packages/sdk/src/time_duration.ts new file mode 100644 index 0000000..57714c4 --- /dev/null +++ b/packages/sdk/src/time_duration.ts @@ -0,0 +1,24 @@ +/** + * A difference between two points in time, represented as a number of nanoseconds. + */ +export class TimeDuration { + __time_duration_nanos: bigint; + + private static NANOS_PER_MILLIS: bigint = 1000000n; + + get nanos(): bigint { + return this.__time_duration_nanos; + } + + get millis(): number { + return Number(this.nanos / TimeDuration.NANOS_PER_MILLIS); + } + + constructor(nanos: bigint) { + this.__time_duration_nanos = nanos; + } + + static fromMillis(millis: number) { + return new TimeDuration(BigInt(millis) * TimeDuration.NANOS_PER_MILLIS); + } +} From e944661701e2f60ff5fe3d79bec9de225b6c7e67 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Thu, 17 Oct 2024 10:59:42 -0400 Subject: [PATCH 3/9] Add forgotten return type annotation --- packages/sdk/src/time_duration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/time_duration.ts b/packages/sdk/src/time_duration.ts index 57714c4..3b9c102 100644 --- a/packages/sdk/src/time_duration.ts +++ b/packages/sdk/src/time_duration.ts @@ -18,7 +18,7 @@ export class TimeDuration { this.__time_duration_nanos = nanos; } - static fromMillis(millis: number) { + static fromMillis(millis: number): Timestamp { return new TimeDuration(BigInt(millis) * TimeDuration.NANOS_PER_MILLIS); } } From 950617838371daa2327acadb4e36a3cea2232116 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Thu, 17 Oct 2024 11:48:38 -0400 Subject: [PATCH 4/9] :facepalm: --- packages/sdk/src/time_duration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/time_duration.ts b/packages/sdk/src/time_duration.ts index 3b9c102..46f14c2 100644 --- a/packages/sdk/src/time_duration.ts +++ b/packages/sdk/src/time_duration.ts @@ -18,7 +18,7 @@ export class TimeDuration { this.__time_duration_nanos = nanos; } - static fromMillis(millis: number): Timestamp { + static fromMillis(millis: number): TimeDuration { return new TimeDuration(BigInt(millis) * TimeDuration.NANOS_PER_MILLIS); } } From 131f468f75bef4609a1faf05e18953503d1ba764 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Thu, 17 Oct 2024 11:50:44 -0400 Subject: [PATCH 5/9] Prettier --- packages/sdk/src/algebraic_type.ts | 10 +++++----- packages/sdk/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/sdk/src/algebraic_type.ts b/packages/sdk/src/algebraic_type.ts index 6c53c4e..b011000 100644 --- a/packages/sdk/src/algebraic_type.ts +++ b/packages/sdk/src/algebraic_type.ts @@ -372,7 +372,7 @@ export class AlgebraicType { '__time_duration_nanos', AlgebraicType.createI64Type() ), - ]) + ]); } isProductType(): boolean { @@ -408,10 +408,10 @@ export class AlgebraicType { #isI64Newtype(tag: string): boolean { return ( this.isProductType() && - this.product.elements.length === 1 && - this.product.elements[0].algebraicType.type === Type.I64 && - this.product.elements[0].name === tag - ) + this.product.elements.length === 1 && + this.product.elements[0].algebraicType.type === Type.I64 && + this.product.elements[0].name === tag + ); } isIdentity(): boolean { diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 88e20da..0b40e58 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -6,4 +6,4 @@ export * from './client_cache.ts'; export * from './identity.ts'; export * from './message_types.ts'; export * from './timestamp.ts'; -export * from './time_duration.ts' +export * from './time_duration.ts'; From a76619ec23ac26b5ddb2874378a3e82f05db6241 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Mon, 21 Oct 2024 11:11:34 -0400 Subject: [PATCH 6/9] Update `client_api` schema to use `TimeDuration` --- .../sdk/src/client_api/bsatn_row_list_type.ts | 2 ++ packages/sdk/src/client_api/call_reducer_type.ts | 2 ++ .../sdk/src/client_api/client_message_type.ts | 2 ++ .../client_api/compressable_query_update_type.ts | 2 ++ .../sdk/src/client_api/database_update_type.ts | 2 ++ packages/sdk/src/client_api/energy_quanta_type.ts | 2 ++ .../sdk/src/client_api/identity_token_type.ts | 2 ++ packages/sdk/src/client_api/index.ts | 2 ++ .../src/client_api/initial_subscription_type.ts | 8 +++++--- .../src/client_api/one_off_query_response_type.ts | 8 +++++--- packages/sdk/src/client_api/one_off_query_type.ts | 2 ++ packages/sdk/src/client_api/one_off_table_type.ts | 2 ++ packages/sdk/src/client_api/query_update_type.ts | 2 ++ .../sdk/src/client_api/reducer_call_info_type.ts | 2 ++ packages/sdk/src/client_api/row_size_hint_type.ts | 2 ++ .../sdk/src/client_api/server_message_type.ts | 2 ++ packages/sdk/src/client_api/subscribe_type.ts | 2 ++ packages/sdk/src/client_api/table_update_type.ts | 2 ++ .../sdk/src/client_api/transaction_update_type.ts | 8 +++++--- packages/sdk/src/client_api/update_status_type.ts | 2 ++ packages/sdk/tests/spacetimedb_client.test.ts | 15 ++++++++------- 21 files changed, 57 insertions(+), 16 deletions(-) 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 054b37f..46133f5 100644 --- a/packages/sdk/src/client_api/bsatn_row_list_type.ts +++ b/packages/sdk/src/client_api/bsatn_row_list_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/call_reducer_type.ts b/packages/sdk/src/client_api/call_reducer_type.ts index bcd96ee..3b11281 100644 --- a/packages/sdk/src/client_api/call_reducer_type.ts +++ b/packages/sdk/src/client_api/call_reducer_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/client_message_type.ts b/packages/sdk/src/client_api/client_message_type.ts index c833783..0682e50 100644 --- a/packages/sdk/src/client_api/client_message_type.ts +++ b/packages/sdk/src/client_api/client_message_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, 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 380878a..0df79d1 100644 --- a/packages/sdk/src/client_api/compressable_query_update_type.ts +++ b/packages/sdk/src/client_api/compressable_query_update_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/database_update_type.ts b/packages/sdk/src/client_api/database_update_type.ts index c6dfbe4..a232c57 100644 --- a/packages/sdk/src/client_api/database_update_type.ts +++ b/packages/sdk/src/client_api/database_update_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/energy_quanta_type.ts b/packages/sdk/src/client_api/energy_quanta_type.ts index c71a9c8..e89c14a 100644 --- a/packages/sdk/src/client_api/energy_quanta_type.ts +++ b/packages/sdk/src/client_api/energy_quanta_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/identity_token_type.ts b/packages/sdk/src/client_api/identity_token_type.ts index d77e7b5..36a7644 100644 --- a/packages/sdk/src/client_api/identity_token_type.ts +++ b/packages/sdk/src/client_api/identity_token_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/index.ts b/packages/sdk/src/client_api/index.ts index 69e3260..93d1cbc 100644 --- a/packages/sdk/src/client_api/index.ts +++ b/packages/sdk/src/client_api/index.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; diff --git a/packages/sdk/src/client_api/initial_subscription_type.ts b/packages/sdk/src/client_api/initial_subscription_type.ts index 52bae89..9a3d335 100644 --- a/packages/sdk/src/client_api/initial_subscription_type.ts +++ b/packages/sdk/src/client_api/initial_subscription_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, @@ -45,7 +47,7 @@ import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; export type InitialSubscription = { databaseUpdate: __DatabaseUpdate; requestId: number; - totalHostExecutionDurationMicros: bigint; + totalHostExecutionDuration: TimeDuration; }; /** @@ -64,8 +66,8 @@ export namespace InitialSubscription { ), new ProductTypeElement('requestId', AlgebraicType.createU32Type()), new ProductTypeElement( - 'totalHostExecutionDurationMicros', - AlgebraicType.createU64Type() + 'totalHostExecutionDuration', + AlgebraicType.createTimeDurationType() ), ]); } 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 2db2ce2..aa7fc1d 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 @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, @@ -46,7 +48,7 @@ export type OneOffQueryResponse = { messageId: Uint8Array; error: string | undefined; tables: __OneOffTable[]; - totalHostExecutionDurationMicros: bigint; + totalHostExecutionDuration: TimeDuration; }; /** @@ -74,8 +76,8 @@ export namespace OneOffQueryResponse { ) ), new ProductTypeElement( - 'totalHostExecutionDurationMicros', - AlgebraicType.createU64Type() + 'totalHostExecutionDuration', + AlgebraicType.createTimeDurationType() ), ]); } 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 5d41a11..af476c9 100644 --- a/packages/sdk/src/client_api/one_off_query_type.ts +++ b/packages/sdk/src/client_api/one_off_query_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, 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 f12c6e3..86a1490 100644 --- a/packages/sdk/src/client_api/one_off_table_type.ts +++ b/packages/sdk/src/client_api/one_off_table_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/query_update_type.ts b/packages/sdk/src/client_api/query_update_type.ts index 42189a6..7f099dd 100644 --- a/packages/sdk/src/client_api/query_update_type.ts +++ b/packages/sdk/src/client_api/query_update_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, 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 8d0bd32..e413837 100644 --- a/packages/sdk/src/client_api/reducer_call_info_type.ts +++ b/packages/sdk/src/client_api/reducer_call_info_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, 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 df36c83..8e0be88 100644 --- a/packages/sdk/src/client_api/row_size_hint_type.ts +++ b/packages/sdk/src/client_api/row_size_hint_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/server_message_type.ts b/packages/sdk/src/client_api/server_message_type.ts index 8b207a7..927799a 100644 --- a/packages/sdk/src/client_api/server_message_type.ts +++ b/packages/sdk/src/client_api/server_message_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/subscribe_type.ts b/packages/sdk/src/client_api/subscribe_type.ts index e784dae..1d6e410 100644 --- a/packages/sdk/src/client_api/subscribe_type.ts +++ b/packages/sdk/src/client_api/subscribe_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/table_update_type.ts b/packages/sdk/src/client_api/table_update_type.ts index 5a8a7bc..2dfff7c 100644 --- a/packages/sdk/src/client_api/table_update_type.ts +++ b/packages/sdk/src/client_api/table_update_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/src/client_api/transaction_update_type.ts b/packages/sdk/src/client_api/transaction_update_type.ts index 04ba3ea..6d46adb 100644 --- a/packages/sdk/src/client_api/transaction_update_type.ts +++ b/packages/sdk/src/client_api/transaction_update_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, @@ -53,7 +55,7 @@ export type TransactionUpdate = { callerAddress: Address; reducerCall: __ReducerCallInfo; energyQuantaUsed: __EnergyQuanta; - hostExecutionDurationMicros: bigint; + totalHostExecutionDuration: TimeDuration; }; /** @@ -88,8 +90,8 @@ export namespace TransactionUpdate { __EnergyQuanta.getTypeScriptAlgebraicType() ), new ProductTypeElement( - 'hostExecutionDurationMicros', - AlgebraicType.createU64Type() + 'totalHostExecutionDuration', + AlgebraicType.createTimeDurationType() ), ]); } diff --git a/packages/sdk/src/client_api/update_status_type.ts b/packages/sdk/src/client_api/update_status_type.ts index 1e145ad..b7f46d3 100644 --- a/packages/sdk/src/client_api/update_status_type.ts +++ b/packages/sdk/src/client_api/update_status_type.ts @@ -35,6 +35,8 @@ import { // @ts-ignore TableCache, // @ts-ignore + TimeDuration, + // @ts-ignore Timestamp, // @ts-ignore deepEqual, diff --git a/packages/sdk/tests/spacetimedb_client.test.ts b/packages/sdk/tests/spacetimedb_client.test.ts index f8a9153..5b37392 100644 --- a/packages/sdk/tests/spacetimedb_client.test.ts +++ b/packages/sdk/tests/spacetimedb_client.test.ts @@ -8,6 +8,7 @@ import { import { beforeEach, describe, expect, test } from 'vitest'; import { Address } from '../src/address'; import { Timestamp } from '../src/timestamp'; +import { TimeDuration } from '../src/time_duration'; import { AlgebraicType } from '../src/algebraic_type'; import { parseValue } from '../src/algebraic_value'; import BinaryWriter from '../src/binary_writer'; @@ -248,7 +249,7 @@ describe('SpacetimeDBClient', () => { ], }, requestId: 0, - totalHostExecutionDurationMicros: BigInt(0), + totalHostExecutionDuration: new TimeDuration(BigInt(0)), }); wsAdapter.sendToClient(subscriptionMessage); @@ -300,7 +301,7 @@ describe('SpacetimeDBClient', () => { requestId: 0, }, energyQuantaUsed: { quanta: BigInt(33841000) }, - hostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(transactionUpdate); @@ -398,7 +399,7 @@ describe('SpacetimeDBClient', () => { ], }, requestId: 0, - totalHostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(subscriptionMessage); @@ -453,7 +454,7 @@ describe('SpacetimeDBClient', () => { requestId: 0, }, energyQuantaUsed: { quanta: BigInt(33841000) }, - hostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(transactionUpdate); @@ -540,7 +541,7 @@ describe('SpacetimeDBClient', () => { requestId: 0, }, energyQuantaUsed: { quanta: BigInt(33841000) }, - hostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(transactionUpdate); @@ -629,7 +630,7 @@ describe('SpacetimeDBClient', () => { ], }, requestId: 0, - totalHostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(subscriptionMessage); @@ -692,7 +693,7 @@ describe('SpacetimeDBClient', () => { requestId: 0, }, energyQuantaUsed: { quanta: BigInt(33841000) }, - hostExecutionDurationMicros: BigInt(1234567890), + totalHostExecutionDuration: new TimeDuration(BigInt(1234567890)), }); wsAdapter.sendToClient(transactionUpdate); From f1019ba461fa36f49b197e96811a8a2dfc7ae09b Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Wed, 30 Oct 2024 12:45:30 -0400 Subject: [PATCH 7/9] Micros, not nanos From SpacetimeDB 072c2ea3a32a6cf6d05ecf1ac9c9b54a4f95e340: Prioritize BSATN and BFLATN compat with 0.12 Timestamp and TimeDuration store `micros: i64`, not `nanos: i64`. This means that old commitlogs and snapshots should still be compatible, assuming they don't include timestamps greater than `i64::MAX`, as previously we used `micros: u64`. This seems unlikely. --- packages/sdk/src/algebraic_type.ts | 8 ++++---- packages/sdk/src/time_duration.ts | 18 +++++++++--------- packages/sdk/src/timestamp.ts | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/sdk/src/algebraic_type.ts b/packages/sdk/src/algebraic_type.ts index b011000..d38cf95 100644 --- a/packages/sdk/src/algebraic_type.ts +++ b/packages/sdk/src/algebraic_type.ts @@ -361,7 +361,7 @@ export class AlgebraicType { static createTimestampType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement( - '__timestamp_nanos_since_unix_epoch', + '__timestamp_micros_since_unix_epoch__', AlgebraicType.createI64Type() ), ]); @@ -369,7 +369,7 @@ export class AlgebraicType { static createTimeDurationType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement( - '__time_duration_nanos', + '__time_duration_micros__', AlgebraicType.createI64Type() ), ]); @@ -423,11 +423,11 @@ export class AlgebraicType { } isTimestamp(): boolean { - return this.#isI64Newtype('__timestamp_nanos_since_unix_epoch'); + return this.#isI64Newtype('__timestamp_micros_since_unix_epoch__'); } isTimeDuration(): boolean { - return this.#isI64Newtype('__time_duration_nanos'); + return this.#isI64Newtype('__time_duration_micros__'); } serialize(writer: BinaryWriter, value: any): void { diff --git a/packages/sdk/src/time_duration.ts b/packages/sdk/src/time_duration.ts index 46f14c2..6179ccd 100644 --- a/packages/sdk/src/time_duration.ts +++ b/packages/sdk/src/time_duration.ts @@ -1,24 +1,24 @@ /** - * A difference between two points in time, represented as a number of nanoseconds. + * A difference between two points in time, represented as a number of microseconds. */ export class TimeDuration { - __time_duration_nanos: bigint; + __time_duration_micros__: bigint; - private static NANOS_PER_MILLIS: bigint = 1000000n; + private static MICROS_PER_MILLIS: bigint = 1000n; - get nanos(): bigint { - return this.__time_duration_nanos; + get micros(): bigint { + return this.__time_duration_micros__; } get millis(): number { - return Number(this.nanos / TimeDuration.NANOS_PER_MILLIS); + return Number(this.micros / TimeDuration.MICROS_PER_MILLIS); } - constructor(nanos: bigint) { - this.__time_duration_nanos = nanos; + constructor(micros: bigint) { + this.__time_duration_micros__ = micros; } static fromMillis(millis: number): TimeDuration { - return new TimeDuration(BigInt(millis) * TimeDuration.NANOS_PER_MILLIS); + return new TimeDuration(BigInt(millis) * TimeDuration.MICROS_PER_MILLIS); } } diff --git a/packages/sdk/src/timestamp.ts b/packages/sdk/src/timestamp.ts index e04a289..92a8c4e 100644 --- a/packages/sdk/src/timestamp.ts +++ b/packages/sdk/src/timestamp.ts @@ -1,17 +1,17 @@ /** - * A point in time, represented as a number of nanoseconds since the Unix epoch. + * A point in time, represented as a number of microseconds since the Unix epoch. */ export class Timestamp { - __timestamp_nanos_since_unix_epoch: bigint; + __timestamp_micros_since_unix_epoch: bigint; - private static NANOS_PER_MILLIS: bigint = 1000000n; + private static MICROS_PER_MILLIS: bigint = 1000n; - get nanosSinceUnixEpoch(): bigint { - return this.__timestamp_nanos_since_unix_epoch; + get microsSinceUnixEpoch(): bigint { + return this.__timestamp_micros_since_unix_epoch; } - constructor(nanos: bigint) { - this.__timestamp_nanos_since_unix_epoch = nanos; + constructor(micros: bigint) { + this.__timestamp_micros_since_unix_epoch = micros; } /** @@ -31,8 +31,8 @@ export class Timestamp { */ static fromDate(date: Date): Timestamp { const millis = date.getTime(); - const nanos = BigInt(millis) * Timestamp.NANOS_PER_MILLIS; - return new Timestamp(nanos); + const micros = BigInt(millis) * Timestamp.MICROS_PER_MILLIS; + return new Timestamp(micros); } /** @@ -42,8 +42,8 @@ export class Timestamp { * and throws `RangeError` if the `Timestamp` is outside the range representable as a `Date`. */ toDate(): Date { - const nanos = this.__timestamp_nanos_since_unix_epoch; - const millis = nanos / Timestamp.NANOS_PER_MILLIS; + const micros = this.__timestamp_micros_since_unix_epoch; + const millis = micros / Timestamp.MICROS_PER_MILLIS; if ( millis > BigInt(Number.MAX_SAFE_INTEGER) || millis < BigInt(Number.MIN_SAFE_INTEGER) From 9065fb90ff39a9c0b4b9a3532a86e25eaa9c3d8f Mon Sep 17 00:00:00 2001 From: Tyler Cloutier Date: Sat, 8 Feb 2025 13:06:57 -0500 Subject: [PATCH 8/9] Ran new code gen --- .../sdk/src/client_api/bsatn_row_list_type.ts | 32 +++---- .../sdk/src/client_api/call_reducer_type.ts | 33 +++---- .../sdk/src/client_api/client_message_type.ts | 61 +++++++------ .../compressable_query_update_type.ts | 32 +++---- .../src/client_api/database_update_type.ts | 32 +++---- .../sdk/src/client_api/energy_quanta_type.ts | 31 +++---- .../sdk/src/client_api/identity_token_type.ts | 31 +++---- packages/sdk/src/client_api/index.ts | 18 ++-- .../client_api/initial_subscription_type.ts | 32 +++---- .../client_api/one_off_query_response_type.ts | 32 +++---- .../sdk/src/client_api/one_off_query_type.ts | 31 +++---- .../sdk/src/client_api/one_off_table_type.ts | 32 +++---- packages/sdk/src/client_api/query_id_type.ts | 2 + .../sdk/src/client_api/query_update_type.ts | 32 +++---- .../src/client_api/reducer_call_info_type.ts | 31 +++---- .../sdk/src/client_api/row_size_hint_type.ts | 31 +++---- .../sdk/src/client_api/server_message_type.ts | 89 +++++++++++++------ .../src/client_api/subscribe_applied_type.ts | 2 + .../sdk/src/client_api/subscribe_rows_type.ts | 2 + .../src/client_api/subscribe_single_type.ts | 2 + packages/sdk/src/client_api/subscribe_type.ts | 31 +++---- .../src/client_api/subscription_error_type.ts | 2 + .../sdk/src/client_api/table_update_type.ts | 32 +++---- .../transaction_update_light_type.ts | 2 + .../src/client_api/transaction_update_type.ts | 34 +++---- .../client_api/unsubscribe_applied_type.ts | 2 + .../sdk/src/client_api/unsubscribe_type.ts | 2 + .../sdk/src/client_api/update_status_type.ts | 32 +++---- 28 files changed, 300 insertions(+), 425 deletions(-) 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 46133f5..130a6b3 100644 --- a/packages/sdk/src/client_api/bsatn_row_list_type.ts +++ b/packages/sdk/src/client_api/bsatn_row_list_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 3b11281..b7910e2 100644 --- a/packages/sdk/src/client_api/call_reducer_type.ts +++ b/packages/sdk/src/client_api/call_reducer_type.ts @@ -1,50 +1,40 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @ts-ignore deepEqual, -} from '..'; +} from '../index'; export type CallReducer = { reducer: string; args: Uint8Array; requestId: number; + flags: number; }; /** @@ -63,6 +53,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/client_message_type.ts b/packages/sdk/src/client_api/client_message_type.ts index 0682e50..5d2be01 100644 --- a/packages/sdk/src/client_api/client_message_type.ts +++ b/packages/sdk/src/client_api/client_message_type.ts @@ -1,52 +1,40 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 { @@ -56,6 +44,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. // ``` @@ -75,6 +68,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([ @@ -87,6 +88,14 @@ export namespace ClientMessage { 'OneOffQuery', __OneOffQuery.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'SubscribeSingle', + __SubscribeSingle.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'Unsubscribe', + __Unsubscribe.getTypeScriptAlgebraicType() + ), ]); } @@ -103,6 +112,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 0df79d1..7d90beb 100644 --- a/packages/sdk/src/client_api/compressable_query_update_type.ts +++ b/packages/sdk/src/client_api/compressable_query_update_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 a232c57..a397669 100644 --- a/packages/sdk/src/client_api/database_update_type.ts +++ b/packages/sdk/src/client_api/database_update_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 e89c14a..0e05256 100644 --- a/packages/sdk/src/client_api/energy_quanta_type.ts +++ b/packages/sdk/src/client_api/energy_quanta_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 36a7644..543b8cb 100644 --- a/packages/sdk/src/client_api/identity_token_type.ts +++ b/packages/sdk/src/client_api/identity_token_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 93d1cbc..151875d 100644 --- a/packages/sdk/src/client_api/index.ts +++ b/packages/sdk/src/client_api/index.ts @@ -148,11 +148,19 @@ export class DBConnection extends DBConnectionImpl< RemoteReducers, SetReducerFlags > { - static builder = (): DBConnectionBuilder => { - return new DBConnectionBuilder( - REMOTE_MODULE, - (imp: DBConnectionImpl) => imp as DBConnection - ); + static builder = (): DBConnectionBuilder< + DBConnection, + ErrorContext, + SubscriptionEventContext + > => { + return new DBConnectionBuilder< + DBConnection, + ErrorContext, + SubscriptionEventContext + >(REMOTE_MODULE, (imp: DBConnectionImpl) => imp as DBConnection); + }; + subscriptionBuilder = (): SubscriptionBuilder => { + return new SubscriptionBuilder(this); }; subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); diff --git a/packages/sdk/src/client_api/initial_subscription_type.ts b/packages/sdk/src/client_api/initial_subscription_type.ts index 9a3d335..033c40a 100644 --- a/packages/sdk/src/client_api/initial_subscription_type.ts +++ b/packages/sdk/src/client_api/initial_subscription_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 aa7fc1d..946230a 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,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 af476c9..4aecd6a 100644 --- a/packages/sdk/src/client_api/one_off_query_type.ts +++ b/packages/sdk/src/client_api/one_off_query_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 86a1490..1d0132f 100644 --- a/packages/sdk/src/client_api/one_off_table_type.ts +++ b/packages/sdk/src/client_api/one_off_table_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 index 8bded14..e82372e 100644 --- a/packages/sdk/src/client_api/query_id_type.ts +++ b/packages/sdk/src/client_api/query_id_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; export type QueryId = { diff --git a/packages/sdk/src/client_api/query_update_type.ts b/packages/sdk/src/client_api/query_update_type.ts index 7f099dd..5883a44 100644 --- a/packages/sdk/src/client_api/query_update_type.ts +++ b/packages/sdk/src/client_api/query_update_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 e413837..ad0b126 100644 --- a/packages/sdk/src/client_api/reducer_call_info_type.ts +++ b/packages/sdk/src/client_api/reducer_call_info_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 8e0be88..3792091 100644 --- a/packages/sdk/src/client_api/row_size_hint_type.ts +++ b/packages/sdk/src/client_api/row_size_hint_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 927799a..76889a5 100644 --- a/packages/sdk/src/client_api/server_message_type.ts +++ b/packages/sdk/src/client_api/server_message_type.ts @@ -1,54 +1,43 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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'; 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 { @@ -63,11 +52,27 @@ 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'; 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. // ``` @@ -81,6 +86,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, @@ -88,6 +96,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([ @@ -99,6 +116,10 @@ export namespace ServerMessage { 'TransactionUpdate', __TransactionUpdate.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'TransactionUpdateLight', + __TransactionUpdateLight.getTypeScriptAlgebraicType() + ), new SumTypeVariant( 'IdentityToken', __IdentityToken.getTypeScriptAlgebraicType() @@ -107,6 +128,18 @@ export namespace ServerMessage { 'OneOffQueryResponse', __OneOffQueryResponse.getTypeScriptAlgebraicType() ), + new SumTypeVariant( + 'SubscribeApplied', + __SubscribeApplied.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'UnsubscribeApplied', + __UnsubscribeApplied.getTypeScriptAlgebraicType() + ), + new SumTypeVariant( + 'SubscriptionError', + __SubscriptionError.getTypeScriptAlgebraicType() + ), ]); } @@ -123,7 +156,11 @@ export namespace ServerMessage { export type ServerMessage = | ServerMessage.InitialSubscription | 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 index a09d042..eccff79 100644 --- a/packages/sdk/src/client_api/subscribe_applied_type.ts +++ b/packages/sdk/src/client_api/subscribe_applied_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { QueryId as __QueryId } from './query_id_type'; diff --git a/packages/sdk/src/client_api/subscribe_rows_type.ts b/packages/sdk/src/client_api/subscribe_rows_type.ts index 7c65448..486e7b8 100644 --- a/packages/sdk/src/client_api/subscribe_rows_type.ts +++ b/packages/sdk/src/client_api/subscribe_rows_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { TableUpdate as __TableUpdate } from './table_update_type'; diff --git a/packages/sdk/src/client_api/subscribe_single_type.ts b/packages/sdk/src/client_api/subscribe_single_type.ts index f0115c9..3bb8dc6 100644 --- a/packages/sdk/src/client_api/subscribe_single_type.ts +++ b/packages/sdk/src/client_api/subscribe_single_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { QueryId as __QueryId } from './query_id_type'; diff --git a/packages/sdk/src/client_api/subscribe_type.ts b/packages/sdk/src/client_api/subscribe_type.ts index 1d6e410..67e538f 100644 --- a/packages/sdk/src/client_api/subscribe_type.ts +++ b/packages/sdk/src/client_api/subscribe_type.ts @@ -1,46 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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 index d9c4f06..fe89a6a 100644 --- a/packages/sdk/src/client_api/subscription_error_type.ts +++ b/packages/sdk/src/client_api/subscription_error_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; export type SubscriptionError = { diff --git a/packages/sdk/src/client_api/table_update_type.ts b/packages/sdk/src/client_api/table_update_type.ts index 2dfff7c..a31d09d 100644 --- a/packages/sdk/src/client_api/table_update_type.ts +++ b/packages/sdk/src/client_api/table_update_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @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/transaction_update_light_type.ts b/packages/sdk/src/client_api/transaction_update_light_type.ts index 30b2ee6..57bb708 100644 --- a/packages/sdk/src/client_api/transaction_update_light_type.ts +++ b/packages/sdk/src/client_api/transaction_update_light_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; diff --git a/packages/sdk/src/client_api/transaction_update_type.ts b/packages/sdk/src/client_api/transaction_update_type.ts index 6d46adb..4843d71 100644 --- a/packages/sdk/src/client_api/transaction_update_type.ts +++ b/packages/sdk/src/client_api/transaction_update_type.ts @@ -1,51 +1,37 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @ts-ignore deepEqual, -} from '..'; -// @ts-ignore +} from '../index'; import { UpdateStatus as __UpdateStatus } from './update_status_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 index 0b2aad1..d62bd60 100644 --- a/packages/sdk/src/client_api/unsubscribe_applied_type.ts +++ b/packages/sdk/src/client_api/unsubscribe_applied_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { QueryId as __QueryId } from './query_id_type'; diff --git a/packages/sdk/src/client_api/unsubscribe_type.ts b/packages/sdk/src/client_api/unsubscribe_type.ts index 1b9f9f4..8cedb63 100644 --- a/packages/sdk/src/client_api/unsubscribe_type.ts +++ b/packages/sdk/src/client_api/unsubscribe_type.ts @@ -26,6 +26,8 @@ import { SumType, SumTypeVariant, TableCache, + TimeDuration, + Timestamp, deepEqual, } from '../index'; import { QueryId as __QueryId } from './query_id_type'; diff --git a/packages/sdk/src/client_api/update_status_type.ts b/packages/sdk/src/client_api/update_status_type.ts index b7f46d3..732aad5 100644 --- a/packages/sdk/src/client_api/update_status_type.ts +++ b/packages/sdk/src/client_api/update_status_type.ts @@ -1,47 +1,35 @@ // 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 TimeDuration, - // @ts-ignore Timestamp, - // @ts-ignore deepEqual, -} from '..'; -// @ts-ignore +} from '../index'; import { DatabaseUpdate as __DatabaseUpdate } from './database_update_type'; // A namespace for generated variants and helper functions. From a29bc9b940ad91f76a4a9d056211a88873428e32 Mon Sep 17 00:00:00 2001 From: Tyler Cloutier Date: Sat, 8 Feb 2025 13:22:27 -0500 Subject: [PATCH 9/9] Fixed rebase conflicts --- packages/sdk/src/reducer_event.ts | 4 - packages/sdk/tests/spacetimedb_client.test.ts | 108 ++++++++---------- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/packages/sdk/src/reducer_event.ts b/packages/sdk/src/reducer_event.ts index a72e385..bcbc3d7 100644 --- a/packages/sdk/src/reducer_event.ts +++ b/packages/sdk/src/reducer_event.ts @@ -1,10 +1,6 @@ import { Address } from './address.ts'; -<<<<<<< HEAD -import type { Reducer, Timestamp, UpdateStatus } from './client_api/index.ts'; -======= import { Timestamp } from './timestamp.ts'; import type { UpdateStatus } from './client_api/index.ts'; ->>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) import { Identity } from './identity.ts'; export type ReducerInfoType = { name: string; args?: any } | never; diff --git a/packages/sdk/tests/spacetimedb_client.test.ts b/packages/sdk/tests/spacetimedb_client.test.ts index 5b37392..bc2bcac 100644 --- a/packages/sdk/tests/spacetimedb_client.test.ts +++ b/packages/sdk/tests/spacetimedb_client.test.ts @@ -1,10 +1,4 @@ -import { - CreatePlayer, - DBConnection, - Player, - Point, - User, -} from '@clockworklabs/test-app/src/module_bindings'; +import * as module_bindings from '@clockworklabs/test-app/src/module_bindings'; import { beforeEach, describe, expect, test } from 'vitest'; import { Address } from '../src/address'; import { Timestamp } from '../src/timestamp'; @@ -70,29 +64,32 @@ class Deferred { beforeEach(() => {}); -function encodePlayer(value: Player): Uint8Array { +function encodePlayer(value: module_bindings.Player): Uint8Array { const writer = new BinaryWriter(1024); - Player.serialize(writer, value); + module_bindings.Player.serialize(writer, value); return writer.getBuffer(); } -function encodeUser(value: User): Uint8Array { +function encodeUser(value: module_bindings.User): Uint8Array { const writer = new BinaryWriter(1024); - User.serialize(writer, value); + module_bindings.User.serialize(writer, value); return writer.getBuffer(); } -function encodeCreatePlayerArgs(name: string, location: Point): Uint8Array { +function encodeCreatePlayerArgs( + name: string, + location: module_bindings.Point +): Uint8Array { const writer = new BinaryWriter(1024); AlgebraicType.createStringType().serialize(writer, name); - Point.serialize(writer, location); + module_bindings.Point.serialize(writer, location); return writer.getBuffer(); } describe('SpacetimeDBClient', () => { test('auto subscribe on connect', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -135,7 +132,7 @@ describe('SpacetimeDBClient', () => { const onConnectPromise = new Deferred(); const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -163,7 +160,7 @@ describe('SpacetimeDBClient', () => { test('it calls onInsert callback when a record is added with a subscription update and then with a transaction update', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -185,9 +182,12 @@ describe('SpacetimeDBClient', () => { const inserts: { reducerEvent: - | ReducerEvent<{ name: 'CreatePlayer'; args: CreatePlayer }> + | ReducerEvent<{ + name: 'CreatePlayer'; + args: module_bindings.CreatePlayer; + }> | undefined; - player: Player; + player: module_bindings.Player; }[] = []; const insert1Promise = new Deferred(); @@ -208,18 +208,23 @@ describe('SpacetimeDBClient', () => { }); let reducerCallbackLog: { - reducerEvent: ReducerEvent<{ name: 'CreatePlayer'; args: CreatePlayer }>; + reducerEvent: ReducerEvent<{ + name: 'CreatePlayer'; + args: module_bindings.CreatePlayer; + }>; reducerArgs: any[]; }[] = []; - client.reducers.onCreatePlayer((ctx, name: string, location: Point) => { - if (ctx.event.tag === 'Reducer') { - const reducerEvent = ctx.event.value; - reducerCallbackLog.push({ - reducerEvent, - reducerArgs: [name, location], - }); + client.reducers.onCreatePlayer( + (ctx, name: string, location: module_bindings.Point) => { + if (ctx.event.tag === 'Reducer') { + const reducerEvent = ctx.event.value; + reducerCallbackLog.push({ + reducerEvent, + reducerArgs: [name, location], + }); + } } - }); + ); const subscriptionMessage: ws.ServerMessage = ws.ServerMessage.InitialSubscription({ @@ -286,13 +291,8 @@ describe('SpacetimeDBClient', () => { }, ], }), -<<<<<<< HEAD - timestamp: { microseconds: BigInt(1681391805281203) }, - callerIdentity: anIdentity, -======= timestamp: new Timestamp(1681391805281203n), - callerIdentity: new Identity('00ff01'), ->>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) + callerIdentity: anIdentity, callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -326,7 +326,7 @@ describe('SpacetimeDBClient', () => { test('it calls onUpdate callback when a record is added with a subscription update and then with a transaction update', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -349,7 +349,10 @@ describe('SpacetimeDBClient', () => { const update1Promise = new Deferred(); const update2Promise = new Deferred(); - const updates: { oldPlayer: Player; newPlayer: Player }[] = []; + const updates: { + oldPlayer: module_bindings.Player; + newPlayer: module_bindings.Player; + }[] = []; client.db.player.onUpdate((_ctx, oldPlayer, newPlayer) => { updates.push({ oldPlayer, @@ -439,13 +442,8 @@ describe('SpacetimeDBClient', () => { }, ], }), -<<<<<<< HEAD - timestamp: { microseconds: BigInt(1681391805281203) }, - callerIdentity: anIdentity, -======= timestamp: new Timestamp(1681391805281203n), - callerIdentity: new Identity('00ff01'), ->>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) + callerIdentity: anIdentity, callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -467,7 +465,7 @@ describe('SpacetimeDBClient', () => { test('a reducer callback should be called after the database callbacks', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -526,13 +524,8 @@ describe('SpacetimeDBClient', () => { }, ], }), -<<<<<<< HEAD - timestamp: { microseconds: BigInt(1681391805281203) }, - callerIdentity: anIdentity, -======= timestamp: new Timestamp(1681391805281203n), - callerIdentity: new Identity('00ff01'), ->>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) + callerIdentity: anIdentity, callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -552,7 +545,7 @@ describe('SpacetimeDBClient', () => { test('it calls onUpdate callback when a record is added with a subscription update and then with a transaction update when the PK is of type Identity', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -577,7 +570,10 @@ describe('SpacetimeDBClient', () => { const update1Promise = new Deferred(); const update2Promise = new Deferred(); - const updates: { oldUser: User; newUser: User }[] = []; + const updates: { + oldUser: module_bindings.User; + newUser: module_bindings.User; + }[] = []; client.db.user.onUpdate((_ctx, oldUser, newUser) => { updates.push({ oldUser, @@ -678,13 +674,8 @@ describe('SpacetimeDBClient', () => { }, ], }), -<<<<<<< HEAD - timestamp: { microseconds: BigInt(1681391805281203) }, - callerIdentity: anIdentity, -======= timestamp: new Timestamp(1681391805281203n), - callerIdentity: new Identity('00ff01'), ->>>>>>> 45a6abe (Add `Timestamp` to the SDK, moving it out of `client_api`) + callerIdentity: anIdentity, callerAddress: Address.random(), reducerCall: { reducerName: 'create_player', @@ -707,7 +698,7 @@ describe('SpacetimeDBClient', () => { test('Filtering works', async () => { const wsAdapter = new WebsocketTestAdapter(); - const client = DBConnection.builder() + const client = module_bindings.DBConnection.builder() .withUri('ws://127.0.0.1:1234') .withModuleName('db') .withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter)) @@ -719,7 +710,8 @@ describe('SpacetimeDBClient', () => { identity: sallyIdentity, username: 'sally', }; - const users: Map = (db.user.tableCache as any).rows; + const users: Map = (db.user.tableCache as any) + .rows; users.set('abc123', user1); users.set('def456', user2);