(
State(worker_ctx): State<S>,
Path(SchemaParams { name_or_identity }): Path<SchemaParams>,
Query(SchemaQueryParams { version }): Query<SchemaQueryParams>,
Extension(auth): Extension<S
| 529 | } |
| 530 | |
| 531 | pub 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> |
| 537 | where |
| 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)] |
| 569 | pub struct DatabaseParam { |
no test coverage detected
searching dependent graphs…