Skip to content

Commit 52d9274

Browse files
committed
Merge remote-tracking branch 'origin/drogus/spacetime-dev' into drogus/spacetime-dev
2 parents 8412d6d + c19b225 commit 52d9274

198 files changed

Lines changed: 4188 additions & 2068 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.sample

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ jobs:
277277
# This can't go on e.g. ubuntu-latest because that runner runs out of disk space. ChatGPT suggested that the general solution tends to be to use
278278
# a custom runner.
279279
runs-on: spacetimedb-runner
280+
# Skip if this is an external contribution. GitHub secrets will be empty, so the step would fail anyway.
281+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
280282
container:
281283
image: ghcr.io/epicgames/unreal-engine:dev-5.6
282284
credentials:

.github/workflows/csharp-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ jobs:
173173
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
174174
# Skip if this is an external contribution.
175175
# The license secrets will be empty, so the step would fail anyway.
176-
if: ${{ !github.event.pull_request.head.repo.fork }}
176+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}

.github/workflows/internal-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ concurrency:
1717

1818
jobs:
1919
run-tests:
20+
# Skip if this is an external contribution. GitHub secrets will be empty, so the step would fail anyway.
21+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
2022
runs-on: ubuntu-latest
2123
steps:
2224
- name: Print current ref and sha

crates/bindings-sys/src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,26 @@ pub mod raw {
645645
pub fn get_jwt(connection_id_ptr: *const u8, bytes_source_id: *mut BytesSource) -> u16;
646646
}
647647

648+
#[link(wasm_import_module = "spacetime_10.3")]
649+
extern "C" {
650+
/// Suspends execution of this WASM instance until approximately `wake_at_micros_since_unix_epoch`.
651+
///
652+
/// Returns immediately if `wake_at_micros_since_unix_epoch` is in the past.
653+
///
654+
/// Upon resuming, returns the current timestamp as microseconds since the Unix epoch.
655+
///
656+
/// Not particularly useful, except for testing SpacetimeDB internals related to suspending procedure execution.
657+
/// # Traps
658+
///
659+
/// Traps if:
660+
///
661+
/// - The calling WASM instance is holding open a transaction.
662+
/// - The calling WASM instance is not executing a procedure.
663+
// TODO(procedure-sleep-until): remove this
664+
#[cfg(feature = "unstable")]
665+
pub fn procedure_sleep_until(wake_at_micros_since_unix_epoch: i64) -> i64;
666+
}
667+
648668
/// What strategy does the database index use?
649669
///
650670
/// See also: <https://www.postgresql.org/docs/current/sql-createindex.html>
@@ -1222,7 +1242,10 @@ impl Drop for RowIter {
12221242
pub mod procedure {
12231243
//! Side-effecting or asynchronous operations which only procedures are allowed to perform.
12241244
#[inline]
1225-
pub fn sleep_until(_wake_at_timestamp: i64) -> i64 {
1226-
todo!("Add `procedure_sleep_until` host function")
1245+
#[cfg(feature = "unstable")]
1246+
pub fn sleep_until(wake_at_timestamp: i64) -> i64 {
1247+
// Safety: Just calling an `extern "C"` function.
1248+
// Nothing weird happening here.
1249+
unsafe { super::raw::procedure_sleep_until(wake_at_timestamp) }
12271250
}
12281251
}

crates/bindings-typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spacetimedb",
3-
"version": "1.6.0",
3+
"version": "1.6.2",
44
"description": "API and ABI bindings for the SpacetimeDB TypeScript module library",
55
"homepage": "https://github.com/clockworklabs/SpacetimeDB#readme",
66
"bugs": {

crates/bindings/src/lib.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#![doc = include_str!("../README.md")]
22
// ^ if you are working on docs, go read the top comment of README.md please.
33

4+
use core::cell::{LazyCell, OnceCell, RefCell};
5+
use core::ops::Deref;
6+
use spacetimedb_lib::bsatn;
7+
48
#[cfg(feature = "unstable")]
59
mod client_visibility_filter;
610
pub mod log_stopwatch;
@@ -12,16 +16,11 @@ pub mod rt;
1216
#[doc(hidden)]
1317
pub mod table;
1418

19+
#[cfg(feature = "unstable")]
20+
pub use client_visibility_filter::Filter;
1521
pub use log;
1622
#[cfg(feature = "rand")]
1723
pub use rand08 as rand;
18-
use spacetimedb_lib::bsatn;
19-
use std::cell::LazyCell;
20-
use std::cell::{OnceCell, RefCell};
21-
use std::ops::Deref;
22-
23-
#[cfg(feature = "unstable")]
24-
pub use client_visibility_filter::Filter;
2524
#[cfg(feature = "rand08")]
2625
pub use rng::StdbRng;
2726
pub use sats::SpacetimeType;
@@ -721,24 +720,9 @@ pub use spacetimedb_bindings_macro::reducer;
721720
/// Procedures are allowed to perform certain operations which take time.
722721
/// During the execution of these operations, the procedure's execution will be suspended,
723722
/// allowing other database operations to run in parallel.
724-
/// The simplest (and least useful) of these operators is [`ProcedureContext::sleep_until`].
725723
///
726724
/// Procedures must not hold open a transaction while performing a blocking operation.
727-
///
728-
/// ```no_run
729-
/// # use std::time::Duration;
730-
/// # use spacetimedb::{procedure, ProcedureContext};
731-
/// #[procedure]
732-
/// fn sleep_one_second(ctx: &mut ProcedureContext) {
733-
/// let prev_time = ctx.timestamp;
734-
/// let target = prev_time + Duration::from_secs(1);
735-
/// ctx.sleep_until(target);
736-
/// let new_time = ctx.timestamp;
737-
/// let actual_delta = new_time.duration_since(prev_time).unwrap();
738-
/// log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
739-
/// }
740-
/// ```
741-
// TODO(procedure-http): replace this example with an HTTP request.
725+
// TODO(procedure-http): add example with an HTTP request.
742726
// TODO(procedure-transaction): document obtaining and using a transaction within a procedure.
743727
///
744728
/// # Scheduled procedures
@@ -1089,7 +1073,8 @@ impl ProcedureContext {
10891073
/// log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
10901074
/// # }
10911075
/// ```
1092-
// TODO(procedure-async): mark this method `async`.
1076+
// TODO(procedure-sleep-until): remove this method
1077+
#[cfg(feature = "unstable")]
10931078
pub fn sleep_until(&mut self, timestamp: Timestamp) {
10941079
let new_time = sys::procedure::sleep_until(timestamp.to_micros_since_unix_epoch());
10951080
let new_time = Timestamp::from_micros_since_unix_epoch(new_time);
@@ -1135,6 +1120,9 @@ impl DbContext for ReducerContext {
11351120
#[non_exhaustive]
11361121
pub struct Local {}
11371122

1123+
/// The [JWT] of an [`AuthCtx`].
1124+
///
1125+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11381126
#[non_exhaustive]
11391127
pub struct JwtClaims {
11401128
payload: String,
@@ -1145,7 +1133,8 @@ pub struct JwtClaims {
11451133
/// Authentication information for the caller of a reducer.
11461134
pub struct AuthCtx {
11471135
is_internal: bool,
1148-
// NOTE(jsdt): cannot directly use a LazyLock without making this struct generic.
1136+
// NOTE(jsdt): cannot directly use a `LazyCell` without making this struct generic,
1137+
// which would cause `ReducerContext` to become generic as well.
11491138
jwt: Box<dyn Deref<Target = Option<JwtClaims>>>,
11501139
}
11511140

@@ -1157,19 +1146,25 @@ impl AuthCtx {
11571146
}
11581147
}
11591148

1160-
/// Create an [`AuthCtx`] for an internal call, with no JWT.
1149+
/// Creates an [`AuthCtx`] for an internal call, with no [JWT].
11611150
/// This represents a scheduled reducer.
1151+
///
1152+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11621153
pub fn internal() -> AuthCtx {
11631154
Self::new(true, || None)
11641155
}
11651156

1166-
/// Creates an [`AuthCtx`] using the json claims from a JWT.
1157+
/// Creates an [`AuthCtx`] using the json claims from a [JWT].
11671158
/// This can be used to write unit tests.
1159+
///
1160+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11681161
pub fn from_jwt_payload(jwt_payload: String) -> AuthCtx {
11691162
Self::new(false, move || Some(JwtClaims::new(jwt_payload)))
11701163
}
11711164

1172-
/// Creates an [`AuthCtx`] that reads the JWT for the given connection id.
1165+
/// Creates an [`AuthCtx`] that reads the [JWT] for the given connection id.
1166+
///
1167+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11731168
fn from_connection_id(connection_id: ConnectionId) -> AuthCtx {
11741169
Self::new(false, move || rt::get_jwt(connection_id).map(JwtClaims::new))
11751170
}
@@ -1179,13 +1174,17 @@ impl AuthCtx {
11791174
self.is_internal
11801175
}
11811176

1182-
/// Check if there is a JWT without loading it.
1183-
/// If [`AuthCtx::is_internal`] is true, this will return false.
1177+
/// Checks if there is a [JWT] without loading it.
1178+
/// If [`AuthCtx::is_internal`] returns true, this will return false.
1179+
///
1180+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11841181
pub fn has_jwt(&self) -> bool {
11851182
self.jwt.is_some()
11861183
}
11871184

1188-
/// Load the jwt.
1185+
/// Loads the [JWT].
1186+
///
1187+
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
11891188
pub fn jwt(&self) -> Option<&JwtClaims> {
11901189
self.jwt.as_ref().deref().as_ref()
11911190
}
@@ -1240,6 +1239,9 @@ impl JwtClaims {
12401239
}
12411240

12421241
/// Get the whole JWT payload as a json string.
1242+
///
1243+
/// This method is intended for parsing custom claims,
1244+
/// beyond the methods offered by [`JwtClaims`].
12431245
pub fn raw_payload(&self) -> &str {
12441246
&self.payload
12451247
}

crates/cli/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ impl RawConfig {
169169
ecdsa_public_key: None,
170170
};
171171
RawConfig {
172-
default_server: local.nickname.clone(),
173-
server_configs: vec![local, maincloud],
172+
default_server: maincloud.nickname.clone(),
173+
server_configs: vec![maincloud, local],
174174
web_session_token: None,
175175
spacetimedb_token: None,
176176
}

0 commit comments

Comments
 (0)