Skip to main content

Db

Struct Db 

Source
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

Source

pub fn blob_path(&self, sha256: &str) -> PathBuf

The data directory’s blob path for sha256.

Source

pub fn start_upload(&self) -> Result<Upload, Error>

Begin streaming an upload, with the server’s size limit.

Source

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.

Source

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.

Source

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.

Source

pub fn detach(&self, user: &User, id: &str) -> Result<Located, Error>

Remove one attachment reference; the blob goes with its last one.

Source

pub fn attachment(&self, id: &str) -> Option<Located>

Find an attachment by id.

Source

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

Source

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.

Source

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

pub fn backup_to_temp(&self) -> Result<(PathBuf, Manifest), Error>

Take a backup into a temporary file for a download. The caller streams it and removes it.

Source§

impl Db

Source

pub fn set_type_fields( &self, id: &str, defs: Vec<AttributeDef>, ) -> Result<(), Error>

Source

pub fn set_occurrence_fields( &self, defs: Vec<AttributeDef>, ) -> Result<(), Error>

Source

pub fn save_layout( &self, user: &User, id: &str, name: &str, columns: Vec<String>, shared: bool, ) -> Result<Layout, Error>

Source

pub fn patch_revision_attributes( &self, user: &User, part: &str, rev: &str, changes: &Value, ) -> Result<(), Error>

Source

pub fn patch_occurrences( &self, user: &User, part: &str, rev: &str, ids: &[String], changes: &Value, ) -> Result<(), Error>

Source§

impl Db

Source

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.

Source

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.

Source

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.

Source

pub fn root(&self) -> &Path

The administrator’s scripts directory. The data directory.

Source

pub fn stop_bake_worker(&self) -> Result<Status, Error>

Stop only the child owned by this server, including on shutdown.

Source

pub fn scripts(&self) -> &Scripts

Source

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.

Source

pub fn backups(&self) -> &Status

The last backup this process took.

Source

pub fn security(&self) -> &Security

The hardening layer: configuration and the sign-in throttle.

Source

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.

Source

pub fn read<R>(&self, f: impl FnOnce(&State) -> R) -> R

Read the metadata under the shared lock.

Source

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.

Source

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.

Source

pub fn audit_query( &self, filter: &AuditFilter, ) -> Result<Vec<AuditEvent>, Error>

Audit events matching filter, newest first.

Source

pub fn sql(&self) -> &Sql

The SQLite store, for the search index and diagnostics.

Source

pub fn read_document(&self, key: &str) -> Result<Option<String>, Error>

One document’s text, or None when it has never been written.

Source

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.

Source

pub fn write_document_deriving( &self, part_id: &str, revision_id: &str, body: &str, if_match: Option<&str>, ) -> Result<(u64, Option<String>), Error>

Self::write_document (or Self::write_document_if with if_match), answering also why the document’s uses list was NOT derived from it, when it was not (S5 derived, derived-uses): an occurrence that places no PLM revision, or a list the uses rules refuse. The document is written either way, as it was when the CAD app published the list in a request of its own.

Source

pub fn write_document_if( &self, part_id: &str, revision_id: &str, body: &str, expected: &str, ) -> Result<u64, Error>

Self::write_document only if the revision still holds the document whose content hash is expected (an If-Match write): checked under the write lock, so a save made meanwhile (another client of the same user, another session) is never overwritten by a write based on the older document. A mismatch is 409, naming when it changed and who holds it now.

Source

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

pub fn remove_document(&self, key: &str) -> Result<(), Error>

Remove a document’s bytes. The revision record stays — a revision with no document is a legitimate state (a part imported with no 3D model).

Source§

impl Db

Source

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

Source

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.

Source

pub fn instructions_part_type(&self) -> Result<String, 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. The part type instructions are numbered in when a request names none: instructions (MI and 9 digits), made the first time it is needed. An admin may rename it or change its numbering like any other type.

Source

pub fn create_part_with( &self, author: &User, spec: &PartSpec, ) -> Result<Part, Error>

Source

pub fn create_revision( &self, author: &User, part_id: &str, ) -> Result<Revision, Error>

Start a new revision of a part, labelled with the suggestion.

Source

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.

Source

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.

Source

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

Source

pub fn settings(&self) -> Settings

The administrator’s settings as they stand.

Source

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

Source

pub fn search_parts(&self, query: &str) -> Vec<Part>

Search parts by number, name, category or tag — what a script’s plm.findParts asks.

Source

pub fn find_parts(&self, filter: &PartFilter) -> Vec<Part>

The parts that pass filter, in creation order.

Source

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.

Source

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.

Source

pub fn checkout( &self, user: &User, part_id: &str, revision_id: &str, client_id: &str, ) -> Result<(), Error>

Take the lock on a draft revision.

Source

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.

Source

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.

Source

pub fn transition_reviewed( &self, user: &User, part_id: &str, revision_id: &str, to: Lifecycle, expected_hash: &str, ) -> Result<Vec<String>, Error>

Source

pub fn delete_draft( &self, user: &User, part_id: &str, revision_id: &str, ) -> Result<(), Error>

Delete a draft revision outright — the only removal this server allows. A released revision is never deleted; it is obsoleted.

Source

pub fn changes_since(&self, since: u64) -> (u64, bool, Vec<String>)

The keys that changed since since, and whether the log still reaches that far back.

Source§

impl Db

Source

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.

Source

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

pub fn delete_category(&self, id: &str) -> Result<(), Error>

Remove a category that nothing uses. A category with children, or with any part filed in it, is refused: deleting it would silently re-file those parts as uncategorized.

Source§

impl Db

Source

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

Source

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

Source

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

Source

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

Source

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

pub fn spin_out( &self, user: &User, key: &str, request: SpinOutRequest, ) -> Result<Part, Error>

Spin a new normal part out of a template: its first revision is the template’s document with values in its expressions (the CAD app’s spin_out), stamped with the template, and queued for a bake.

Source§

impl Db

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

pub fn fail_bake( &self, worker: &User, id: &str, error: &str, ) -> Result<(), Error>

A worker reports that a bake failed (an expression that does not evaluate, a feature that does not build). The job waits for a person.

Source

pub fn retry_bake(&self, id: &str) -> Result<(), Error>

Put a failed or claimed job back in the queue — after fixing the row that failed, or to take a job off a worker that went away.

Source§

impl Db

Source

pub fn create_jobs( &self, user: &User, request: &NewJob, ) -> Result<Vec<Job>, Error>

Queue quantity jobs building one released instructions revision.

Source

pub fn update_job(&self, id: &str, fields: &Value) -> Result<Job, Error>

Change a job’s place in the queue, who it is assigned to, or cancel it (status: "cancelled"; a cancelled job frees its serials).

Source

pub fn sign_step( &self, user: &User, id: &str, step: &str, signoff: &SignOff, ) -> Result<JobStep, Error>

Sign one step of a job, in order, with the serials it captures.

Source

pub fn reopen_step( &self, user: &User, id: &str, step: &str, reason: &str, ) -> Result<Job, Error>

Reopen a signed step and every step after it: the check-in group, with a reason the audit keeps. A done job is in progress again.

Source§

impl Db

Source

pub fn replace_everywhere( &self, user: &User, part_key: &str, request: &ReplaceRequest, ) -> Result<ReplaceReport, Error>

Replace everywhere (see the module header).

Source§

impl Db

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

pub fn inbox(&self, user: &User) -> Inbox

What is waiting on user, and what they submitted.

Source§

impl Db

Source

pub fn put_player_data( &self, user: &User, part_key: &str, revision_key: &str, staged: Staged, claimed: &str, ) -> Result<PlayerArtifact, Error>

Keep staged (already checked to be player data) as the player data of a revision — instructions, or an ordinary part’s motion study — made from document claimed.

Source

pub fn player_data( &self, part_key: &str, revision_key: &str, ) -> Result<(String, String, Option<PlayerArtifact>), Error>

A revision’s current player data (instructions, or an ordinary part’s motion study), with its part and revision ids; None when there is none or it is stale.

Source

pub fn instructions_player_data( &self, part_key: &str, revision_key: &str, ) -> Result<(String, String, Option<PlayerArtifact>), Error>

The same for manufacturing instructions only: the /instructions/… page refuses an ordinary part (its study plays at /motion/…).

Source

pub fn create_share( &self, user: &User, part_key: &str, revision_key: &str, label: &str, ) -> Result<(Share, String), Error>

Make a customer link to a released instructions revision: the share and its token, which is never shown again.

Source

pub fn revoke_share( &self, part_key: &str, revision_key: &str, id: &str, ) -> Result<(), Error>

Source

pub fn shared_player( &self, token: &str, ) -> Option<(String, Option<PlayerArtifact>)>

What a customer link opens: its revision’s current player data, while the revision is released. None for an unknown or revoked token.

Source§

impl Db

Source

pub fn create_company( &self, which: Companies, fields: &Value, ) -> Result<Company, Error>

Add a manufacturer or supplier: {name, website?, notes?}.

Source

pub fn update_company( &self, which: Companies, id: &str, fields: &Value, ) -> Result<Company, Error>

Source

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.

Source

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?}.

Source

pub fn update_manufacturer_part( &self, part_id: &str, mp_id: &str, fields: &Value, ) -> Result<ManufacturerPart, Error>

Source

pub fn delete_manufacturer_part( &self, part_id: &str, mp_id: &str, ) -> Result<(), Error>

Remove a manufacturer part and every offer under it.

Source

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?}.

Source

pub fn update_offer( &self, part_id: &str, mp_id: &str, offer_id: &str, fields: &Value, ) -> Result<SupplierOffer, Error>

Source

pub fn delete_offer( &self, part_id: &str, mp_id: &str, offer_id: &str, ) -> Result<(), Error>

Source§

impl Db

Source

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

pub fn thumbnail( &self, part_key: &str, revision_key: &str, ) -> Result<Option<(String, Thumbnail)>, Error>

The thumbnail to serve for a revision (revision_key non-empty) or a part: None when there is no current one. Err only for an unknown part or revision.

Source§

impl Db

Source

pub fn create_tool(&self, user: &User, fields: &Value) -> Result<Tool, Error>

Source

pub fn update_tool(&self, id: &str, fields: &Value) -> Result<Tool, Error>

Source

pub fn set_tool_picture( &self, id: &str, staged: Staged, media_type: &str, ) -> Result<Tool, Error>

Set a tool’s picture to an uploaded image; the old one’s blob goes when nothing else references it.

Source§

impl Db

Source

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).

Source

pub fn folders_linking( &self, viewer: &User, part: &str, ) -> Result<Vec<LinkingFolder>, Error>

The folders in viewer’s Home holding a link to part (an id or number), each once, by path: what an assembly opened some other way than from the workspace is filed under. The top of the Home is the folder with an empty id.

Source

pub fn workspace_folder( &self, viewer: &User, owner: &str, parent: &str, ) -> Result<Vec<EntryView>, Error>

What is in one folder (by its id, or any link’s to it), or at the top of owner’s Home when parent is empty: folders first, then by name.

Source

pub fn workspace_folders(&self, viewer: &User) -> Vec<EntryView>

Every folder viewer may read, by name: the folders as parts are found in the catalog, linked anywhere or nowhere.

Source

pub fn workspace_files(&self, viewer: &User) -> Vec<EntryView>

Every file viewer may read, by name, linked anywhere or nowhere.

Source

pub fn workspace_entry( &self, viewer: &User, id: &str, ) -> Result<EntryView, Error>

One entry, if viewer may read where it is.

Source

pub fn workspace_versions( &self, viewer: &User, id: &str, ) -> Result<Vec<VersionView>, Error>

A file’s versions, oldest first, by the file’s id or a link’s. A link to an attachment has the attachment as its one version.

Source

pub fn workspace_file( &self, viewer: &User, id: &str, version: u32, ) -> Result<(String, FileVersion), Error>

One version of a file (0: the current one), by the file’s id or a link’s, with its name — what a download needs.

Source

pub fn create_folder( &self, user: &User, parent: &str, name: &str, ) -> Result<EntryView, Error>

Make a folder, owned by user, and link it into their folder parent (empty: their Home). Answers the link.

Link a part (by id or number) into a folder user owns, or their Home, 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.

Link a folder (its id, or any link’s to it) into a folder user owns or their Home, or, with home naming a user, at the top of that user’s Home, which only the folder’s owner does. It is the same folder in every place; nothing is copied. Linking a folder needs only that user may read it. Idempotent: the same place again answers the link already there.

Source

pub fn create_file( &self, user: &User, parent: &str, name: &str, media_type: &str, staged: Staged, ) -> Result<EntryView, Error>

Store a new file, owned by user, at version 1, and link it into a folder they own or their Home. Answers the link.

Source

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.

Source

pub fn replace_file_checked( &self, user: &User, id: &str, media_type: &str, staged: Staged, expected: Option<String>, ) -> Result<EntryView, Error>

Source

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.

Link a file (its id, or any link’s to it) into a folder user owns or their Home. It is the same file in every place: its name, owner and versions. Needs only that user may read it. Idempotent.

Link a part’s attachment (revision empty) or a revision’s into a folder user owns or their Home. It shows there as a file, and stays the attachment: read-only in the folder, changed on its part. Idempotent.

Source

pub fn paste_copy( &self, user: &User, parent: &str, what: &CopyOf, ) -> Result<EntryView, Error>

Paste a new unique copy of a folder, a file or an attachment into a folder user owns or their Home (what names one; see CopyOf). Owned by user, named as the original, or <name> (2), (3), … when the place holds that name.

  • a file or an attachment: a new file holding the same bytes (shared blobs, nothing re-uploaded), its versions its own from then on — a file keeps its whole history;
  • a folder: a new folder, and in it new copies of its folders and files, all the way down; what it links (parts, attachments) is linked again, never copied.

A new copy of a part is Db::copy_part’s. Answers the link placing the copy.

Source

pub fn copy_part( &self, user: &User, parent: &str, part: &str, revision: &str, number: &str, ) -> Result<Part, Error>

Paste a new unique copy of a part: a new part, with its own number, of the same type, category, tags and attributes, holding the model of revision (an id or label; empty: the newest) and every attachment of the part and of that revision (the bytes shared, nothing re-uploaded). It is linked into parent (a folder user owns, or their Home) following its newest revision, as a part a user makes is. number is the new part’s for a type that takes a typed number (empty: the type’s counter or script). Needs the author group. Answers the new part.

Source

pub fn update_entry( &self, user: &User, id: &str, fields: &Value, ) -> Result<EntryView, Error>

Rename, move, re-pin or re-own an entry. fields may carry name, parent (a folder id, or empty for the Home’s top), for a link to a part revision (an id or label to pin to, or empty to follow the newest), and for a folder owner (a user id or username).

Through a link to a folder, a name or an owner is the folder’s (and so in every place it is linked), which its owner changes; a parent moves the link, which the owners of both places allow. The owner is a property of the folder: it moves nothing.

Source

pub fn delete_entry( &self, user: &User, id: &str, recursive: bool, ) -> Result<Vec<String>, Error>

Remove an entry. A link — to a part, a folder, a file or an attachment — goes, and never touches what it points at. A folder or file itself (by its own id) is deleted only by its owner, and every link to it goes with it: a folder only empty unless recursive, which removes the links in it (what they point at stays); a file with every version. A file’s blobs go when nothing else references them. Answers the ids removed.

Source

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

Source

pub fn save_workflow( &self, user: &User, definition: Definition, ) -> Result<Definition, Error>

Source

pub fn start_workflow( &self, user: &User, key: &str, title: &str, part: &str, revision: &str, fields: Map<String, Value>, ) -> Result<String, Error>

Source

pub fn workflow_view(&self, user: &User, id: &str) -> Result<Value, Error>

Return a redacted smart form and execution graph, never trusted code.

Source

pub fn workflow_action( &self, user: &User, id: &str, node_id: &str, outcome: &str, comment: &str, fields: Map<String, Value>, ) -> Result<(), Error>

Source

pub fn control_workflow( &self, user: &User, id: &str, action: &str, node: &str, ) -> Result<(), Error>

Source

pub fn drive_workflow(&self, id: &str) -> Result<(), Error>

Source

pub fn recover_workflows(&self) -> Result<(), Error>

Called once at boot. Never silently replay uncertain external effects.

Trait Implementations§

Source§

impl Clone for Db

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Db

§

impl !UnwindSafe for Db

§

impl Forget for Db

§

impl Freeze for Db
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<RwLock<State>> is !null: Freeze, PhantomData<ArcInner<RwLock<State>>>: Freeze, *const ArcInner<Scripts> is !null: Freeze, PhantomData<ArcInner<Scripts>>: Freeze, *const ArcInner<Security> is !null: Freeze, PhantomData<ArcInner<Security>>: Freeze, *const ArcInner<Sql> is !null: Freeze, PhantomData<ArcInner<Sql>>: Freeze, *const ArcInner<DirLock> is !null: Freeze, PhantomData<ArcInner<DirLock>>: Freeze, *const ArcInner<Status> is !null: Freeze, PhantomData<ArcInner<Status>>: Freeze, *const ArcInner<Controller> is !null: Freeze, PhantomData<ArcInner<Controller>>: Freeze,

§

impl Move for Db

§

impl Send for Db

§

impl Sync for Db

§

impl Unpin for Db

§

impl UnsafeUnpin for Db
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<RwLock<State>> is !null: UnsafeUnpin, PhantomData<ArcInner<RwLock<State>>>: UnsafeUnpin, *const ArcInner<Scripts> is !null: UnsafeUnpin, PhantomData<ArcInner<Scripts>>: UnsafeUnpin, *const ArcInner<Security> is !null: UnsafeUnpin, PhantomData<ArcInner<Security>>: UnsafeUnpin, *const ArcInner<Sql> is !null: UnsafeUnpin, PhantomData<ArcInner<Sql>>: UnsafeUnpin, *const ArcInner<DirLock> is !null: UnsafeUnpin, PhantomData<ArcInner<DirLock>>: UnsafeUnpin, *const ArcInner<Status> is !null: UnsafeUnpin, PhantomData<ArcInner<Status>>: UnsafeUnpin, *const ArcInner<Controller> is !null: UnsafeUnpin, PhantomData<ArcInner<Controller>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more