pub struct Db { /* private fields */ }Expand description
The server’s whole persistent state: the metadata under one lock (and in SQLite), the document tree beside it, and the administrator’s scripts.
A Db is a HANDLE: cloning it is cheap and every clone is the same store.
That is what lets a script’s plm.* bindings hold the store for the length
of one hook call.
Implementations§
Source§impl Db
impl Db
Sourcepub fn start_upload(&self) -> Result<Upload, Error>
pub fn start_upload(&self) -> Result<Upload, Error>
Begin streaming an upload, with the server’s size limit.
Sourcepub fn attach(
&self,
user: &User,
part_key: &str,
revision_key: &str,
staged: Staged,
describe: &Describe,
) -> Result<Attachment, Error>
pub fn attach( &self, user: &User, part_key: &str, revision_key: &str, staged: Staged, describe: &Describe, ) -> Result<Attachment, Error>
Attach a staged upload to a part (revision empty) or to one of its
revisions.
Sourcepub fn attach_blob(
&self,
user: &User,
part_key: &str,
revision_key: &str,
sha256: &str,
size: u64,
staged: Option<Staged>,
describe: &Describe,
check: impl FnOnce(&State) -> Result<(), Error>,
) -> Result<Attachment, Error>
pub fn attach_blob( &self, user: &User, part_key: &str, revision_key: &str, sha256: &str, size: u64, staged: Option<Staged>, describe: &Describe, check: impl FnOnce(&State) -> Result<(), Error>, ) -> Result<Attachment, Error>
Db::attach for bytes that are either a staged upload or, with
staged absent, a blob the store already holds (a workspace file
promoted to an attachment). check runs inside the lock first, so a
caller can prove its blob is still referenced at the write.
Sourcepub fn replace_attachment(
&self,
user: &User,
id: &str,
part: &str,
revision: &str,
expected_hash: &str,
staged: Staged,
) -> Result<Located, Error>
pub fn replace_attachment( &self, user: &User, id: &str, part: &str, revision: &str, expected_hash: &str, staged: Staged, ) -> Result<Located, Error>
Replace exactly one attachment reference atomically. A fresh id protects copies carried into other revisions; their original bytes remain intact.
Sourcepub fn detach(&self, user: &User, id: &str) -> Result<Located, Error>
pub fn detach(&self, user: &User, id: &str) -> Result<Located, Error>
Remove one attachment reference; the blob goes with its last one.
Sourcepub fn attachment(&self, id: &str) -> Option<Located>
pub fn attachment(&self, id: &str) -> Option<Located>
Find an attachment by id.
Sourcepub fn sweep_blobs(&self) -> Result<usize>
pub fn sweep_blobs(&self) -> Result<usize>
Remove blobs nothing references and uploads left in staging — what a
crash between moving a blob and committing its reference can leave.
For start-up, before the server takes requests (one process owns the
directory, see crate::dirlock); returns how many files went.
Source§impl Db
impl Db
Sourcepub fn backup_now(&self, trigger: &str) -> Result<LastBackup, Error>
pub fn backup_now(&self, trigger: &str) -> Result<LastBackup, Error>
Take a backup into --backup-dir, then keep only the newest
--backup-keep. Refused while another backup runs.
Sourcepub fn backup_into(&self, out: &Path) -> Result<Manifest>
pub fn backup_into(&self, out: &Path) -> Result<Manifest>
A backup of this store into out, with the snapshot and the draft
documents taken under the store’s read lock: writes wait for those
few milliseconds, and the backup never has to be retaken for them.
Source§impl Db
impl Db
pub fn set_type_fields( &self, id: &str, defs: Vec<AttributeDef>, ) -> Result<(), Error>
pub fn set_occurrence_fields( &self, defs: Vec<AttributeDef>, ) -> Result<(), Error>
pub fn save_layout( &self, user: &User, id: &str, name: &str, columns: Vec<String>, shared: bool, ) -> Result<Layout, Error>
pub fn patch_revision_attributes( &self, user: &User, part: &str, rev: &str, changes: &Value, ) -> Result<(), Error>
pub fn patch_occurrences( &self, user: &User, part: &str, rev: &str, ids: &[String], changes: &Value, ) -> Result<(), Error>
Source§impl Db
impl Db
Sourcepub fn open(root: impl Into<PathBuf>) -> Result<(Self, Option<String>)>
pub fn open(root: impl Into<PathBuf>) -> Result<(Self, Option<String>)>
Open (or create) the store at root.
Returns the generated administrator password when — and only when — this call seeded the first account. It is printed once at boot and never recoverable, which is the point: no build of this server ships a known password.
Sourcepub fn open_with_scripts(
root: impl Into<PathBuf>,
scripts: Option<PathBuf>,
) -> Result<(Self, Option<String>)>
pub fn open_with_scripts( root: impl Into<PathBuf>, scripts: Option<PathBuf>, ) -> Result<(Self, Option<String>)>
Db::open, with the scripts directory somewhere other than
<root>/scripts — typically a git checkout the administrator manages.
This is the path serve opens with, always at Durability::Full.
Sourcepub fn open_with(
root: impl Into<PathBuf>,
scripts: Option<PathBuf>,
durability: Durability,
) -> Result<(Self, Option<String>)>
pub fn open_with( root: impl Into<PathBuf>, scripts: Option<PathBuf>, durability: Durability, ) -> Result<(Self, Option<String>)>
Db::open_with_scripts at a chosen Durability. The test suites
open with Durability::Normal; the server never does.
Sourcepub fn stop_bake_worker(&self) -> Result<Status, Error>
pub fn stop_bake_worker(&self) -> Result<Status, Error>
Stop only the child owned by this server, including on shutdown.
pub fn scripts(&self) -> &Scripts
Sourcepub fn with_config(self, config: ServerConfig) -> Self
pub fn with_config(self, config: ServerConfig) -> Self
This store with the network-facing configuration config. Called once,
at start-up, before the store is shared; the throttle starts empty.
Sourcepub fn security(&self) -> &Security
pub fn security(&self) -> &Security
The hardening layer: configuration and the sign-in throttle.
Sourcepub fn script_editor_allowed(&self) -> bool
pub fn script_editor_allowed(&self) -> bool
Whether administrators may edit and test-run scripts in the browser:
the setting, unless --lock-script-editor forces it off.
Sourcepub fn read<R>(&self, f: impl FnOnce(&State) -> R) -> R
pub fn read<R>(&self, f: impl FnOnce(&State) -> R) -> R
Read the metadata under the shared lock.
Sourcepub fn mutate<R>(
&self,
f: impl FnOnce(&mut State) -> Result<R, Error>,
) -> Result<R, Error>
pub fn mutate<R>( &self, f: impl FnOnce(&mut State) -> Result<R, Error>, ) -> Result<R, Error>
Mutate the metadata under the exclusive lock, bump the sequence, and PERSIST before returning.
Persisting inside the guard is what makes number allocation safe: two
concurrent part creations serialize on this lock, and neither response
is sent until the number it handed out is committed. A closure that
returns Err leaves the state untouched: the parts it touched are put
back from the journal (Parts) and every other field from the copy
taken before it ran. The same happens when the write to disk fails —
a UNIQUE constraint the closure’s own check missed, a full disk.
The change’s audit events (crate::audit) are computed from exactly
what it touched and committed in the SAME transaction as the change, so
a change is never on disk without its events, nor an event without its
change. Every write path goes through here, so every change is logged
without any of them asking.
Sourcepub fn record(&self, action: &str, entity: EntityRef, detail: impl Into<String>)
pub fn record(&self, action: &str, entity: EntityRef, detail: impl Into<String>)
Record an event that is not a change to the store: a failed sign-in, a script file edited or run in the browser.
Sourcepub fn audit_query(
&self,
filter: &AuditFilter,
) -> Result<Vec<AuditEvent>, Error>
pub fn audit_query( &self, filter: &AuditFilter, ) -> Result<Vec<AuditEvent>, Error>
Audit events matching filter, newest first.
Sourcepub fn read_document(&self, key: &str) -> Result<Option<String>, Error>
pub fn read_document(&self, key: &str) -> Result<Option<String>, Error>
One document’s text, or None when it has never been written.
Sourcepub fn write_document(
&self,
part_id: &str,
revision_id: &str,
body: &str,
) -> Result<u64, Error>
pub fn write_document( &self, part_id: &str, revision_id: &str, body: &str, ) -> Result<u64, Error>
Write a document and record its hash on the revision.
The editable check is HERE, not only in the API layer: this is the one function that can change a revision’s bytes, so it is the one that has to refuse a released revision. A guard that lives only in the handler is a guard that the next caller forgets.
Everything happens inside one Db::mutate, which is what makes the
check race-free — a release landing between a separate check and the
write would otherwise rewrite released bytes. Within the guard the file
still lands BEFORE the metadata that describes it, so a crash between
the two leaves a document whose hash is not yet recorded, rather than a
recorded hash for bytes that do not exist.
Sourcepub fn write_import_document(
&self,
user: &User,
part_id: &str,
revision_id: &str,
expected_hash: &str,
body: &str,
uses: &Value,
) -> Result<u64, Error>
pub fn write_import_document( &self, user: &User, part_id: &str, revision_id: &str, expected_hash: &str, body: &str, uses: &Value, ) -> Result<u64, Error>
Import a reviewed document and its structure together. The expected hash and checkout are checked under the write lock, so another save or a broken checkout cannot silently replace the document reviewed by the user.
Source§impl Db
impl Db
Sourcepub fn prune_sessions(&self) -> Result<usize, Error>
pub fn prune_sessions(&self) -> Result<usize, Error>
Remove every expired session (session_expired), as the system;
how many went.
A session used to be removed only by signing out, or when its cookie came back after it expired. A browser that simply stops sending the cookie — it expired there, the user cleared it, a private window closed — left its session in the store for good, and every sign-in adds one: the list grew with use and nothing bounded it. This runs at every sign-in — the only way the list grows — so it holds the sessions that could still be used, plus whatever expired since the last sign-in. Not at start-up: opening a store changes nothing in it (an import or a restore opens exactly what it was given). Nothing is written when nothing has expired.
Source§impl Db
impl Db
Sourcepub fn create_part(
&self,
author: &User,
part_type_id: &str,
name: &str,
description: &str,
category: &str,
) -> Result<Part, Error>
pub fn create_part( &self, author: &User, part_type_id: &str, name: &str, description: &str, category: &str, ) -> Result<Part, Error>
Create a part of the default shape: the type decides the number, the document is normal, the first revision takes the suggested label.
Sourcepub fn create_part_with(
&self,
author: &User,
spec: &PartSpec,
) -> Result<Part, Error>
pub fn create_part_with( &self, author: &User, spec: &PartSpec, ) -> Result<Part, Error>
Create a part with its first draft revision.
The number comes from the type’s NumberMode. A Script-mode type and
the revision-label hook are asked OUTSIDE the store lock, on a snapshot;
then one Db::mutate re-checks everything their answers depend on —
that the type’s mode did not change meanwhile, and that the number and
label are still free. Two concurrent creates that a script gave the
same number therefore end as one part and one refusal, never two parts.
Sourcepub fn create_revision(
&self,
author: &User,
part_id: &str,
) -> Result<Revision, Error>
pub fn create_revision( &self, author: &User, part_id: &str, ) -> Result<Revision, Error>
Start a new revision of a part, labelled with the suggestion.
Sourcepub fn create_revision_labelled(
&self,
author: &User,
part_id: &str,
label: &str,
) -> Result<Revision, Error>
pub fn create_revision_labelled( &self, author: &User, part_id: &str, label: &str, ) -> Result<Revision, Error>
Start a new revision of a part.
While another revision is in work this is refused only when the
administrator has turned Settings::allow_multiple_open_drafts off;
by default several revisions may be in work at once. The new draft
inherits the document of the revision currently RELEASED — or, when
none is, the newest revision — so revising a part starts from what the
part currently is, never from somebody else’s unfinished draft. That
includes an imported part, which is revised rather than forked.
label is free text; empty takes the suggestion. It must not repeat a
label the part already has.
Sourcepub fn create_revision_from(
&self,
author: &User,
part_id: &str,
label: &str,
origin: Origin,
) -> Result<Revision, Error>
pub fn create_revision_from( &self, author: &User, part_id: &str, label: &str, origin: Origin, ) -> Result<Revision, Error>
Db::create_revision_labelled with the new revision’s origin: a
library re-import makes an imported one, so the next re-import
still knows the latest revision is its own.
Sourcepub fn update_part(&self, key: &str, fields: &Value) -> Result<Part, Error>
pub fn update_part(&self, key: &str, fields: &Value) -> Result<Part, Error>
Change a part’s descriptive fields — name, description,
category, tags, external_ref and attributes. The number, the
type and the document class are identity and never change here.
attributes MERGES: each key given is set (type-checked against the
part’s category, the new one if category changes in the same call),
and a null clears it. Keys not mentioned are untouched — so moving a
part to another category keeps the values the new schema lacks.
This is the write behind PATCH /api/parts/:id and a script’s
plm.updatePart.
Source§impl Db
impl Db
Sourcepub fn update_settings(&self, fields: &Value) -> Result<Settings, Error>
pub fn update_settings(&self, fields: &Value) -> Result<Settings, Error>
Change settings. fields MERGES: each key given is set, the rest are
untouched. An unknown key or a value of the wrong type is refused
rather than ignored, so a typo in an admin’s request cannot silently
leave a policy where it was.
Source§impl Db
impl Db
Sourcepub fn search_parts(&self, query: &str) -> Vec<Part>
pub fn search_parts(&self, query: &str) -> Vec<Part>
Search parts by number, name, category or tag — what a script’s
plm.findParts asks.
Sourcepub fn find_parts(&self, filter: &PartFilter) -> Vec<Part>
pub fn find_parts(&self, filter: &PartFilter) -> Vec<Part>
The parts that pass filter, in creation order.
Sourcepub fn find_parts_page(
&self,
filter: &PartFilter,
after: Option<&str>,
limit: Option<usize>,
) -> PartPage
pub fn find_parts_page( &self, filter: &PartFilter, after: Option<&str>, limit: Option<usize>, ) -> PartPage
One page of the parts that pass filter, in creation order: at most
limit, continuing after the cursor after (a PartPage::next).
The SQLite side narrows (crate::sql::Sql::candidates): the trigram
index finds the parts whose searchable text contains the search text,
and indexed columns apply the category, tag and company filters. Every
candidate is then checked against the in-memory part with the exact
rules below, so the answer is the one the rules give — the index only
decides how few parts are looked at. Search text shorter than three
characters (the trigram minimum) narrows nothing and is checked on
every part the other filters leave. Should the index fail, the answer
comes from a scan of memory rather than an error.
Sourcepub fn find_parts_scanning(&self, filter: &PartFilter) -> Vec<Part>
pub fn find_parts_scanning(&self, filter: &PartFilter) -> Vec<Part>
Db::find_parts by a scan of memory alone, with no index — what the
index’s answers are checked against.
Sourcepub fn checkout(
&self,
user: &User,
part_id: &str,
revision_id: &str,
client_id: &str,
) -> Result<(), Error>
pub fn checkout( &self, user: &User, part_id: &str, revision_id: &str, client_id: &str, ) -> Result<(), Error>
Take the lock on a draft revision.
Sourcepub fn checkin(
&self,
user: &User,
part_id: &str,
revision_id: &str,
force: bool,
) -> Result<(), Error>
pub fn checkin( &self, user: &User, part_id: &str, revision_id: &str, force: bool, ) -> Result<(), Error>
Release the lock. force is the BREAK path and requires the check-in
group; without it only the holder may check in.
Sourcepub fn transition(
&self,
user: &User,
part_id: &str,
revision_id: &str,
to: Lifecycle,
) -> Result<Vec<String>, Error>
pub fn transition( &self, user: &User, part_id: &str, revision_id: &str, to: Lifecycle, ) -> Result<Vec<String>, Error>
Move a revision’s lifecycle state, applying the rules in
crate::lifecycle and the automatic supersede.
A release runs two hooks when their files exist. beforeRelease runs
first, outside the store lock, and a throw refuses the release; the
locked write then re-checks that the revision’s bytes are the ones the
hook saw. afterRelease runs once the release is committed: it cannot
undo it, so its failure comes back as a WARNING, the release standing.
pub fn transition_reviewed( &self, user: &User, part_id: &str, revision_id: &str, to: Lifecycle, expected_hash: &str, ) -> Result<Vec<String>, Error>
Source§impl Db
impl Db
Sourcepub fn create_category(
&self,
id: &str,
change: CategoryChange,
) -> Result<Category, Error>
pub fn create_category( &self, id: &str, change: CategoryChange, ) -> Result<Category, Error>
Add a category. The whole tree is re-checked inside the write
(catalog::check_tree), so a parent that vanished meanwhile or a
key an ancestor gained meanwhile is caught there.
Sourcepub fn update_category(
&self,
id: &str,
change: CategoryChange,
) -> Result<Category, Error>
pub fn update_category( &self, id: &str, change: CategoryChange, ) -> Result<Category, Error>
Rename a category, move it, or replace its own attributes.
Changing an attribute’s type, or dropping one, leaves the values parts already hold where they are: a value that no longer fits is reported at the next release of that part, and a value whose key is gone is inert. Nothing is rewritten behind anyone’s back.
Source§impl Db
impl Db
Sourcepub fn set_uses(
&self,
user: &User,
part_id: &str,
revision_id: &str,
body: &Value,
) -> Result<Vec<Use>, Error>
pub fn set_uses( &self, user: &User, part_id: &str, revision_id: &str, body: &Value, ) -> Result<Vec<Use>, Error>
Replace a revision’s uses list — the call the CAD app makes on save,
and the web page’s stand-in until it does. Written under the same two
conditions as the document (check_writable), so a released
revision’s list never changes; checked by bom::check_uses inside
the same lock, so no two concurrent writes can close a cycle between
them.
Source§impl Db
impl Db
Sourcepub fn family_view(
&self,
viewer: &User,
key: &str,
revision: &str,
) -> Result<FamilyView, Error>
pub fn family_view( &self, viewer: &User, key: &str, revision: &str, ) -> Result<FamilyView, Error>
The family page for key at revision (empty: the newest).
Source§impl Db
impl Db
Sourcepub fn generate(
&self,
user: &User,
key: &str,
request: GenerateRequest,
) -> Result<GenerateReport, Error>
pub fn generate( &self, user: &User, key: &str, request: GenerateRequest, ) -> Result<GenerateReport, Error>
Generate a family’s members (see the module header for the rules).
Source§impl Db
impl Db
Sourcepub fn import_table(
&self,
user: &User,
key: &str,
revision: &str,
csv: &str,
) -> Result<ImportReport, Error>
pub fn import_table( &self, user: &User, key: &str, revision: &str, csv: &str, ) -> Result<ImportReport, Error>
Merge CSV rows into the table of a family revision in work (revision,
or else the newest one in work), writing the family’s DOCUMENT — the
table lives there. A row whose part number the table already has is
updated (its revision and description when the CSV has those columns,
and its value in every column the CSV has; an empty cell clears the
value back to the family’s own); a new number is appended. Expression
columns the table lacks are added. Nothing is generated here.
Source§impl Db
impl Db
Sourcepub fn template_view(
&self,
key: &str,
revision: &str,
) -> Result<TemplateView, Error>
pub fn template_view( &self, key: &str, revision: &str, ) -> Result<TemplateView, Error>
The template page for key at revision (empty: the released one,
else the newest).
Source§impl Db
impl Db
Sourcepub fn queue_resaves(
&self,
user: &User,
parts: &[String],
) -> Result<ResaveReport, Error>
pub fn queue_resaves( &self, user: &User, parts: &[String], ) -> Result<ResaveReport, Error>
Queue the latest revision of each selected part in the existing bake queue. The snapshot and all accepted jobs persist in one transaction.
Sourcepub fn bake_jobs(&self, status: &str) -> Vec<BakeJob>
pub fn bake_jobs(&self, status: &str) -> Vec<BakeJob>
The bake jobs, oldest first. status narrows to one status; all
includes finished jobs, which are otherwise left out.
Sourcepub fn bake_jobs_page(
&self,
status: &str,
offset: usize,
limit: Option<usize>,
ids: Option<&[String]>,
) -> BakePage
pub fn bake_jobs_page( &self, status: &str, offset: usize, limit: Option<usize>, ids: Option<&[String]>, ) -> BakePage
Count matching jobs, but build detailed views only for the requested page.
ids restricts progress to one user’s batch, including jobs on other pages.
Sourcepub fn claim_bake(
&self,
worker: &User,
id: Option<&str>,
) -> Result<Option<BakeJob>, Error>
pub fn claim_bake( &self, worker: &User, id: Option<&str>, ) -> Result<Option<BakeJob>, Error>
Take a bake job: id, or else the oldest one free. A job is free when
it is pending, or claimed longer than BAKE_LEASE ago. None when
asked for the next and nothing is free.
Sourcepub fn renew_bake(&self, worker: &User, id: &str) -> Result<BakeJob, Error>
pub fn renew_bake(&self, worker: &User, id: &str) -> Result<BakeJob, Error>
Extend a claimed job’s lease: the claim holder says “still baking”, and
the claim runs BAKE_LEASE from now. A long bake renews every so
often instead of being handed to another worker at 15 minutes. Only the
holder may renew ([held_by]): a job another worker took over after
the lease lapsed, or one nobody has claimed, is refused by name.
Sourcepub fn finish_bake(
&self,
worker: &User,
id: &str,
body: &str,
) -> Result<(), Error>
pub fn finish_bake( &self, worker: &User, id: &str, body: &str, ) -> Result<(), Error>
A worker’s result: the baked document replaces the assembled one, the job is done, and a family member’s stamp takes the new hash (a baked member is not “edited by hand”).
Source§impl Db
impl Db
Sourcepub fn replace_everywhere(
&self,
user: &User,
part_key: &str,
request: &ReplaceRequest,
) -> Result<ReplaceReport, Error>
pub fn replace_everywhere( &self, user: &User, part_key: &str, request: &ReplaceRequest, ) -> Result<ReplaceReport, Error>
Replace everywhere (see the module header).
Source§impl Db
impl Db
Sourcepub fn submit_for_review(
&self,
user: &User,
part_id: &str,
revision_id: &str,
submission: &Submission,
) -> Result<Vec<String>, Error>
pub fn submit_for_review( &self, user: &User, part_id: &str, revision_id: &str, submission: &Submission, ) -> Result<Vec<String>, Error>
Submit a draft for review: open a round and move it to InReview.
The rule is found, and the reviewers hook asked, on a snapshot and
OUTSIDE the store lock; the locked write then re-checks that the move is
still allowed. After it commits the review-event hook is told.
Sourcepub fn decide_revision(
&self,
user: &User,
part_id: &str,
revision_id: &str,
verdict: Verdict,
comment: &str,
) -> Result<Vec<String>, Error>
pub fn decide_revision( &self, user: &User, part_id: &str, revision_id: &str, verdict: Verdict, comment: &str, ) -> Result<Vec<String>, Error>
Approve or reject a revision’s live round. A rejection ends the round and sends the revision back to Draft.
Sourcepub fn change_revision_review(
&self,
user: &User,
part_id: &str,
revision_id: &str,
change: &RoundChange,
) -> Result<Vec<String>, Error>
pub fn change_revision_review( &self, user: &User, part_id: &str, revision_id: &str, change: &RoundChange, ) -> Result<Vec<String>, Error>
Change a revision’s live round: its reviewers, due date, and (for the check-in group) how many approvals it needs.
Sourcepub fn comment_on_revision(
&self,
user: &User,
part_id: &str,
revision_id: &str,
body: &str,
parent: &str,
) -> Result<(Comment, Vec<String>), Error>
pub fn comment_on_revision( &self, user: &User, part_id: &str, revision_id: &str, body: &str, parent: &str, ) -> Result<(Comment, Vec<String>), Error>
Add a comment to a revision’s discussion.
Sourcepub fn revision_review(
&self,
viewer: &User,
part_id: &str,
revision_id: &str,
) -> Result<RevisionReview, Error>
pub fn revision_review( &self, viewer: &User, part_id: &str, revision_id: &str, ) -> Result<RevisionReview, Error>
One revision’s review panel, as viewer sees it.
Source§impl Db
impl Db
Sourcepub fn create_company(
&self,
which: Companies,
fields: &Value,
) -> Result<Company, Error>
pub fn create_company( &self, which: Companies, fields: &Value, ) -> Result<Company, Error>
Add a manufacturer or supplier: {name, website?, notes?}.
pub fn update_company( &self, which: Companies, id: &str, fields: &Value, ) -> Result<Company, Error>
Sourcepub fn delete_company(&self, which: Companies, id: &str) -> Result<(), Error>
pub fn delete_company(&self, which: Companies, id: &str) -> Result<(), Error>
Remove a company that nothing names. One still named by a manufacturer part or an offer is refused, with the count: deleting it would leave sourcing pointing at nobody.
Sourcepub fn add_manufacturer_part(
&self,
part_id: &str,
fields: &Value,
) -> Result<ManufacturerPart, Error>
pub fn add_manufacturer_part( &self, part_id: &str, fields: &Value, ) -> Result<ManufacturerPart, Error>
Add a manufacturer part to a part:
{manufacturer, mpn, status?, preferred?, datasheet?, notes?}.
pub fn update_manufacturer_part( &self, part_id: &str, mp_id: &str, fields: &Value, ) -> Result<ManufacturerPart, Error>
Sourcepub fn delete_manufacturer_part(
&self,
part_id: &str,
mp_id: &str,
) -> Result<(), Error>
pub fn delete_manufacturer_part( &self, part_id: &str, mp_id: &str, ) -> Result<(), Error>
Remove a manufacturer part and every offer under it.
Sourcepub fn add_offer(
&self,
part_id: &str,
mp_id: &str,
fields: &Value,
) -> Result<SupplierOffer, Error>
pub fn add_offer( &self, part_id: &str, mp_id: &str, fields: &Value, ) -> Result<SupplierOffer, Error>
Add a supplier’s offer to a manufacturer part:
{supplier, spn?, url?, currency?, price_breaks?, lead_time_days?, moq?, stock?, notes?}.
pub fn update_offer( &self, part_id: &str, mp_id: &str, offer_id: &str, fields: &Value, ) -> Result<SupplierOffer, Error>
pub fn delete_offer( &self, part_id: &str, mp_id: &str, offer_id: &str, ) -> Result<(), Error>
Source§impl Db
impl Db
Sourcepub fn put_thumbnail(
&self,
user: &User,
part_key: &str,
revision_key: &str,
staged: Staged,
(width, height): (u32, u32),
claim: &Claim,
) -> Result<Thumbnail, Error>
pub fn put_thumbnail( &self, user: &User, part_key: &str, revision_key: &str, staged: Staged, (width, height): (u32, u32), claim: &Claim, ) -> Result<Thumbnail, Error>
Keep staged (already checked by png_size) as the thumbnail of
revision_key of part_key. Refused 409 when the revision’s
document is not the one pictured.
Source§impl Db
impl Db
Sourcepub fn workspaces(&self, viewer: &User) -> Vec<WorkspaceRow>
pub fn workspaces(&self, viewer: &User) -> Vec<WorkspaceRow>
The workspaces viewer may open: their own first, then every other
active user’s while workspaces are browsable (or to an admin).
Sourcepub fn workspace_folder(
&self,
viewer: &User,
owner: &str,
parent: &str,
) -> Result<Vec<EntryView>, Error>
pub fn workspace_folder( &self, viewer: &User, owner: &str, parent: &str, ) -> Result<Vec<EntryView>, Error>
The entries directly in one folder of owner’s workspace (the top
when parent is empty): folders first, then by name.
Sourcepub fn workspace_entry(
&self,
viewer: &User,
id: &str,
) -> Result<EntryView, Error>
pub fn workspace_entry( &self, viewer: &User, id: &str, ) -> Result<EntryView, Error>
One entry, if viewer may read its workspace.
Sourcepub fn workspace_versions(
&self,
viewer: &User,
id: &str,
) -> Result<Vec<VersionView>, Error>
pub fn workspace_versions( &self, viewer: &User, id: &str, ) -> Result<Vec<VersionView>, Error>
A file’s versions, oldest first.
Sourcepub fn workspace_file(
&self,
viewer: &User,
id: &str,
version: u32,
) -> Result<(String, FileVersion), Error>
pub fn workspace_file( &self, viewer: &User, id: &str, version: u32, ) -> Result<(String, FileVersion), Error>
One version of a file (0: the current one), with the entry’s name — what a download needs.
Sourcepub fn create_folder(
&self,
user: &User,
parent: &str,
name: &str,
) -> Result<EntryView, Error>
pub fn create_folder( &self, user: &User, parent: &str, name: &str, ) -> Result<EntryView, Error>
Make a folder in user’s own workspace.
Sourcepub fn create_link(
&self,
user: &User,
parent: &str,
name: &str,
part: &str,
revision: &str,
) -> Result<EntryView, Error>
pub fn create_link( &self, user: &User, parent: &str, name: &str, part: &str, revision: &str, ) -> Result<EntryView, Error>
Link a part (by id or number) into user’s workspace, following its
newest revision, or pinned to revision (an id or label). The name
defaults to the part’s number.
Idempotent: when the folder already links that part the same way
(following, or pinned to the same revision) the answer is that entry,
and nothing is added. A client that retries, or that links a part the
server already linked on create (link_on_create), makes one link.
Sourcepub fn create_file(
&self,
user: &User,
parent: &str,
name: &str,
media_type: &str,
staged: Staged,
) -> Result<EntryView, Error>
pub fn create_file( &self, user: &User, parent: &str, name: &str, media_type: &str, staged: Staged, ) -> Result<EntryView, Error>
Store a new file in user’s workspace: version 1.
Sourcepub fn replace_file(
&self,
user: &User,
id: &str,
media_type: &str,
staged: Staged,
) -> Result<EntryView, Error>
pub fn replace_file( &self, user: &User, id: &str, media_type: &str, staged: Staged, ) -> Result<EntryView, Error>
Replace a file’s bytes. The version before stays in its list.
pub fn replace_file_checked( &self, user: &User, id: &str, media_type: &str, staged: Staged, expected: Option<String>, ) -> Result<EntryView, Error>
Sourcepub fn restore_version(
&self,
user: &User,
id: &str,
version: u32,
) -> Result<EntryView, Error>
pub fn restore_version( &self, user: &User, id: &str, version: u32, ) -> Result<EntryView, Error>
Make an old version current again, as a NEW version with its bytes, so the versions after it are kept too.
Sourcepub fn update_entry(
&self,
user: &User,
id: &str,
fields: &Value,
) -> Result<EntryView, Error>
pub fn update_entry( &self, user: &User, id: &str, fields: &Value, ) -> Result<EntryView, Error>
Rename, move, or re-pin an entry. fields may carry name,
parent (a folder id, or empty for the top) and, for a link,
revision (an id or label to pin to, or empty to follow the newest).
Sourcepub fn delete_entry(
&self,
user: &User,
id: &str,
recursive: bool,
) -> Result<Vec<String>, Error>
pub fn delete_entry( &self, user: &User, id: &str, recursive: bool, ) -> Result<Vec<String>, Error>
Remove an entry — a link, a file with every version, or a folder.
A folder that holds anything is refused unless recursive. Never
touches a part or a revision; a file’s blobs go when nothing else
references them. Answers the ids removed.
Sourcepub fn promote(
&self,
user: &User,
id: &str,
ask: &Promote,
) -> Result<Attachment, Error>
pub fn promote( &self, user: &User, id: &str, ask: &Promote, ) -> Result<Attachment, Error>
Promote a version of a workspace file to a real attachment on a part or one of its revisions. Every attachment rule applies: the author group, a revision in work, not checked out by someone else. The bytes are shared, not copied, and the file stays in the workspace.
Source§impl Db
impl Db
pub fn save_workflow( &self, user: &User, definition: Definition, ) -> Result<Definition, Error>
pub fn start_workflow( &self, user: &User, key: &str, title: &str, part: &str, revision: &str, fields: Map<String, Value>, ) -> Result<String, Error>
Sourcepub fn workflow_view(&self, user: &User, id: &str) -> Result<Value, Error>
pub fn workflow_view(&self, user: &User, id: &str) -> Result<Value, Error>
Return a redacted smart form and execution graph, never trusted code.
pub fn workflow_action( &self, user: &User, id: &str, node_id: &str, outcome: &str, comment: &str, fields: Map<String, Value>, ) -> Result<(), Error>
pub fn control_workflow( &self, user: &User, id: &str, action: &str, node: &str, ) -> Result<(), Error>
pub fn drive_workflow(&self, id: &str) -> Result<(), Error>
Sourcepub fn recover_workflows(&self) -> Result<(), Error>
pub fn recover_workflows(&self) -> Result<(), Error>
Called once at boot. Never silently replay uncertain external effects.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Db
impl !UnwindSafe for Db
impl Freeze for Db
impl Send for Db
impl Sync for Db
impl Unpin for Db
impl UnsafeUnpin for Db
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.