Skip to main content

haste_repository/
sequence.rs

1use haste_fhir_model::r4::{
2    generated::resources::{Resource, ResourceType},
3    sqlx::FHIRJson,
4};
5use haste_fhir_operation_error::OperationOutcomeError;
6use haste_jwt::{ProjectId, ResourceId, TenantId};
7
8use crate::types::FHIRMethod;
9
10#[derive(Clone)]
11pub struct ResourcePollingValue {
12    pub id: ResourceId,
13    pub resource_type: ResourceType,
14    pub version_id: String,
15    pub project: ProjectId,
16    pub tenant: TenantId,
17    pub resource: FHIRJson<Resource>,
18    pub sequence: i64,
19    pub fhir_method: FHIRMethod,
20}
21
22pub trait ResourceSequential {
23    /// The highest `resources.sequence` a consumer may read up to without
24    /// skipping a row that is still being written: every row at or below it
25    /// that will ever commit is visible to any snapshot taken after this call
26    /// returns.
27    fn max_safe_sequence(&self) -> impl Future<Output = Result<i64, OperationOutcomeError>> + Send;
28
29    /// The project's rows with `sequence_id < sequence <= safe_sequence`, in
30    /// sequence order. `safe_sequence` must come from a
31    /// [`max_safe_sequence`](Self::max_safe_sequence) call that returned
32    /// before this query's snapshot was taken.
33    fn get_sequence(
34        &self,
35        tenant_id: &TenantId,
36        project_id: &ProjectId,
37        sequence_id: u64,
38        safe_sequence: i64,
39        count: Option<u64>,
40    ) -> impl Future<Output = Result<Vec<ResourcePollingValue>, OperationOutcomeError>> + Send;
41}