schedule#

Schedules a ProjectData snapshot once and returns the result envelope. The call is stateless: it creates a temporary project with strict validation, solves the data once and drops the project before returning. Nothing is kept between calls, and there's no handle to free. To keep a baseline and send edits later, use JsonProject.solve.

Signature#

schedule(data_json: string, options_json: string): string

Synchronous and CPU-bound. The same data_json and options_json always produce the same result. In the browser build, call it only after init() has resolved.

Request#

Argument Payload Required Description
data_json ProjectData yes The full snapshot to schedule. Always validated in strict mode; the rules are listed on ProjectData.
options_json SolveOptions yes What to schedule and what to report. "{}" schedules the whole project with default options.

Response#

The success envelope carries a ScheduleResult. The envelope shape is described in Wire format.

The result's baselineId is set, but it names the baseline of the temporary project, so no later call can use it.

Errors#

Error When
kind: "parse" data_json or options_json isn't valid JSON, has the wrong JSON type, misses a required field, or options_json has an unknown field.
kind: "validation" A value the decoder rejects (path: null), or data_json fails strict validation (path names the field, e.g. tasks[0].start_date).

schedule never returns kind: "project": each call starts from a fresh project. Errors come back in the returned envelope; the call doesn't throw for bad input. See Error handling for the error fields and for host-level failures such as calling before init() resolves.

Example#

Request (data_json):

{
  "tasks": [
    { "id": "design", "start_date": "2026-01-05", "duration": 2 },
    { "id": "build", "start_date": "2026-01-05", "duration": 3 }
  ],
  "links": [{ "id": "l1", "source": "design", "target": "build", "type": "fs" }]
}

Options (options_json): {}

Response:

{
  "ok": true,
  "result": {
    "baselineId": "1-1527fed5c4d6197a",
    "conflicts": [],
    "converged": true,
    "cycles": [],
    "notes": [],
    "updates": [
      { "end_date": "2026-01-10 00:00", "id": "build", "kind": "task", "start_date": "2026-01-07 00:00" }
    ]
  }
}

Only build moved, so it's the only entry in updates. Pass {"includeUnchanged": true} as options_json to list every scheduled task.

Host call in Node:

const { schedule } = require("./pkg-node/plen_wasm.js");

const data = {
  tasks: [
    { id: "design", start_date: "2026-01-05", duration: 2 },
    { id: "build", start_date: "2026-01-05", duration: 3 },
  ],
  links: [{ id: "l1", source: "design", target: "build", type: "fs" }],
};

const envelope = JSON.parse(schedule(JSON.stringify(data), "{}"));

if (envelope.ok) {
  for (const update of envelope.result.updates) {
    console.log(update.id, update.start_date, update.end_date);
  }
} else {
  const { kind, message, path } = envelope.error;
  console.error(kind, message, path);
}