Skip to main content

Module scripting

Module scripting 

Source
Expand description

Administrator scripts: the directory they live in, the hooks the server calls, and the test run the web editor offers.

The operator’s design:

  • Scripts are plain .js FILES in a directory on the server (--scripts, default <data>/scripts). The directory is the source of truth, so an administrator can keep it in git. The web editor writes the same files. History is git’s job.
  • A changed file takes effect on the NEXT call: Scripts::source re-reads a file whenever its modification time or length differs from what it cached. There is no watcher thread and no restart.
  • Scripts are FULLY TRUSTED — network, the PLM API, the file system and child processes (host).
  • A script that throws, fails to parse or times out in a host call REFUSES the operation it hooks. The one exception is AFTER_RELEASE, which runs after the release is committed and so can only report.

§The hooks

One file per hook, each defining one global function that takes one JSON argument:

FileFunctionWhen
the type’s own filepartNumber(input)creating a part of a Script-mode type
REVISION_LABELrevisionLabel(input)creating any revision, when the file exists
BEFORE_RELEASEbeforeRelease(input)before a release commits, when the file exists
AFTER_RELEASEafterRelease(input)after a release commits, when the file exists

A hook NEVER runs while the store lock is held: the store decides on a snapshot, runs the hook, and then re-checks everything the hook’s answer depends on inside its one locked write (see crate::db).

Re-exports§

pub use brep_script_core as engine;

Modules§

host
The server’s host bindings: what a fully trusted script can reach.

Structs§

HookDoc
The hooks, for the page: which file, which function, what it is for.
ScriptFile
One file in the directory, as the page lists it.
Scripts
The scripts directory and a modification-time cache of its files.

Enums§

HookResult
What a hook call produced, for the caller that runs it.

Constants§

AFTER_RELEASE
Told about a release after it commits.
BEFORE_RELEASE
May refuse a release.
DEFAULT_PART_NUMBER
The file a new Script-mode part type is offered by default.
HOOKS
REVIEWERS
Proposes a review round’s reviewers when a revision is submitted.
REVIEW_EVENT
Told about every review event after it commits — the notification hook.
REVISION_LABEL
Suggests or validates the label of every new revision.

Functions§

run
Run function in the script relative, with the server’s host bindings acting as user.
run_source
Run unsaved source — the editor’s test run of text not yet written.
string_answer
Read a hook’s answer as a string: either the string itself or the named field of a returned object ("B" or { label: "B" }).
user_json
The user as a script sees it: identity and groups, never the verifier.