JsonProject#
A project that lives in wasm memory between calls. It holds the accepted data, the baseline from the last solve and the cached result, so later calls send only edits and options. Create one with new JsonProject(options_json) or by calling clone() on an existing handle. For a one-shot run without a handle, use schedule.
Declaration#
The class has the same declaration in the browser build (pkg/plen_wasm.js) and the Node build (pkg-node/plen_wasm.js). In the browser build, init() must resolve before the first new JsonProject.
Release every handle, clones included, with free() or a using declaration ([Symbol.dispose]).
Creating#
new options_json: string
Creates an empty project. It has no data and no baseline, so the first call is usually solve with data.
Request#
| Argument | Payload | Required | Description |
|---|---|---|---|
options_json |
ProjectOptions |
yes | Project-wide options. "{}" for defaults |
ProjectOptions#
How the project treats imported data. The options are fixed for the handle's lifetime, and a clone inherits them. Unknown fields are rejected.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
validation |
"strict" | "repair" |
no | "strict" |
"strict" rejects invalid data with a validation error. "repair" fixes duplicate ids and missing or inconsistent dates and reports each fix as a repaired note. null means the default |
What each mode accepts and fixes: Accept messy input.
Errors#
The constructor is the only export that throws on bad input. It throws a string, the JSON text of an error envelope, not an Error object.
kind |
code |
When |
|---|---|---|
parse |
null |
options_json isn't valid JSON, isn't an object, or has an unknown field |
validation |
null |
validation is a string other than "strict" or "repair" |
In the browser build, calling the constructor before init() resolves fails at host level; see Host-level failures.
Example#
Create a handle in Node, with the thrown string parsed as an envelope:
const = ;
let ;
// ... solve, apply, preview
;
options_json that fails:
What the constructor throws:
Operations#
Each operation takes JSON text and returns an envelope as JSON text. None of them throws for bad input.
| Operation | Description |
|---|---|
solve |
Load data or reschedule edits, and accept the dates as the baseline |
preview |
Schedule hypothetical changes against the baseline without changing the project |
analyze |
Critical path and slack over supplied or current dates, without scheduling |
apply |
Commit edits to the accepted state |
level |
Resolve resource overallocation with delays and splits, and accept the result |
loadProfile |
Per-bucket load and capacity for resources on the baseline |
evaluate |
Score candidate change sets against the baseline |
slots |
Build assignment slots from workers' skills and task requirements |
suggestAssignments |
Propose assignments that fill, repair or rebalance slots |
Handle members#
clone#
: JsonProject
Returns a new handle with the same accepted state, baseline, cached result and options. The copy shares immutable state with the original until one of them is edited, and edits to one never affect the other. Works on a project in any state, solved or not.
Returns - a separate JsonProject. Free it on its own: freeing the original doesn't free the clone, and the other way round.
Errors - throws at host level when called on a freed handle.
const = ;
free#
: void
Releases the project's wasm memory right away. After free(), every method call on the handle throws an Error from the generated bindings, and so does a second free().
A handle that becomes unreachable without free() is released eventually by a FinalizationRegistry, at a time the garbage collector chooses.
[Symbol.dispose]#
: void
The same function as free(). Lets hosts that support explicit resource management free the handle at the end of a scope:
Example#
Load a project, try an edit on a clone, and free both handles, in Node:
const = ;
const = ;
const = new;
Response of copy.solve(undefined, "{}"):
Related#
init- loads the module before the first constructor call in the browserJsonProject.solve- load data and accept the first baseline- Module and Handles - handle lifetime, cloning and freeing
- Editing a Project - change sets, applying and rescheduling
- Error handling - the thrown constructor envelope and host-level failures