Skip to main content

brep_app/plm/
mod.rs

1//! The PLM client: where the server is, how a request reaches it, and — in
2//! `client` — sign-in, the refusals, the change feed and the version check.
3//! Nothing here runs unless a server is configured; the file-based app never
4//! constructs any of it.
5
6pub mod backend;
7pub mod bom;
8pub mod client;
9pub mod connection;
10pub mod config;
11pub mod transport;
12// The pure halves of S5 (uses lists) and S13 (adoption): no transport, no
13// store writes — the publisher and the importer drive them.
14pub mod adoption;
15pub mod kicad;
16pub mod uses;
17/// Embedded copies of PLM parts as a cache of their revisions (refreshed on open).
18pub mod cached_copies;
19/// Embedded copies pinned to a superseded or obsolete PLM revision.
20pub mod superseded;
21/// The bake worker (S10): open a queued member, build it, report.
22pub mod bake;
23/// Families and templates on a PLM store (S9): Generate, members, spin-out.
24pub mod family;
25/// Parts with no document of their own become items (an assembly's Save).
26pub mod promote;
27/// Revision thumbnails (P9): the picture a save makes and uploads.
28pub mod thumbnail;
29/// The instructions player's data a save of an instructions revision makes
30/// and uploads.
31pub mod player_data;
32pub mod thumbnail_view;
33pub mod tool_pictures;
34#[cfg(not(target_arch = "wasm32"))]
35pub mod native;
36
37/// One HTTP exchange with the PLM, whatever carries it. `path` is relative to
38/// the server's base URL (`"/api/store/index"`); the client, not the
39/// transport, adds the credential headers.
40pub struct PlmRequest {
41    pub method: &'static str,
42    pub path: String,
43    pub headers: Vec<(String, String)>,
44    pub body: Vec<u8>,
45}
46
47/// The server's answer, whatever its status.
48pub struct PlmResponse {
49    pub status: u16,
50    pub headers: Vec<(String, String)>,
51    pub body: Vec<u8>,
52}
53
54/// Deliberately not `Send`, like the store seam's `BackendFuture`: every host
55/// is single-threaded (the browser main thread; the native frame loop).
56pub type PlmFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = Result<T, String>>>>;
57
58/// Carries a [`PlmRequest`] to the server. `Err` means the request never got
59/// an answer (network, DNS, refused connection). Every HTTP status — 204, 4xx
60/// and 5xx included — is `Ok`; the client maps them.
61pub trait PlmTransport {
62    fn send(&self, request: PlmRequest) -> PlmFuture<PlmResponse>;
63}
64
65/// Lowercase hex SHA-256 of `bytes`: the server's `content_hash`
66/// (`brep_plm::auth::content_hash`) of a document written with exactly these
67/// bytes. The app's one copy (I13).
68pub fn content_hash(bytes: &[u8]) -> String {
69    use sha2::{Digest, Sha256};
70    Sha256::digest(bytes).iter().map(|byte| format!("{byte:02x}")).collect()
71}
72
73pub mod identity;