Fix keynote-2 module (#4412)

# Description of Changes

Updates to v2 bindings

# Expected complexity level and risk

1

# Testing

- [x] Compiles
This commit is contained in:
Noa
2026-02-23 17:30:03 -06:00
committed by GitHub
parent 55c1b815d4
commit 28ca85566a
13 changed files with 160 additions and 40 deletions
+13 -17
View File
@@ -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.3 (commit 02449737ca3b29e7e39679fccbef541a50f32094).
// This was generated using spacetimedb cli version 2.0.0 (commit 044efda9054d37b62625b8a9424e12a77f8bcd55).
/* eslint-disable */
/* tslint:disable */
@@ -12,6 +12,7 @@ import {
TypeBuilder as __TypeBuilder,
Uuid as __Uuid,
convertToAccessorMap as __convertToAccessorMap,
makeQueryBuilder as __makeQueryBuilder,
procedureSchema as __procedureSchema,
procedures as __procedures,
reducerSchema as __reducerSchema,
@@ -25,33 +26,28 @@ import {
type Event as __Event,
type EventContextInterface as __EventContextInterface,
type Infer as __Infer,
type QueryBuilder as __QueryBuilder,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type RemoteModule as __RemoteModule,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
type SubscriptionHandleImpl as __SubscriptionHandleImpl,
} from "spacetimedb";
// Import and reexport all reducer arg types
// Import all reducer arg schemas
import CreateAccountReducer from "./create_account_reducer";
export { CreateAccountReducer };
import SeedReducer from "./seed_reducer";
export { SeedReducer };
import TransferReducer from "./transfer_reducer";
export { TransferReducer };
// Import and reexport all procedure arg types
// Import all procedure arg schemas
// Import and reexport all table handle types
// Import all table schema definitions
import AccountsRow from "./accounts_table";
export { AccountsRow };
// Import and reexport all types
import Accounts from "./accounts_type";
export { Accounts };
/** Type-only namespace exports for generated type groups. */
/** 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({
const tablesSchema = __schema({
accounts: __table({
name: 'accounts',
indexes: [
{ name: 'id', algorithm: 'btree', columns: [
@@ -62,7 +58,7 @@ const tablesSchema = __schema(
{ name: 'accounts_id_key', constraint: 'unique', columns: ['id'] },
],
}, AccountsRow),
);
});
/** 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(
@@ -78,7 +74,7 @@ const proceduresSchema = __procedures(
/** The remote SpacetimeDB module schema, both runtime and type information. */
const REMOTE_MODULE = {
versionInfo: {
cliVersion: "1.11.3" as const,
cliVersion: "2.0.0" as const,
},
tables: tablesSchema.schemaType.tables,
reducers: reducersSchema.reducersType.reducers,
@@ -89,8 +85,8 @@ const REMOTE_MODULE = {
typeof proceduresSchema
>;
/** The tables available in this remote SpacetimeDB module. */
export const tables = __convertToAccessorMap(tablesSchema.schemaType.tables);
/** The tables available in this remote SpacetimeDB module. Each table reference doubles as a query builder. */
export const tables: __QueryBuilder<typeof tablesSchema.schemaType> = __makeQueryBuilder(tablesSchema.schemaType);
/** The reducers available in this remote SpacetimeDB module. */
export const reducers = __convertToAccessorMap(reducersSchema.reducersType.reducers);
@@ -10,9 +10,9 @@ import {
type Infer as __Infer,
} from "spacetimedb";
export default __t.object("Accounts", {
export const Accounts = __t.object("Accounts", {
id: __t.u32(),
balance: __t.i64(),
});
export type Accounts = __Infer<typeof Accounts>;
+10
View File
@@ -0,0 +1,10 @@
// 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 */
import { type Infer as __Infer } from "spacetimedb";
// Import all procedure arg schemas
+16
View File
@@ -0,0 +1,16 @@
// 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 */
import { type Infer as __Infer } from "spacetimedb";
// Import all reducer arg schemas
import CreateAccountReducer from "../create_account_reducer";
import SeedReducer from "../seed_reducer";
import TransferReducer from "../transfer_reducer";
export type CreateAccountParams = __Infer<typeof CreateAccountReducer>;
export type SeedParams = __Infer<typeof SeedReducer>;
export type TransferParams = __Infer<typeof TransferReducer>;
+1 -1
View File
@@ -36,7 +36,7 @@
"drizzle-orm": "^0.44.7",
"express": "^5.1.0",
"hdr-histogram-js": "^3.0.1",
"spacetimedb": "1.11.4",
"spacetimedb": "^2.0",
"sql.js": "^1.13.0",
"undici": "^6.19.2"
}
@@ -0,0 +1,18 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Spacetime ignore
/.spacetime
spacetime.local.json
@@ -9,5 +9,5 @@ edition = "2021"
crate-type = ["cdylib"]
[dependencies]
spacetimedb = "=1.9.0"
spacetimedb = { path = "../../../crates/bindings" }
log = "0.4"
@@ -1,7 +1,7 @@
use log::info;
use spacetimedb::{reducer, ReducerContext, Table};
#[spacetimedb::table(name = accounts, public)]
#[spacetimedb::table(accessor = accounts, public)]
#[derive(Debug, Clone)]
pub struct Accounts {
#[primary_key]
+3 -18
View File
@@ -1,18 +1,3 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Spacetime ignore
/.spacetime
spacetime.local.json
node_modules/
dist/
.cursor/
@@ -0,0 +1,18 @@
{
"name": "spacetime-module",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "spacetime build",
"publish": "spacetime publish"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"spacetimedb": "workspace:*"
},
"devDependencies": {
"typescript": "^5.9.3"
}
}
@@ -0,0 +1,53 @@
import { schema, table, t, SenderError } from 'spacetimedb/server';
const spacetimedb = schema({
account: table(
{ name: 'account' },
{
id: t.u32().primaryKey().index('hash'),
balance: t.i64(),
},
),
});
export default spacetimedb;
export const seed = spacetimedb.reducer(
{ n: t.u32(), balance: t.i64() },
(ctx, { n, balance }) => {
const accounts = ctx.db.account;
for (const row of accounts) {
accounts.delete(row);
}
for (let id = 0; id < n; id++) {
accounts.insert({ id, balance });
}
},
);
export const transfer = spacetimedb.reducer(
{ from: t.u32(), to: t.u32(), amount: t.u32() },
(ctx, { from, to, amount: amt }) => {
const accounts = ctx.db.account;
const byId = accounts.id;
const fromRow = byId.find(from)!;
const toRow = byId.find(to)!;
const amount = BigInt(amt);
if (fromRow.balance < amount) {
throw new SenderError('insufficient_funds');
}
byId.update({
id: from,
balance: fromRow.balance - amount,
});
byId.update({
id: to,
balance: toRow.balance + amount,
});
},
);
@@ -0,0 +1,24 @@
/*
* This tsconfig is used for TypeScript projects created with `spacetimedb init
* --lang typescript`. You can modify it as needed for your project, although
* some options are required by SpacetimeDB.
*/
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"moduleResolution": "bundler",
"jsx": "react-jsx",
/* The following options are required by SpacetimeDB
* and should not be modified
*/
"target": "ESNext",
"lib": ["ES2021", "dom"],
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*"]
}