Skip to content

validate ​

Check a document in memory: its kind is read from its schema field, and every problem comes explained (field, rule, fix).

Example ​

example.mjs
js
// Validate a document in memory: its kind is read from its `schema` field.
import { validate } from "@altasystem/sdk";

const doc = {
  schema: "alta.quests/0.3",
  id: "my-pack",
  branch: "core",
  quests: [{
    uid: "core.my-pack.hello",
    title: { en: "Hello", fr: "Salut" },
    act: 1,
    giver: "daemon",
    steps: [{ id: "wave", kind: "manual", human: "judge", title: { en: "Wave at your agent", fr: "Fais signe à ton agent" } }],
    reward: { xp: 10 },
  }],
};

const ok = validate(doc);
console.log(ok.kind, ok.ok, ok.problems.length);

delete doc.quests[0].steps[0].kind;
const bad = validate(doc);
console.log(bad.ok, bad.problems[0].rule, bad.problems[0].field);

examples/sdk/validate.mjs

Run it from a folder where the package is installed: node example.mjs.

Output
text
quests true 0
false step.kind quests[0].steps[0].kind

Functions ​

validate ​

ts
function validate(doc: unknown, env: Env = {}, kind: Kind | undefined = detect(doc)): Result

Validates a document: its kind (detected unless given), its problems explained (field, rule, guide).

detect ​

ts
function detect(doc: unknown): Kind | undefined

The kind of a parsed JSON document, from its schema field; undefined when it is not a content file.

withFragments ​

ts
function withFragments(game: Game, fragments: QuestFragment[]): Game

A game with the fragments given added (to check guides and scenes that name a pack's quests).

See also ​

Alta OS is open source (MIT).