@patterkit/core 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -96,6 +96,7 @@ ${indent}}`;
96
96
  var import_model = require("@patterkit/model");
97
97
  var import_model2 = require("@patterkit/model");
98
98
  var import_model3 = require("@patterkit/model");
99
+ var import_expr = require("@wildwinter/expr");
99
100
  function choiceLoopsBack(choice, ...targets) {
100
101
  const back = new Set(targets.filter((s) => typeof s === "string" && s.length > 0));
101
102
  const hits = (n) => n.type === "snippet" ? !!n.jump && back.has(n.jump.to) : (n.children ?? []).some(hits);
@@ -601,18 +602,21 @@ function checkDecls(decls, where, issues) {
601
602
  });
602
603
  }
603
604
  if (decl.type === "quality") {
604
- const stages = decl.stages ?? [];
605
- if (stages.length < 2) {
606
- issues.push({
607
- code: "invalid-declaration",
608
- message: `${where}: '${decl.name}' is a quality but declares ${stages.length === 0 ? "no stages" : "only one stage"} (a ladder needs at least two)`
609
- });
610
- }
611
- const seenStages = /* @__PURE__ */ new Set();
612
- for (const s of stages) {
613
- if (!s.trim()) issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' has an empty stage name` });
614
- else if (seenStages.has(s)) issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' declares stage '${s}' more than once` });
615
- else seenStages.add(s);
605
+ for (const problem2 of (0, import_expr.qualityDeclarationProblems)(decl.stages)) {
606
+ switch (problem2.kind) {
607
+ case "too-few-stages":
608
+ issues.push({
609
+ code: "invalid-declaration",
610
+ message: `${where}: '${decl.name}' is a quality but declares ${problem2.count === 0 ? "no stages" : "only one stage"} (a ladder needs at least two)`
611
+ });
612
+ break;
613
+ case "empty-stage":
614
+ issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' has an empty stage name` });
615
+ break;
616
+ case "duplicate-stage":
617
+ issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' declares stage '${problem2.stage}' more than once` });
618
+ break;
619
+ }
616
620
  }
617
621
  }
618
622
  if (decl.default !== void 0 && !defaultMatchesType(decl.default, decl)) {
@@ -636,7 +640,7 @@ function defaultMatchesType(value, decl) {
636
640
  case "flags":
637
641
  return Array.isArray(value) && value.every((v) => typeof v === "string" && (decl.values?.includes(v) ?? true));
638
642
  case "quality":
639
- return typeof value === "string" && (decl.stages?.includes(value) ?? true);
643
+ return typeof value === "string" && !(0, import_expr.qualityDeclarationProblems)(decl.stages, value).some((p) => p.kind === "default-not-a-stage");
640
644
  }
641
645
  }
642
646
 
package/dist/index.js CHANGED
@@ -58,6 +58,7 @@ ${indent}}`;
58
58
  import { walkNodes, DEFAULT_WRITING_STATUSES, DEFAULT_RECORDING_STATUSES, DEFAULT_DOCUMENTATION_CLASSES, projectQualifiers, usedSpeakerPairs, PAD_AFTER_MIN, PAD_AFTER_MAX } from "@patterkit/model";
59
59
  import { isValidGameId, effectiveGameId } from "@patterkit/model";
60
60
  import { isValidPropertyName, propertyNameify, RESERVED_PROPERTY_NAMES } from "@patterkit/model";
61
+ import { qualityDeclarationProblems } from "@wildwinter/expr";
61
62
  function choiceLoopsBack(choice, ...targets) {
62
63
  const back = new Set(targets.filter((s) => typeof s === "string" && s.length > 0));
63
64
  const hits = (n) => n.type === "snippet" ? !!n.jump && back.has(n.jump.to) : (n.children ?? []).some(hits);
@@ -563,18 +564,21 @@ function checkDecls(decls, where, issues) {
563
564
  });
564
565
  }
565
566
  if (decl.type === "quality") {
566
- const stages = decl.stages ?? [];
567
- if (stages.length < 2) {
568
- issues.push({
569
- code: "invalid-declaration",
570
- message: `${where}: '${decl.name}' is a quality but declares ${stages.length === 0 ? "no stages" : "only one stage"} (a ladder needs at least two)`
571
- });
572
- }
573
- const seenStages = /* @__PURE__ */ new Set();
574
- for (const s of stages) {
575
- if (!s.trim()) issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' has an empty stage name` });
576
- else if (seenStages.has(s)) issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' declares stage '${s}' more than once` });
577
- else seenStages.add(s);
567
+ for (const problem2 of qualityDeclarationProblems(decl.stages)) {
568
+ switch (problem2.kind) {
569
+ case "too-few-stages":
570
+ issues.push({
571
+ code: "invalid-declaration",
572
+ message: `${where}: '${decl.name}' is a quality but declares ${problem2.count === 0 ? "no stages" : "only one stage"} (a ladder needs at least two)`
573
+ });
574
+ break;
575
+ case "empty-stage":
576
+ issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' has an empty stage name` });
577
+ break;
578
+ case "duplicate-stage":
579
+ issues.push({ code: "invalid-declaration", message: `${where}: '${decl.name}' declares stage '${problem2.stage}' more than once` });
580
+ break;
581
+ }
578
582
  }
579
583
  }
580
584
  if (decl.default !== void 0 && !defaultMatchesType(decl.default, decl)) {
@@ -598,7 +602,7 @@ function defaultMatchesType(value, decl) {
598
602
  case "flags":
599
603
  return Array.isArray(value) && value.every((v) => typeof v === "string" && (decl.values?.includes(v) ?? true));
600
604
  case "quality":
601
- return typeof value === "string" && (decl.stages?.includes(value) ?? true);
605
+ return typeof value === "string" && !qualityDeclarationProblems(decl.stages, value).some((p) => p.kind === "default-not-a-stage");
602
606
  }
603
607
  }
604
608
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Patter core: stable id generation, readable-handle computation, canonical (de)serialisation, and the structural validator.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@patterkit/model": "0.14.0",
38
+ "@wildwinter/expr": "^0.5.2",
38
39
  "@wildwinter/toolkit": "^0.1.0",
39
40
  "json5": "^2.2.3"
40
41
  }