JsonProject.analyze#

Computes analytics over dates without scheduling them. It reads either a supplied ProjectData snapshot or the current dates of the JsonProject, including edits that haven't been solved yet. Use it instead of solve when the dates are already final and only the critical path or slack is needed. It works on an unsolved project.

Signature#

analyze(data_json: string | null | undefined, options_json: string): string

Synchronous and read-only.

Request#

Argument Payload Required Description
data_json ProjectData no Dates to analyze. null or undefined analyzes the project's current dates.
options_json AnalyzeOptions yes Which analytics to compute. Send "{}" for none.

AnalyzeOptions#

The options object for analyze. Unknown fields are rejected with a parse error. The object itself can't be null.

Field Type Required Default Description
analytics AnalyticsOptions | null no no analytics Requests criticalPath and slack. Fills analytics in the result. null is the same as leaving it out.

Behavior#

  • With data_json, the data is validated and read but never installed. The project keeps its previous state, and its solved status doesn't change. When the project was created with validation: "repair", the data is repaired first and the repairs are reported in notes.
  • Without data_json, the project's current dates are read, including unsolved edits from apply. The project stays unsolved after the call if it was unsolved before.
  • Nothing is scheduled: dates are taken as they are.

Response#

An envelope with a ScheduleResult:

  • updates and conflicts are always empty, and converged is true.
  • cycles, notes and overallocations describe the analyzed dates.
  • analytics is present only when options_json requests it. Check its status before reading the data; see ScheduleResult.
  • baselineId is present only when data_json is omitted and the project is solved with no unsolved edits. Otherwise the field is left out.

Errors#

kind When
parse data_json or options_json isn't valid JSON, has a wrong type or an unknown field, or options_json is "null"
validation The supplied data fails validation, e.g. a task with fewer than two of start_date, end_date and duration (path: tasks[0].start_date)

analyze doesn't return project errors and doesn't throw for bad input. Error kinds are described in Error handling.

Example#

Get the critical path and slack of dates stored elsewhere, without scheduling them. Task build starts a day later than link l1 requires.

Request (data_json):

{
  "tasks": [
    { "id": "design", "start_date": "2026-08-10 08:00", "duration": 2 },
    { "id": "build", "start_date": "2026-08-13 08:00", "duration": 3 }
  ],
  "links": [{ "id": "l1", "source": "design", "target": "build", "type": "fs" }]
}

Request (options_json):

{ "analytics": { "criticalPath": true, "slack": true } }

Response:

{
  "ok": true,
  "result": {
    "analytics": {
      "criticalPath": { "links": [], "tasks": ["build"] },
      "slack": [
        { "free": 1, "task": "design", "total": 1 },
        { "free": 0, "task": "build", "total": 0 }
      ],
      "status": "available"
    },
    "conflicts": [],
    "converged": true,
    "cycles": [],
    "notes": [],
    "updates": []
  }
}

The call from a Node.js host:

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

const data = {
  tasks: [
    { id: "design", start_date: "2026-08-10 08:00", duration: 2 },
    { id: "build", start_date: "2026-08-13 08:00", duration: 3 },
  ],
  links: [{ id: "l1", source: "design", target: "build", type: "fs" }],
};
const options = { analytics: { criticalPath: true, slack: true } };

const project = new JsonProject("{}");
try {
  const response = JSON.parse(project.analyze(JSON.stringify(data), JSON.stringify(options)));
  if (!response.ok) {
    throw new Error(`${response.error.kind}: ${response.error.message}`);
  }
  console.log(response.result.analytics.criticalPath.tasks); // [ 'build' ]
} finally {
  project.free();
}