Aller au contenu
En Markdown

explain ​

Transformer un message du validateur en problème qu'un auteur peut réparer, et l'afficher comme alta lint.

Les signatures et leurs descriptions sont en anglais, comme le code.

Exemple ​

example.mjs
js
// Read a problem as an author: the field, the rule, how to fix it, and the page that explains it.
import { formatProblem, ruleInfo, ruleUrl, 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", title: { en: "Wave at your agent", fr: "Fais signe à ton agent" } }],
    reward: { xp: 10 },
  }],
};

for (const p of validate(doc).problems) {
  console.log(formatProblem(p, "quests.json"));
  console.log("fix:", ruleInfo(p.rule)?.fix);
  console.log("docs:", ruleUrl(p.rule));
}

examples/sdk/explain.mjs

Lance-le depuis un dossier où le paquet est installé : node example.mjs.

Sortie
text
error: quests.json › quests[0].steps[0].human: core.my-pack.hello/wave: a manual step says why only the player can do it (human) [step.manual-reason] (see https://docs.altasystem.ai/reference/errors#step-manual-reason)
fix: Add `"human"`: speak, approve, device, external, judge or before; or give the step a `run` and a `check`.
docs: https://docs.altasystem.ai/reference/errors#step-manual-reason

Fonctions ​

explain ​

ts
function explain(kind: string, messages: string[], doc: unknown, level: Problem["level"] = "error"): Problem[]

Explains the messages of a validator for a document of this kind.

formatProblem ​

ts
function formatProblem(p: Problem, file?: string): string

One line for a terminal: file › field: message [rule] (see <the rule on the errors page>).

ruleInfo ​

ts
const ruleInfo = (id: string): RuleInfo | undefined

The rule of an id, or undefined.

ruleUrl ​

ts
const ruleUrl = (id: string)

The page that explains a rule.

Voir aussi ​

Le standard, le SDK et la CLI sont sous Apache-2.0 ; Alta System OS et Alta World sous FSL-1.1-ALv2.