diff --git a/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts b/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts index afaacdde18c..6c8ddf2c07c 100644 --- a/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts @@ -138,7 +138,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts b/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts index afaacdde18c..11f16431785 100644 --- a/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.9.0 (commit a4bb137e53d55517e0b3f031be6a7453f7ba2b1e). +// This was generated using spacetimedb cli version 1.11.0 (commit 93c0015f51af4afaf9489b92191d6e6d838af8a9). /* eslint-disable */ /* tslint:disable */ @@ -84,7 +84,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.9.0' as const, + cliVersion: '1.11.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, @@ -138,7 +138,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts b/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts index d96261a002e..3c58dc8ec21 100644 --- a/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 62b00c4e1576f6915fb872c3152d3f79df6fda7d). +// This was generated using spacetimedb cli version 1.11.0 (commit 93c0015f51af4afaf9489b92191d6e6d838af8a9). /* eslint-disable */ /* tslint:disable */ @@ -148,7 +148,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/src/lib/schema.ts b/crates/bindings-typescript/src/lib/schema.ts index 69b6da1ad01..028621e7514 100644 --- a/crates/bindings-typescript/src/lib/schema.ts +++ b/crates/bindings-typescript/src/lib/schema.ts @@ -110,32 +110,21 @@ export function tablesToSchema< // UntypedTableDef expects mutable array; idxs are readonly, spread to copy. indexes: [ ...schema.idxs.map( - (idx: Infer): IndexOpts => - ({ + (idx: Infer): IndexOpts => { + const columnIds = + idx.algorithm.tag === 'Direct' + ? [idx.algorithm.value] + : idx.algorithm.value; + const columns = columnIds.map(i => colNameList[i]); + return { name: idx.accessorName, - unique: schema.tableDef.constraints - .map(c => { - if (idx.algorithm.tag == 'BTree') { - return c.data.value.columns.every(col => { - const idxColumns = idx.algorithm.value; - if (Array.isArray(idxColumns)) { - return idxColumns.includes(col); - } else { - return col === idxColumns; - } - }); - } - }) - .includes(true), + unique: schema.tableDef.constraints.some(c => + c.data.value.columns.every(col => columnIds.includes(col)) + ), algorithm: idx.algorithm.tag.toLowerCase() as 'btree', - columns: (() => { - const cols = - idx.algorithm.tag === 'Direct' - ? [idx.algorithm.value] - : idx.algorithm.value; - return cols.map(i => colNameList[i]); - })(), - }) as IndexOpts + columns, + } as IndexOpts; + } ), ], } as const; diff --git a/crates/bindings-typescript/src/sdk/client_api/index.ts b/crates/bindings-typescript/src/sdk/client_api/index.ts index bfa84abe720..a018d9b14b7 100644 --- a/crates/bindings-typescript/src/sdk/client_api/index.ts +++ b/crates/bindings-typescript/src/sdk/client_api/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.9.0 (commit a4bb137e53d55517e0b3f031be6a7453f7ba2b1e). +// This was generated using spacetimedb cli version 1.11.0 (commit 93c0015f51af4afaf9489b92191d6e6d838af8a9). /* eslint-disable */ /* tslint:disable */ @@ -118,7 +118,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.9.0' as const, + cliVersion: '1.11.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, @@ -172,7 +172,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/test-app/src/module_bindings/index.ts b/crates/bindings-typescript/test-app/src/module_bindings/index.ts index 9bddca88456..019f94093da 100644 --- a/crates/bindings-typescript/test-app/src/module_bindings/index.ts +++ b/crates/bindings-typescript/test-app/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.9.0 (commit a4bb137e53d55517e0b3f031be6a7453f7ba2b1e). +// This was generated using spacetimedb cli version 1.11.0 (commit 93c0015f51af4afaf9489b92191d6e6d838af8a9). /* eslint-disable */ /* tslint:disable */ @@ -109,7 +109,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.9.0' as const, + cliVersion: '1.11.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, @@ -163,7 +163,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/test-react-router-app/src/module_bindings/counter_table.ts b/crates/bindings-typescript/test-react-router-app/src/module_bindings/counter_table.ts index d492e387b23..97d74912ab2 100644 --- a/crates/bindings-typescript/test-react-router-app/src/module_bindings/counter_table.ts +++ b/crates/bindings-typescript/test-react-router-app/src/module_bindings/counter_table.ts @@ -11,6 +11,6 @@ import { } from '../../../src/index'; export default __t.row({ - id: __t.u32(), + id: __t.u32().primaryKey(), count: __t.u32(), }); diff --git a/crates/bindings-typescript/test-react-router-app/src/module_bindings/index.ts b/crates/bindings-typescript/test-react-router-app/src/module_bindings/index.ts index fa3f793bdb5..5954d92c0bf 100644 --- a/crates/bindings-typescript/test-react-router-app/src/module_bindings/index.ts +++ b/crates/bindings-typescript/test-react-router-app/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using ../../../src/index cli version 1.6.0 (commit 0b0b06d5f67fecff50eb7b1c79bff5dad686f5d2). +// This was generated using spacetimedb cli version 1.11.0 (commit 93c0015f51af4afaf9489b92191d6e6d838af8a9). /* eslint-disable */ /* tslint:disable */ @@ -11,6 +11,8 @@ import { SubscriptionBuilderImpl as __SubscriptionBuilderImpl, TypeBuilder as __TypeBuilder, convertToAccessorMap as __convertToAccessorMap, + procedureSchema as __procedureSchema, + procedures as __procedures, reducerSchema as __reducerSchema, reducers as __reducers, schema as __schema, @@ -25,6 +27,7 @@ import { type ReducerEventContextInterface as __ReducerEventContextInterface, type RemoteModule as __RemoteModule, type SubscriptionEventContextInterface as __SubscriptionEventContextInterface, + type SubscriptionHandleImpl as __SubscriptionHandleImpl, } from '../../../src/index'; // Import and reexport all reducer arg types @@ -37,6 +40,8 @@ export { ClientDisconnected }; import IncrementCounter from './increment_counter_reducer'; export { IncrementCounter }; +// Import and reexport all procedure arg types + // Import and reexport all table handle types import CounterRow from './counter_table'; export { CounterRow }; @@ -51,67 +56,109 @@ export { Counter }; import User from './user_type'; export { User }; +/** The schema information for all tables in this module. This is defined the same was as the tables would have been defined in the server. */ const tablesSchema = __schema( __table( { name: 'counter', - indexes: [], + indexes: [{ name: 'id', algorithm: 'btree', columns: ['id'] }], + constraints: [ + { name: 'counter_id_key', constraint: 'unique', columns: ['id'] }, + ], }, CounterRow ), __table( { name: 'offline_user', - indexes: [], + indexes: [ + { name: 'identity', algorithm: 'btree', columns: ['identity'] }, + ], + constraints: [ + { + name: 'offline_user_identity_key', + constraint: 'unique', + columns: ['identity'], + }, + ], }, - UserRow + OfflineUserRow ), __table( { name: 'user', - indexes: [], + indexes: [ + { name: 'identity', algorithm: 'btree', columns: ['identity'] }, + ], + constraints: [ + { + name: 'user_identity_key', + constraint: 'unique', + columns: ['identity'], + }, + ], }, UserRow ) ); +/** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( __reducerSchema('clear_counter', ClearCounter), __reducerSchema('increment_counter', IncrementCounter) ); +/** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */ +const proceduresSchema = __procedures(); + +/** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.6.0' as const, + cliVersion: '1.11.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, + ...proceduresSchema, } satisfies __RemoteModule< typeof tablesSchema.schemaType, - typeof reducersSchema.reducersType + typeof reducersSchema.reducersType, + typeof proceduresSchema >; +/** The tables available in this remote SpacetimeDB module. */ export const tables = __convertToAccessorMap(tablesSchema.schemaType.tables); + +/** The reducers available in this remote SpacetimeDB module. */ export const reducers = __convertToAccessorMap( reducersSchema.reducersType.reducers ); +/** The context type returned in callbacks for all possible events. */ export type EventContext = __EventContextInterface; +/** The context type returned in callbacks for reducer events. */ export type ReducerEventContext = __ReducerEventContextInterface< typeof REMOTE_MODULE >; +/** The context type returned in callbacks for subscription events. */ export type SubscriptionEventContext = __SubscriptionEventContextInterface< typeof REMOTE_MODULE >; +/** The context type returned in callbacks for error events. */ export type ErrorContext = __ErrorContextInterface; +/** The subscription handle type to manage active subscriptions created from a {@link SubscriptionBuilder}. */ +export type SubscriptionHandle = __SubscriptionHandleImpl; +/** Builder class to configure a new subscription to the remote SpacetimeDB instance. */ export class SubscriptionBuilder extends __SubscriptionBuilderImpl< typeof REMOTE_MODULE > {} +/** Builder class to configure a new database connection to the remote SpacetimeDB instance. */ export class DbConnectionBuilder extends __DbConnectionBuilder {} +/** The typed database connection to manage connections to the remote SpacetimeDB instance. This class has type information specific to the generated module. */ export class DbConnection extends __DbConnectionImpl { + /** Creates a new {@link DbConnectionBuilder} to configure and connect to the remote SpacetimeDB instance. */ static builder = (): DbConnectionBuilder => { return new DbConnectionBuilder( REMOTE_MODULE, @@ -119,7 +166,9 @@ export class DbConnection extends __DbConnectionImpl { new DbConnection(config) ); }; - subscriptionBuilder = (): SubscriptionBuilder => { + + /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; } diff --git a/crates/bindings-typescript/test-react-router-app/src/module_bindings/offline_user_table.ts b/crates/bindings-typescript/test-react-router-app/src/module_bindings/offline_user_table.ts index 7a83afcebf0..cb2103b54f5 100644 --- a/crates/bindings-typescript/test-react-router-app/src/module_bindings/offline_user_table.ts +++ b/crates/bindings-typescript/test-react-router-app/src/module_bindings/offline_user_table.ts @@ -11,6 +11,6 @@ import { } from '../../../src/index'; export default __t.row({ - identity: __t.identity(), + identity: __t.identity().primaryKey(), hasIncrementedCount: __t.u32(), }); diff --git a/crates/bindings-typescript/test-react-router-app/src/module_bindings/user_table.ts b/crates/bindings-typescript/test-react-router-app/src/module_bindings/user_table.ts index 7a83afcebf0..cb2103b54f5 100644 --- a/crates/bindings-typescript/test-react-router-app/src/module_bindings/user_table.ts +++ b/crates/bindings-typescript/test-react-router-app/src/module_bindings/user_table.ts @@ -11,6 +11,6 @@ import { } from '../../../src/index'; export default __t.row({ - identity: __t.identity(), + identity: __t.identity().primaryKey(), hasIncrementedCount: __t.u32(), }); diff --git a/crates/codegen/src/typescript.rs b/crates/codegen/src/typescript.rs index 254506a8f98..c3686130009 100644 --- a/crates/codegen/src/typescript.rs +++ b/crates/codegen/src/typescript.rs @@ -430,7 +430,7 @@ impl Lang for TypeScript { writeln!(out); writeln!(out, "/** Creates a new {{@link SubscriptionBuilder}} to configure a subscription to the remote SpacetimeDB instance. */"); - writeln!(out, "subscriptionBuilder = (): SubscriptionBuilder => {{"); + writeln!(out, "override subscriptionBuilder = (): SubscriptionBuilder => {{"); out.indent(1); writeln!(out, "return new SubscriptionBuilder(this);"); diff --git a/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap b/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap index d10dfda0d0c..77602152edb 100644 --- a/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap +++ b/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap @@ -1,6 +1,5 @@ --- source: crates/codegen/tests/codegen.rs -assertion_line: 37 expression: outfiles --- "add_player_reducer.ts" = ''' @@ -587,7 +586,7 @@ export class DbConnection extends __DbConnectionImpl { }; /** Creates a new {@link SubscriptionBuilder} to configure a subscription to the remote SpacetimeDB instance. */ - subscriptionBuilder = (): SubscriptionBuilder => { + override subscriptionBuilder = (): SubscriptionBuilder => { return new SubscriptionBuilder(this); }; }