MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / schema

Function schema

crates/client-api/src/routes/database.rs:531–566  ·  view source on GitHub ↗
(
    State(worker_ctx): State<S>,
    Path(SchemaParams { name_or_identity }): Path<SchemaParams>,
    Query(SchemaQueryParams { version }): Query<SchemaQueryParams>,
    Extension(auth): Extension<S

Source from the content-addressed store, hash-verified

529}
530
531pub async fn schema<S>(
532 State(worker_ctx): State<S>,
533 Path(SchemaParams { name_or_identity }): Path<SchemaParams>,
534 Query(SchemaQueryParams { version }): Query<SchemaQueryParams>,
535 Extension(auth): Extension<SpacetimeAuth>,
536) -> axum::response::Result<impl IntoResponse>
537where
538 S: ControlStateDelegate + NodeDelegate,
539{
540 let (leader, _) = find_leader_and_database(&worker_ctx, name_or_identity).await?;
541 // Wait for the module to finish loading rather than returning an immediate
542 // 500 error. The database may still be initializing (replaying the log,
543 // running init reducers, etc.).
544 let module = leader
545 .wait_for_module(std::time::Duration::from_secs(10))
546 .await
547 .map_err(log_and_500)?;
548
549 let module_def = &module.info.module_def;
550 let response_json = match version {
551 SchemaVersion::V9 => {
552 let raw = RawModuleDefV9::from(module_def.as_ref().clone());
553 axum::Json(sats::serde::SerdeWrapper(raw)).into_response()
554 }
555 SchemaVersion::V10 => {
556 let raw = RawModuleDefV10::from(module_def.as_ref().clone());
557 axum::Json(sats::serde::SerdeWrapper(raw)).into_response()
558 }
559 };
560
561 Ok((
562 TypedHeader(SpacetimeIdentity(auth.claims.identity)),
563 TypedHeader(SpacetimeIdentityToken(auth.creds)),
564 response_json,
565 ))
566}
567
568#[derive(Deserialize)]
569pub struct DatabaseParam {

Callers 1

Calls 9

find_leader_and_databaseFunction · 0.85
SerdeWrapperClass · 0.85
SpacetimeIdentityClass · 0.85
wait_for_moduleMethod · 0.80
OkFunction · 0.50
cloneMethod · 0.45
as_refMethod · 0.45
into_responseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…