Skip to main content

Crate haste_document_storage

Crate haste_document_storage 

Source
Expand description

Storage for document bodies (Binary content, attachments, exports) that is independent of the hosting cloud.

Callers only use the DocumentStorage trait; each backend lives under providers behind a cargo feature and is built with connect.

Every call names the tenant and project the document belongs to (DocumentScope) and the document’s name within them (DocumentName), so a caller can only ever reach its own project’s documents.

use haste_document_storage::{
    Document, DocumentName, DocumentScope, DocumentStorageKind,
    providers::gcs::{GcsConfig, GcsCredentials},
};
use haste_jwt::{ProjectId, TenantId};

let storage = haste_document_storage::connect(DocumentStorageKind::Gcs(GcsConfig {
    bucket: "my-bucket".into(),
    prefix: Some("documents".into()),
    credentials: GcsCredentials::ApplicationDefault,
    endpoint: None,
}))
.await?;

let scope = DocumentScope::new(
    &TenantId::new("acme".to_string())?,
    &ProjectId::new("clinic".to_string())?,
);
let name = DocumentName::new("Binary/123")?;
storage
    .put(
        &scope,
        &name,
        Document::new(b"...".as_slice()).with_content_type("application/pdf"),
    )
    .await?;
let document = storage.get(&scope, &name).await?;
let bytes = document.body.collect().await?;

Modules§

providers
Storage backends, each behind a cargo feature.
retry
Retry policy shared by backends.

Structs§

Document
A document to store: its bytes and what the backend keeps with them.
DocumentBody
A document body as a stream of chunks. Forward it chunk by chunk (for example into an HTTP response) or gather it with DocumentBody::collect.
DocumentMetadata
What a backend knows about a stored document without reading its body.
DocumentName
A document’s name within its DocumentScope, such as Binary/123.
DocumentScope
The tenant and project a document belongs to.
ListPage
One page of a scope’s listing, in name order.
ListRequest
Selects one page of a scope’s listing.
StoredDocument
A stored document: its metadata and body.

Enums§

DocumentStorageKind
The backend to connect to, with its configuration.
StorageError
Failure of a DocumentStorage call.

Traits§

DocumentStorage
Object storage for document bodies. A document is addressed by the DocumentScope (tenant and project) it belongs to and its DocumentName within that scope.

Functions§

connect
Builds the configured backend and verifies that it can authenticate. The Postgres backend’s table must already exist (see providers::postgres).

Type Aliases§

StorageFuture
Boxed future returned by DocumentStorage methods, so the trait stays object safe.