Commit Graph

165 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 492e591845 Add WASM point scan ABIs & use them in Rust bindings (#3863)
# Description of Changes

Provides new WASM ABIs:

- `datastore_index_scan_point_bsatn`
- `datastore_delete_by_index_scan_point_bsatn`

These are then used where applicable to speed up `.find(_)` and friends.

Point scans are also used more internally where applicable.

What remains after this is use in C# module bindings and to expose this
in TS as well.

The PR makes TPS go from roughly 36k to 38k TPS on my machine and also
makes a difference in flamegraphs where the time spent in some index
scans are substantially decreased.

# API and ABI breaking changes

None

# Expected complexity level and risk

3? This touches the datastore an how we expose it to modules.

# Testing

Some existing tests now exercise the new ABIs by changing what
`.find(_)` and friends do.

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-12-12 22:07:54 +00:00
Mario Montoya cdf8391ff3 Add rng support to ProcedureContext on Rust (#3865)
# Description of Changes

As the title says, required for
https://github.com/clockworklabs/SpacetimeDB/pull/3538.

# Expected complexity level and risk

1

# Testing

Will be done on the `uuid` pr.

---------

Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-12-10 19:05:21 +00:00
Shubham Mishra 6c0b66ad6e filter alias for rust query builder's where method (#3856)
# Description of Changes
As title.


# API and ABI breaking changes
incremental binding.

# Expected complexity level and risk

# Testing
Unit and smoketest
2025-12-10 13:19:32 +00:00
Shubham Mishra d6eff1befe lte and gte operators to rust query builder (#3855)
# Description of Changes
Fixes #3827 

Adding lte and gte support for query_builder in rust.


# API and ABI breaking changes
Incremental change to bindings.

# Expected complexity level and risk
1


# Testing
unit test and smoketest
2025-12-10 12:24:34 +00:00
Shubham Mishra 5100aec3d4 Some more UI tests for Views (#3829)
# Description of Changes
As title

# API and ABI breaking changes
NA

# Expected complexity level and risk
0

---------

Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-12-08 19:33:02 +00:00
Noa afe169ac4a Fix the issues with scheduling procedures (#3816)
# Description of Changes

This reapplies the patch from #3704, and fixes the issues that were
causing it to deadlock.

The reason it was deadlocking was that it allowed for the following
sequence of events:
* `SchedulerActor::handle_queued()` begins mutable tx
* `ModuleHost::disconnect_client()` submits call to `call_reducer(tx:
None)`
* scheduler submits call to `call_reducer(tx: Some)`
* `WasmModuleInstance::disconnect_client` now has to try to take tx
lock, but the scheduler's call_reducer already holds it and is behind it
in the queue

So, I moved most of the logic from `handle_queued` back to being
executed in the module worker thread, but kept the code in
`scheduler.rs` so that it can all be reasoned about locally.

Fixes #3645. Should I uncomment the implementation of
`ExportFunctionForScheduledTable for F: Procedure` now?

# Expected complexity level and risk

2 - there's a chance that this patch hasn't fully fixed the deadlock
issue from #3704, but I'm quite confident.

# Testing

- [x] Manually verified that deadlock no longer occurs - previously,
`while true; do python -m smoketests schedule_reducer -k
test_scheduled_table_subscription; done` would freeze up in only 2 or 3
iterations, but now it can run for 10 minutes without issues.
2025-12-05 22:27:30 +00:00
Shubham Mishra c99a6131c8 [Rust] Query builder Integration. (#3823)
# Description of Changes
Patch contain few different things, required to run query builder end to
end.
Git history seems messed up but it can be reviewed commitwise from -
69c1907b3e.

1. Decouples generic type `T` from table name, as type represents the
`struct` and not table, and there couple be multiple tables implemented
from same struct.
2. modify table macro implementaiton to generate code supporting
`traits` and types required for query builder,
3. Disable aliasing in sql queries for now, as it was causing
semantically wrong query when we were doing joins on `FromWhere` (as
original `Expr` were referencing to original table names).
4. smoketests.


# API and ABI breaking changes
Add `Query<T>` type as Views return type.


# Expected complexity level and risk
2, changes are simple but not splitted up well.

# Testing
1. Added smoketest.

TODO:
ui test.

---------

Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-12-04 17:45:29 +00:00
joshua-spacetime 60048ecbdf [Rust] update module bindings to use new view abi (#3819)
# Description of Changes

Updates the rust module bindings to use new view abi
(`ViewResultHeader`) and updates the return codes for the
`__call_view__` and `__call_view_anon__` module exports. This is in
preparation for `Query` builder support.

# API and ABI breaking changes

Not breaking. Existing modules will continue to use the old abi. New
modules will use the new abi. However previous host versions will not
support modules built using this version of the bindings.

# Expected complexity level and risk

2

# Testing

This is an internal refactor. All existing tests should continue to
pass. The only tests that needed updating were the negative module
compilation tests because the error messages produced by rustc changed.
2025-12-04 08:28:41 +00:00
Shubham Mishra 51ec052509 [Rust] Module-side query builder types (#3797)
# Description of Changes

Implements a query builder for rust modules according to the
[spec](https://github.com/clockworklabs/SpacetimeDBPrivate/blob/master/proposals/0030-views.md#5-query-builder-for-incremental-evaluation).

Look at the tests in `query_builder.rs`.

TODO: Extend return type for views to include `Query` and update the
`#[table]` macro to generate query builder bindings.

# API and ABI breaking changes

This is an additive change. Current modules do not need to be updated
unless they wish to use the query builder.

# Expected complexity level and risk

1.5, Will appreciate comments to better structure code.

# Testing 

[x]: unit tests.

I have also done type safety checks manually from module.

---------

Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-12-04 06:53:26 +00:00
Tamaro Skaljic 87bc15c0b4 Implement DbContext for AnonymousViewContext and ViewContext (#3787)
# Description of Changes

The trait has already been implemented for ReducerContext and TxContext,
but implementation for AnonymousViewContext and ViewContext is still
missing.

## Background why I need this change

In SpacetimeDSL, I currently have the ReducerContext hard-coded as a
prerequisite for creating a DSL instance (see
https://github.com/tamaro-skaljic/SpacetimeDSL/blob/main/src/lib.rs#L9-L33)
.

With the addition of

- ViewContext,
- AnonymousViewContext,
- ProcedureContext, and
- TxContext,

I am now faced with the dilemma that I also have to support SpacetimeDSL
with the other contexts.

I hope to be able to use `spacetimedb::DbContext<DbView =
spacetimedb::Local>` and `spacetimedb::DbContext<DbView =
spacetimedb::LocalReadOnly>` as a common denominator.

(I signed the CLA)

# API and ABI breaking changes

No

# Expected complexity level and risk

1

Signed-off-by: Tamaro Skaljic <49238587+tamaro-skaljic@users.noreply.github.com>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-12-02 07:07:37 +00:00
Phoebe Goldman ae9bd74eca Disable scheduling procedures (#3768)
# Description of Changes

We've been unable to get scheduled procedures into the initial release
of procedures due to a nondeterministic hang in some of our tests which
we don't have time to debug. As such, this commit disables scheduled
procedures by:

- Changing the `RawModuleDevV9` validator to reject scheduled
procedures.
- Changing the Rust bindings library's typechecking magic so that
scheduled table annotations referencing procedures will cause a type
error.
- Removes some docs from the Rust bindings library which reference
scheduled procedures.

# API and ABI breaking changes

N/a

# Expected complexity level and risk

1

# Testing

Automated tests should be sufficient.

Prior to merging #3774 , CI for this branch merged with master failed in
the intended way: modules which attempted to define scheduled procedures
failed to typecheck.
2025-11-26 18:40:25 +00:00
Noa de142d4af9 HTTP followup: remove http dep from spacetimedb_lib (#3719)
# Description of Changes

Follow up to #3684. Moves `Error` and `Timeout` out of lib, so that we
don't have to implement `SpacetimeType` for them, and then removes the
http dependency altogether, so that `lib` can be leaner. I also got rid
of the separate `HttpValue` type, since it only really exists to mirror
the `http` crate and typescript won't make use of it.

# Expected complexity level and risk

1

# Testing

n/a - just code movement.
2025-11-21 06:01:21 +00:00
Phoebe Goldman 7df8719b61 Add procedure HTTP request API for WASM modules and the Rust module bindings library (#3684)
# Description of Changes

Closes #3517 .

With this PR, procedures (at least, those defined in Rust modules) can
perform HTTP requests! This is performed through a new field on the
`ProcedureContext`, `http: HttpClient`, which has a method `send` for
sending an `http::Request`, as well as a convenience wrapper `get`.

Internally, these methods hit the `procedure_http_request` ABI call /
host function, which uses reqwest to perform an HTTP request. The
request is run with a user-configurable timeout which defaults and is
clamped to 500 ms.
Rather than exposing the HTTP stream to modules, we download the entire
response body immediately, within the same timeout.

I've added an example usage of `get` to `module-test` which performs a
request against `localhost:3000` to read its own schema/moduledef.

This PR also makes all procedure-related definitions in the Rust module
bindings library `#[cfg(feature = "unstable")]`, as per #3644 . The
rename of the `/v1/database/:name/procedure/:name` route is not included
in this PR, so this does not close #3644 .

Left as TODOs are:
- Metrics for recording request and response size.
- Improving performance by stashing a long-lived `reqwest::Client`
someplace.
  Currently we build a new `Client` for each request.
- Improving performance (possibly) by passing the request-future to the
global tokio executor
  rather than running it on the single-threaded database executor.

# API and ABI breaking changes

Adds new APIs, which are marked as unstable. Adds a new ABI, which is
not unstable in any meaningful way (we can't really do that). Marks
unreleased APIs as unstable. Does not affect any pre-existing
already-released APIs or ABIs.

# Expected complexity level and risk

3 or so: networking is scary, and even though we impose a timeout which
prevents these connections from being truly long-lived, they're still
potentially long-lived on the scale of Tokio futures. It's possible that
running them on the database core is problematic in some way, and so
what I've left as a performance TODO could actually be a
concurrency-correctness issue.

# Testing

- [x] Manually wrote and executed some procedures which make HTTP
requests.
- [x] Added two automated tests to the `sdk-test` suite,
`procedure::http_ok` and `procedure::http_err`, which make successful
and failing requests respectively, then return its result. A client then
makes some assertions about the result.

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2025-11-20 20:47:35 +00:00
Mazdak Farrokhzad 0a3251708a Add ProcedureContext::with_tx (#3638)
# Description of Changes

Adds `ProcedureContext::{with_tx, try_with_tx}`.

Fixes https://github.com/clockworklabs/SpacetimeDB/issues/3515.

# API and ABI breaking changes

None

# Expected complexity level and risk

2

# Testing

An integration test `test_calling_with_tx` is added.
2025-11-19 20:33:02 +00:00
Tyler Cloutier 9e3ffeb932 Adds flag to publish to allow clearing on migration conflict. (#3601)
# Description of Changes

This PR modifies the `--delete-data` flag on `spacetime publish` and
adds the `--delete-data` flag on `spacetime dev`.

In particular instead of `--delete-data` being a boolean, it is now a an
enum:

- `always` -> corresponds to the old value of `true`
- `never` -> corresponds to the old value of `false`
- `on-conflict` -> clears the database, but only if publishing would
have required a manual migration

This flag does NOT change any behavior about prompting users to confirm
if they want to delete the data. Users will still be prompted to confirm
UNLESS they pass the separate `--yes` flag.

`spacetime dev` gets the same `--delete-data` flag. The default value of
`never` is equivalent to the existing behavior. `spacetime dev`
continues to publish with `--yes` just as before. This behavior is
unchanged.

# API and ABI breaking changes

Adds the flags specified above. This is NOT a breaking change to the
CLI. Passing `--delete-data` is the equivalent of
`--delete-data=always`.

This IS technically a breaking change to the `pre_publish` route. As far
as I'm aware this is *only* used by our CLI however.

> IMPORTANT SIDE NOTE: I would argue that `--break-clients` should
really be renamed to `--yes-break-clients` because it actually behaves
like the `--yes` force flag, but only for a subset of the user prompts.
I have not made this change because it would be a breaking change, but
if the reviewers agree, I will make this change.

# Expected complexity level and risk

2, Very small change, but if we get it wrong users could accidentally
lose data. I would ask reviewers to think about ways that users might
accidentally pass `--delete-data --yes`.

# Testing

- [ ] I have not yet tested manually.

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2025-11-19 17:38:49 +00:00
joshua-spacetime fad2ab3325 Reference docs for views (#3641)
# Description of Changes

Includes Rust, C#, and TypeScript.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

Just docs.
2025-11-11 22:34:59 +00:00
joshua-spacetime 6401818fe5 Disable parameterized views in rust (#3629)
# Description of Changes

Disables parameterized views in rust until we can pass arguments from
sql. Note parameters are already disabled in C# and typescript.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

Needed to update some tests. Will revert these changes once we re-enable
parameters.
2025-11-10 22:51:29 +00:00
Shubham Mishra 8307d7c576 fix: view index (#3596)
# Description of Changes

`call_view` and `call_view_anon` maintains separate `Vec` list for view
inside Module but `ModuleDef` used to have single `Vec`. Hence, Views
index is not same across `ModuleDef` and module itself.

Added a `index` field inside `ViewDef` which stores it index inside
module.

# API and ABI breaking changes
NA

How complicated do you think these changes are? Grade on a scale from 1
to 5,
2, 

there could be some existing code relying on poistion in `Vec` and may
not appear as compiler error


# Testing

Future smoketests should cover this.
2025-11-07 09:54:53 +00:00
Jeffrey Dallatezza 9586136db7 Treat a missing aud claim as an empty list (#3542)
# Description of Changes

The `aud` claim is required in the OIDC spec, but the server currently
allows it to be missing, and the spacetime auth tokens we use for the
website don't have an audience.

Previously the module bindings would throw an error if there were no
`aud` claim in a jwt payload (if someone used the `audience` within a
reducer), but this change makes us treat a missing audience as an empty
list.

This also renames the `authCtx` fields to `senderAuth` in the typescript
and csharp module APIs, so they match rust.

# API and ABI breaking changes

This doesn't break any ABIs.

This changes the ReducerContext APIs in typescript and rust, but only by
renaming a field that hasn't been released yet.

# Expected complexity level and risk

1.

# Testing

I've tested accessing the `audience` within a reducer for a token
missing an `aud` claim in Typescript and Rust.
2025-10-31 00:48:40 +00:00
Phoebe Goldman 3f1de9e096 WASM host execution for procedures (#3498)
# Description of Changes

This commit builds support for executing procedures in WASM modules.
This includes an HTTP endpoint,
`/v1/database/:name_or_address/procedure/:name POST`, as well as an
extension to the WS protocol. These new APIs are not wired up to the CLI
or SDKs, but I have manually tested the HTTP endpoint via `curl`. The
new WS extensions are completely untested.

Several TODOs are scattered throughout the new code, most notably for
sensibly tracking procedure execution time in the metrics.

I also expect that we will want to remove the `procedure_sleep_until`
syscall and the `ProcedureContext::sleep_until` method prior to release.

# API and ABI breaking changes

Adds new APIs and ABIs.

# Expected complexity level and risk

3? 4? Unlikely to break existing stuff, 'cause it's mostly additive, but
adds plenty of potentially-fragile new stuff. Notably is the first time
we're doing anything actually `async`hronous on a database core Tokio
worker, and we don't yet have strong evidence of how that will affect
reducer execution.

# Testing

- [x] Manually published `modules/module-test` and executed procedures
with the following `curl` invocations:
- `curl -X POST -H "Content-Type:application/json" -d '[]'
http://localhost:3000/v1/database/module-test/procedure/sleep_one_second`
- `curl -X POST -H "Content-Type:application/json" -d '[1223]'
http://localhost:3000/v1/database/module-test/procedure/return_value`
- [ ] Need to write automated tests.

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-10-30 13:17:45 +00:00
Piotr Sarnacki 647be7e9c0 spacetime init rewrite (#3366)
This is a draft of the new functionality for `spacetime init`. In order
to run it with built-in templates you have to set the path to the config
file:

```
export SPACETIMEDB_CLI_TEMPLATES_FILE=crates/cli/.init-templates.json
```

In the future it will fetch the list from GH.

A few notes:

* the previous functionality of `spacetime init` does not work at the
moment
* the code needs a bit more cleanup and tests before merging
* there is a bit of a mix in how we generate empty server and client
projects. For Rust we use the existing way of generating. For TypeScript
we clone an empty project from the repo. I wanted to play with both ways
of doing things, and I'm still not sure which is better. Generation in
Rust means that the generated code will match the CLI version and not
necessarily whatever is in Git. On the other hand, for the builtin
templates we will be fetching the newest version from GH, which I guess
might also not what we want, ie. we probably want only stable templates.
More discussion is needed here
* we use `spacetimedb` directory for the server files
* I don't particularly like the inability to disable interactive mode
easily. We discussed disabling it by default if all of the required
arguments are passed, but I don't think it's feature proof. For example,
if someone relies on a non-interactive mode, and we add a new required
argument, instead of printing a message `missing --foo`, we will
automatically launch interactive mode, which is harder to debug. That's
why I think I'd prefer to implement `--non-interactive` argument
* it's kind of hard to keep the legacy behaviour. If you don't pass any
arguments, we go into interactive mode. In the legacy version, we would
print required arguments. If someone passes `--lang` or `--project-path`
explicitly, I guess we could run the legacy workflow, but not sure if
it's worth it, as the command was marked as unstable anyway
* the project path defaults to the project name, but I think we should
probably replace change whitespaces to dashes, or at least ask for the
project path with the project name being the default (or both)

---------

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
Co-authored-by: = <cloutiertyler@gmail.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2025-10-30 04:26:08 +00:00
Mazdak Farrokhzad c58a7d19c5 Improve JwtClaims & AuthCtx docs (#3477)
# Description of Changes

Adds a bit more docs to `JwtClaims` and `AuthCtx`.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

Just adds docs.
2025-10-28 16:09:35 +00:00
joshua-spacetime 8f11ac81e3 Make name a required parameter of view macro (#3480)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Makes `name` a required parameter of the `#[view]` macro. This is to be
consistent with the `#[table]` macro since views should expose the same
interface as tables.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Added new compile tests
- [x] Updated existing compile tests
2025-10-24 20:43:33 +00:00
Phoebe Goldman dcd8640543 Rust module bindings and macros for defining procedures (#3444)
# Description of Changes

This commit adds a macro attribute `#[procedure]` which applies to
functions, and various in-WASM machinery for defining, calling and
running procedures.

A simple example of a procedure, included in `modules/module-test`:

```rust
fn sleep_one_second(ctx: &mut ProcedureContext) {
    let prev_time = ctx.timestamp;
    let target = prev_time + Duration::from_secs(1);
    ctx.sleep_until(target);
    let new_time = ctx.timestamp;
    let actual_delta = new_time.duration_since(prev_time).unwrap();
    log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
}
```

We intend eventually to make procedures be `async` functions (with the
trivial `now_or_never` executor from `future-util`), but I found that
making the types work for this was giving me a lot of trouble, and
decided to put it off in the interest of unblocking more parallelizable
work.

Host-side infrastructure for executing procedures is not included in
this commit. I have a prototype working, but cleaning it up for review
and merge will come a bit later.

One item of complexity in this PR is enabling scheduled tables to
specify either reducers or procedures, while still providing
compile-time diagnostics for ill-typed scheduled functions (as opposed
to publish-time). I had to rewrite the previous
`schedule_reducer_typecheck` into a more complex `schedule_typecheck`
with a trait `ExportFunctionForScheduledTable`, which takes a "tacit
trait parameter" encoding reducer-ness or procedure-ness, as described
in https://willcrichton.net/notes/defeating-coherence-rust/ .

The trait name `ExportFunctionForScheduledTable` is user-facing in the
sense that it will appear in compiler diagnostics in ill-typed modules.
As such, I am open to bikeshedding.

# API and ABI breaking changes

Adds a new user-facing API, which we intend to change before releasing.

# Expected complexity level and risk

2? Mostly pretty mechanical changes to macros and bindings.

# Testing

- [x] Added a procedure definition to `module-test`, saw that it
typechecks.
- [x] Executed same procedure definition using #3390 , the prototype
implementation this PR draws from.
2025-10-24 14:35:32 +00:00
joshua-spacetime f8631cc749 Remove connection_id from ViewContext (#3464)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Removing `connection_id` from `ViewContext` for performance reasons. We
intend to wait to hear from clients before assuming that it's necessary
to include.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None (unreleased feature)

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

0

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

n/a
2025-10-23 18:43:35 +00:00
joshua-spacetime 0d325b2dcc Add macro bindings for views (#3429)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Adds the `#[view]` procedural macro and module describers for views.
```rust
#[view(public)]
fn player(ctx: &ViewContext) -> Vec<Player> {
    ctx.db.player().identity().find(ctx.sender).into_iter().collect()
}

#[view(public)]
fn player(ctx: &AnonymousViewContext, level: u32) -> Vec<Player> {
    ctx.db.player().level().filter(level).collect()
}
```

Note, this deviates from the proposal in that views may only return
`Vec<T>` or `Option<T>`. They can't return an arbitrary `SpacetimeType`.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

This technically isn't a breaking change, but it's worth mentioning that
this patch refactors `ReducerInfo` so that we can use it for views as
well.

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

2

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Negative compile tests
- [x] Negative publish (module validation) tests
- [x] Test system tables are updated accurately
2025-10-22 20:23:48 +00:00
Jeffrey Dallatezza bf37b2947b Add bindings for csharp modules to use JWT claims (#3414)
# Description of Changes

This exposes JWT claims for csharp modules, similar to how they are
exposed to rust modules in
https://github.com/clockworklabs/SpacetimeDB/pull/3288.

This adds the new types `AuthCtx` and `JwtClaims`, and adds an `AuthCtx`
to the `ReducerContext`.

`AuthCtx` represents the credentials associated with the request, and
`JwtClaims` represents a jwt token.

One difference from the rust version is that I didn't create helpers to
build an `AuthCtx` from a jwt payload. The reason is that we would need
to be able to compute the identity from the payload claims, which
requires a blake3 hash implementation. The first two c# libraries I
found had issues at runtime
([Blake3](https://www.nuget.org/packages/Blake3) is wrapping a rust
implementation, and
[HashifyNet](https://github.com/Deskasoft/HashifyNET/tree/main/HashifyNet/Algorithms/Blake3)
seems to be broken by our trimming because it uses reflection heavily).
I can look into taking the implementation from `HashifyNet`, since it is
MIT licensed, but I don't think we need to block merging on that.

# API and ABI breaking changes

This adds the new types `AuthCtx` and `JwtClaims`, and adds an `AuthCtx`
to the `ReducerContext`.

This also adds a csharp wrapper for the get_jwt ABI function added in
https://github.com/clockworklabs/SpacetimeDB/pull/3288.

# Expected complexity level and risk

2.

# Testing

This has a very minimal unit test of JwtClaims.

I manually tested using this locally with the csharp quickstart, and I
was able to print jwt tokens inside the module.
2025-10-21 19:17:33 +00:00
joshua-spacetime c724a4e35d add rust-src to the toolchain and update trybuild test output (#3440)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Adds `rust-src` to the toolchain and updates the expected output of the
`trybuild` tests.

`rust-src` places the entire source code of the rust stdlib under the
local toolchain directory. `rust-analyzer` uses it for "go to
definition" (among other things) in the stdlib. When included in the
toolchain, rustc can provide code frames that it can't otherwise.

The reason for its addition is that if anyone includes it in their local
toolchain, the error messages produced by rustc when running the `ui`
tests will be slightly different (have some more information) than when
run in CI. Hence those tests will fail locally but not in CI. Rather
than removing `rust-src` locally so that the tests will pass, I've opted
to just add it to the toolchain so that everyone runs with it by
default, including in CI.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

0

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Updated rustc tests
2025-10-21 02:03:07 +00:00
Jeffrey Dallatezza dbc49b1fd6 Add AuthCtx to ReducerContext for rust (#3288)
# Description of Changes

This exposes client credentials in reducer calls for rust.

# API and ABI breaking changes

API Changes:

The main API change is the addition of `AuthCtx` and the `sender_auth`
in `ReducerContext`. This also adds JwtClaims, which has some helpers
for getting commonly used claims.

ABI Changes:

This adds one new functions `get_jwt`. This uses
`st_connection_credentials` to look up the credentials associated with a
connection id.

This adds ABI version 10.2.

# Expected complexity level and risk

2. This adds new ABI functions

# Testing

I've done some manual testing with modified versions of the quickstart.
We should add some examples that use the new API.
2025-10-17 21:03:54 +00:00
Phoebe Goldman 0a6aa7c5d9 ModuleDef and schema changes to support procedures (#3392)
# Description of Changes

This commit extends various schema and schema-adjacent structures to
describe procedures, a new kind of database function which are allowed
to perform side effects.

This includes extending `RawModuleDefV9` with a way to register
`RawProcedureDefV9`s in the `misc_exports`, preserving compatibility
with modules that predate procedures.

The module validation path is reorganized somewhat to validate various
properties related to procedures while preserving code clarity and
maintainability.

Additionally, the `ArgsTuple` machinery for ser/de-ing reducer arguments
using the argument type as a seed is extended to also support procedure
arguments.

All of this is currently unused.

# API and ABI breaking changes

Additive and backwards-compatible additions to `RawModuleDefV9` and
friends.

# Expected complexity level and risk

2 - some minor complexity in schema validation which may have gotten
borked in a merge at some point.

# Testing

Unsure what tests would be useful, open to suggestions from reviewers.

- [ ] <!-- maybe a test you want to do -->
- [ ] <!-- maybe a test you want a reviewer to do, so they can check it
off when they're satisfied. -->
2025-10-17 17:22:14 +00:00
Noa 207e559859 Noa/ts module host changes (#3388)
# Description of Changes

Host-side changes extracted from #3327 

I added AUTO_INC_OVERFLOW even though we don't currently ever return it,
in order to future-proof so it's already there when we start emitting
it.

Prepublish was failing because it was expecting a wasm module
unconditionally, so now it takes ?host_type.

I tweaked JS deser to accept null/undefined when the unit type or an
option type is expected.

I switched to bsatn, because the native sats->js translator wasn't
matching what js was expecting.

I renamed the sys module: my thinking is that `spacetime:` as a scheme
will help disambiguate it, and maybe it could also be used for IMC in
the future or something? And I believe we had discussed wanting this to
be versioned, similar to wasm imports.

Trying to get a borrowed str from deserialize_js doesn't work, because
v8 strings don't store utf8.

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] All this was done in the course of getting an actual typescript
module to successfully publish.
2025-10-10 18:25:26 +00:00
Noa 619b8ce021 Bump Rust to 1.90 (#3397)
# Description of Changes

Necessary for pulling in rolldown.

# API and ABI breaking changes

None

# Expected complexity level and risk

1, with the caveat that this updates the Rust version and therefore
touches all the code.

# Testing

- [ ] Just the automated testing
2025-10-09 20:41:25 +00:00
joshua-spacetime 9f59118e24 Generate read-only table handles for #[table] (#3364)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

The `#[table]` macro now generates read-only table and index handles.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] positive and negative test cases using
`ReducerContext::as_read_only()`
2025-10-07 19:26:42 +00:00
Phoebe Goldman 351af50578 Support BytesSources other than the one for reducer args (#3294)
# Description of Changes

Each reducer gets its arguments through an `ArgSource`, a Unix-file-like
abstraction for streams of bytes. Prior to this commit, we had an ABI
designed as if it could support other args sources, but it actually
hardcoded the ID of the reducer args source, and errored elsewhere.

This commit extends the `BytesSource` infrastructure to support other
bytes sources. This will be useful for exposing JWT payloads and HTTP
responses. No other `BytesSource` uses are actually included in this
commit, only the infrastructure.

This commit also defines a new host call,
`bytes_source_remaining_length`. This is intended to allow callers to
pre-allocate a buffer correctly sized to read the entire `BytesSource`
all at once. The new host function is added to a new ABI minor version,
10.1, so that old SpacetimeDB hosts can detect and reject too-new
compiled modules. I have added uses of this new function to
`__call_reducer__` in both Rust and C#, even though it's not strictly
necessary,
and I haven't removed the loop which repeatedly calls
`bytes_source_read` and grows the buffer.

# API and ABI breaking changes

Adds a new ABI minor version, `spacetime_10.1`. This means that old
SpacetimeDB hosts will reject new compiled modules.

# Expected complexity level and risk

2-ish? WASM ABI code is always fiddly, but this is a pretty simple case.

# Testing

- [x] New behavior and new host function are both hit through existing
tests that instantiate modules and call reducers against them, so I
believe automated testing is sufficient.

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-09-29 15:32:58 -04:00
Mazdak Farrokhzad 2743d0bae3 SATS: impl ser/de for tuples (#3292)
# Description of Changes

Implements `Serialize` and `Deserialize` for tuples.
Extracted from https://github.com/clockworklabs/SpacetimeDB/pull/3276.

# API and ABI breaking changes

None

# Expected complexity level and risk

2

# Testing

A test `roundtrip_tuples_in_different_data_formats` is added.
2025-09-25 15:30:10 +00:00
Shubham Mishra cfb185a235 rust: default macro (#3177)
# Description of Changes
PR introduces support for column-level default values via a new
`#[default(...)]` attribute.

It also validates, `default` macro is not used along with `primary_key`,
`unique` or `auto_inc`.

# API and ABI breaking changes

NA

# Expected complexity level and risk
2

# Testing
Start using macro in `module-test`.

---------

Co-authored-by: James Gilles <jameshgilles@gmail.com>
2025-09-16 08:39:52 +00:00
james gilles f274414b26 Enable adding columns in auto migrations in schema crate (#2956)
# Description of Changes

This adds auto migration support to the `schema` crate.
Additional changes are needed to fully implement this feature: see
https://github.com/clockworklabs/SpacetimeDB/issues/2912

# API and ABI breaking changes

None

# Expected complexity level and risk

1, at this level the change is fairly straightforward. The integration
will be more difficult.

# Testing

Added `schema` unit tests for success/failure cases.

---------

Co-authored-by: Shubham Mishra <shivam828787@gmail.com>
2025-08-20 07:32:53 +00:00
Zeke Foppa f6f0909ea4 Update all licenses (#3002)
# Description of Changes

We recently merged several repos together. This PR clarifies the license
terms for several subdirectories, as well as the relationship between
the licenses.

The licenses in our subdirectories have become symbolic links to
licenses in our toplevel `licenses` directory. For any particular
subdirectory's license file in the diff, you can click `... -> View
file` and then click on the text that says "Symbolic Link" on that page.
This will take you to the license file that it links to.

I have also updated the `tools/upgrade-version` script to update the
change date in the new `licenses/BSL.txt` file.

# API and ABI breaking changes

None.

# Expected complexity level and risk

1

# Testing

None. Only changes to license files.

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2025-08-12 18:20:58 +00:00
Noa 742303ca49 Bump rust-toolchain to rust 1.88 (#2749)
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-07-15 17:39:41 +00:00
Mazdak Farrokhzad 1166d68e65 Extract spacetimedb-memory-usage & Nix bindings dep on spacetimedb-data-structures (#2919) 2025-07-04 12:54:00 +00:00
Mazdak Farrokhzad 0c3635188d Auto-migrate: Allow adding new variants at the tail (#2874) 2025-06-27 17:29:31 +00:00
Viktor Szépe f6da9e1f5f Fix typos (#2812)
Signed-off-by: Viktor Szépe <viktor@szepe.net>
2025-06-04 16:33:32 +00:00
Kim Altintop a056796efb Prevent ahash from pulling in getrandom 0.3 (#2714) 2025-05-08 14:33:58 +00:00
Rafael Guerreiro 0f70e63304 Simple implementation of insert_or_update and try_insert_or_update (#2678)
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-05-02 15:51:48 -04:00
Phoebe Goldman 57fa739c6d Add docs for FilterableValue to rust bindings crate (#2547)
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-04-15 01:56:35 +00:00
Noa 483a9488e2 Update rand (#2568) 2025-04-11 17:39:41 +00:00
Mazdak Farrokhzad c39f7fa64c Plain enums as index keys with specialized indices (#2506) 2025-04-09 18:52:15 +00:00
Phoebe Goldman 80b3613f45 Add CI job to run cargo doc on the bindings crate (#2548) 2025-04-03 17:41:17 +00:00
joshua-spacetime 20e92ced5a Feature gate #[client_visibility_filter] (#2528) 2025-03-31 23:15:24 +00:00
joshua-spacetime 01c391f8a9 Add sql support for :sender parameter (#2483) 2025-03-21 17:53:34 +00:00