Skip to content

Commit 2b7f421

Browse files
Upgrade SpacetimeDB to 1.10.0, add procedure support, fix hook docs, add prelude (#101)
* Fixes #88 * Upgrade SpacetimeDB to 1.10.0 and use unstable feature, bump version to v0.15.0 * Fixes #99 * Fixes #100 * fix grammar, fix trait code docs * Expose LocalReadOnly in ReadOnlyDSL and context * Refactor imports to use spacetimedsl prelude
1 parent 4bdfd4f commit 2b7f421

File tree

19 files changed

+450
-288
lines changed

19 files changed

+450
-288
lines changed

Cargo.lock

Lines changed: 30 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Tamaro Skaljic<mail@tamaro-skaljic.de>"]
33
name = "spacetimedsl"
4-
version = "0.14.0"
4+
version = "0.15.0"
55
edition = "2024"
66
description = "Ergonomic DSL for SpacetimeDB"
77
documentation = "https://docs.rs/spacetimedsl"
@@ -14,10 +14,10 @@ readme = "README.md"
1414

1515
[dependencies]
1616
# https://crates.io/crates/spacetimedb Easy support for interacting between SpacetimeDB and Rust.
17-
spacetimedb = "1.9.0"
17+
spacetimedb = { version = "1.10.0", features = [ "unstable" ] }
1818

1919
# https://crates.io/crates/spacetimedsl_derive Macros to extend SpacetimeDSL
20-
spacetimedsl_derive = { version = "0.14.0", path = "derive" }
20+
spacetimedsl_derive = { version = "0.15.0", path = "derive" }
2121

2222
# https://crates.io/crates/itertools Extra iterator adaptors, iterator methods, free functions, and macros.
2323
itertools = "^0.14"

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn create_example(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
175175
)?;
176176

177177
// SpacetimeDB with SpacetimeDSL
178-
let dsl: spacetimedsl::DSL<'_> = spacetimedsl::dsl(ctx);
178+
let dsl: spacetimedsl::DSL<'_, spacetimedb::ReducerContext> = spacetimedsl::dsl(ctx);
179179

180180
// Without the question mark it would return a Result<Entity, spacetimedsl::SpacetimeDSLError>
181181
let entity: Entity = dsl.create_entity()?;
@@ -212,7 +212,7 @@ pub fn create_example(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
212212
Here is the implementation:
213213

214214
```rust
215-
pub trait CreateEntityRow : spacetimedsl::DSLContext {
215+
pub trait CreateEntityRow<T: spacetimedsl::WriteContext>: spacetimedsl::DSLContext<T> {
216216
fn create_entity<'a>(&'a self) -> Result<Entity, spacetimedsl::SpacetimeDSLError> {
217217
use spacetimedsl::Wrapper;
218218
use spacetimedb::{DbContext, Table};
@@ -249,7 +249,7 @@ pub trait CreateEntityRow : spacetimedsl::DSLContext {
249249
}
250250
}
251251

252-
impl CreateEntityRow for spacetimedsl::DSL<'_> {}
252+
impl<T: spacetimedsl::WriteContext> CreateEntityRow<T> for spacetimedsl::DSL<'_, T> {}
253253
```
254254

255255
### 🚨 The `SpacetimeDSLError` Type
@@ -819,7 +819,7 @@ pub struct Invalid {
819819
<summary>📄 Here is the `Delete One` DSL method of the Entity table</summary>
820820

821821
```rust
822-
pub trait DeleteEntityRowById: spacetimedsl::DSLContext {
822+
pub trait DeleteEntityRowById<T: spacetimedsl::WriteContext>: spacetimedsl::DSLContext<T> {
823823
fn delete_entity_by_id(
824824
&self,
825825
id: impl Into<EntityId> + Clone,
@@ -962,7 +962,7 @@ pub trait DeleteEntityRowById: spacetimedsl::DSLContext {
962962
});
963963
}
964964
}
965-
impl DeleteEntityRowById for spacetimedsl::DSL<'_> {}
965+
impl<T: spacetimedsl::WriteContext> DeleteEntityRowById<T> for spacetimedsl::DSL<'_, T> {}
966966
```
967967

968968
</details>
@@ -1583,15 +1583,15 @@ use spacetimedsl::hook;
15831583

15841584
// After insert hook
15851585
#[hook]
1586-
pub fn after_entity_insert(dsl: &impl spacetimedsl::DSLContext, row: &Entity) -> Result<(), SpacetimeDSLError> {
1586+
pub fn after_entity_insert(dsl: &spacetimedsl::DSL<'_, T>, row: &Entity) -> Result<(), SpacetimeDSLError> {
15871587
log::info!("Inserted entity with id={}", row.id());
15881588
Ok(())
15891589
}
15901590

15911591
// Before update hook - has access to both old and new values and can Mutate the new row before the update occurs
15921592
#[hook]
15931593
pub fn before_entity_update(
1594-
dsl: &impl spacetimedsl::DSLContext,
1594+
dsl: &spacetimedsl::DSL<'_, T>,
15951595
old_row: &Entity,
15961596
mut new_row: Entity
15971597
) -> Result<Entity, SpacetimeDSLError> {
@@ -1605,7 +1605,7 @@ pub fn before_entity_update(
16051605

16061606
// Before delete hook
16071607
#[hook]
1608-
pub fn before_entity_delete(dsl: &impl spacetimedsl::DSLContext, row: &Entity) -> Result<(), SpacetimeDSLError> {
1608+
pub fn before_entity_delete(dsl: &spacetimedsl::DSL<'_, T>, row: &Entity) -> Result<(), SpacetimeDSLError> {
16091609
log::info!("Deleting entity with id={}", row.id());
16101610
Ok(())
16111611
}
@@ -1778,13 +1778,15 @@ spacetimedsl = { version = "*" }
17781778

17791779
- [Using IndexScanRangeBounds / FilterableValue](https://github.com/tamaro-skaljic/SpacetimeDSL/issues/21) 🔄
17801780

1781-
- SpacetimeDSL is not available in `#[spacetimedb::view]` functions, because SpacetimeDB uses structs instead of traits for Contexts - We are not really able to generate code which use `ReducerContext`, `ViewContext` and `AnonymousViewContext` at the same time, so we would need to generate each read-only DSL method 3 times.
1782-
- If you encounter that you can't access a method on the (Anonymous)ViewContext type because it's private, please follow these instructions: <https://github.com/tamaro-skaljic/SpacetimeDSL/issues/90#issuecomment-3573925117> until <https://github.com/clockworklabs/SpacetimeDB/issues/3754> is resolved.
1781+
- SpacetimeDSL is not available in `#[spacetimedb::view]` functions until [SpacetimeDB#3787](https://github.com/clockworklabs/SpacetimeDB/pull/3787) is merged and released.
1782+
- If you encounter that you can't access a method on the `(Anonymous)ViewContext` type because it's private, please follow these instructions: <https://github.com/tamaro-skaljic/SpacetimeDSL/issues/90#issuecomment-3573925117> until [SpacetimeDB#3754](https://github.com/clockworklabs/SpacetimeDB/issues/3754) is resolved and released.
17831783

17841784
## ❓ FAQ
17851785

17861786
**❔ Why must `#[primary_key]` columns be private?**
17871787

1788+
> Currently, they are allowed to be public, until [SpacetimeDB#3754](https://github.com/clockworklabs/SpacetimeDB/issues/3754) is resolved and released.
1789+
17881790
- 🔒 They should never change after insertion
17891791
- DSL generates [setters](#-accessors-getters-and-setters) for non-private columns
17901792
- Making them public would:

derive-input/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Tamaro Skaljic<mail@tamaro-skaljic.de>"]
33
name = "spacetimedsl_derive-input"
4-
version = "0.14.0"
4+
version = "0.15.0"
55
edition = "2024"
66
description = "Contains structs which represent the input and output of SpacetimeDSL. Can be used by other proc-macro crates to build Macros which utilize SpacetimeDSL under the hood."
77
documentation = "https://docs.rs/spacetimedsl_derive-input"
@@ -10,6 +10,7 @@ repository = "https://github.com/tamaro-skaljic/SpacetimeDSL/tree/main/derive-in
1010
publish = true
1111
include = ["/src/**"]
1212
keywords = ["dsl", "spacetime", "macro", "codegen", "boilerplate"]
13+
readme = "../README.md"
1314

1415
[dependencies]
1516
# https://crates.io/crates/ident_case Utility for applying case rules to Rust identifiers.
@@ -28,7 +29,7 @@ quote = "1"
2829
itertools = "0.14.0"
2930

3031
# https://crates.io/crates/spacetimedb Easy support for interacting between SpacetimeDB and Rust.
31-
spacetimedb = "1.9.0"
32+
spacetimedb = { version = "1.10.0", features = [ "unstable" ] }
3233

3334
# https://crates.io/crates/spacetime-bindings-macro-input Unofficial Input Crate for the SpacetimeDB Macro Bindings.
3435
spacetime-bindings-macro-input = "1.6.0"

derive-input/src/internal/dsl/hook.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn build_dsl_function_arg() -> SpacetimeDSLArg {
241241
is_option: false,
242242
arg_name: format_ident!("dsl"),
243243
arg_type: SpacetimeDSLArgType::Normal(quote! {
244-
&spacetimedsl::DSL
244+
&spacetimedsl::DSL<'_, T>
245245
}),
246246
}
247247
}

0 commit comments

Comments
 (0)