@heroiclands/package-build 19.0.0 → 20.0.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +624 -0
  2. package/CONTENT.md +79 -8
  3. package/bin/content-build.mjs +7 -1
  4. package/content-config.mjs +10 -1
  5. package/docs/content-format.md +394 -72
  6. package/engine/actor-compiler.mjs +197 -7
  7. package/engine/address-charset.mjs +23 -5
  8. package/engine/base-compiler.mjs +63 -2
  9. package/engine/bundles.mjs +9 -0
  10. package/engine/content-address.mjs +92 -1
  11. package/engine/content-format.mjs +102 -0
  12. package/engine/content-index.mjs +11 -8
  13. package/engine/content-links.mjs +37 -21
  14. package/engine/field-reference.mjs +57 -5
  15. package/engine/field-spec.mjs +214 -7
  16. package/engine/folder-notes.mjs +24 -1
  17. package/engine/foreign-catalog.mjs +4 -1
  18. package/engine/foundry-entries.mjs +14 -0
  19. package/engine/frontmatter-lint.mjs +186 -27
  20. package/engine/frontmatter.mjs +11 -11
  21. package/engine/generate.mjs +67 -10
  22. package/engine/helpers.mjs +86 -9
  23. package/engine/index.mjs +3 -0
  24. package/engine/item-compiler.mjs +37 -0
  25. package/engine/journals.mjs +21 -4
  26. package/engine/macros.mjs +8 -0
  27. package/engine/map-notes.mjs +7 -7
  28. package/engine/note-ids.mjs +25 -1
  29. package/engine/note-vocabulary.mjs +76 -9
  30. package/engine/retired-fields.mjs +57 -16
  31. package/engine/runtime-only-fields.mjs +204 -0
  32. package/engine/scenes.mjs +12 -19
  33. package/engine/schema-check.mjs +23 -1
  34. package/engine/site-index.mjs +17 -0
  35. package/engine/subtype-registry.mjs +30 -0
  36. package/engine/system-block.mjs +81 -3
  37. package/engine/web-wikilinks.mjs +33 -27
  38. package/engine/wikilink-syntax.mjs +7 -0
  39. package/engine/wikilinks.mjs +74 -16
  40. package/hm3/actors.mjs +63 -13
  41. package/package.json +2 -2
  42. package/sohl/actors.mjs +106 -7
  43. package/sohl/item-fields.mjs +203 -0
  44. package/sohl/note-schemas.mjs +6 -3
  45. package/types/engine/actor-compiler.d.mts +83 -3
  46. package/types/engine/address-charset.d.mts +22 -4
  47. package/types/engine/base-compiler.d.mts +54 -3
  48. package/types/engine/content-address.d.mts +64 -0
  49. package/types/engine/content-format.d.mts +9 -0
  50. package/types/engine/field-spec.d.mts +271 -3
  51. package/types/engine/folder-notes.d.mts +20 -0
  52. package/types/engine/foundry-entries.d.mts +6 -0
  53. package/types/engine/frontmatter-lint.d.mts +18 -2
  54. package/types/engine/frontmatter.d.mts +11 -11
  55. package/types/engine/generate.d.mts +27 -0
  56. package/types/engine/helpers.d.mts +37 -9
  57. package/types/engine/index.d.mts +1 -0
  58. package/types/engine/map-notes.d.mts +2 -2
  59. package/types/engine/note-ids.d.mts +14 -0
  60. package/types/engine/retired-fields.d.mts +29 -13
  61. package/types/engine/runtime-only-fields.d.mts +102 -0
  62. package/types/engine/schema-check.d.mts +10 -1
  63. package/types/engine/subtype-registry.d.mts +21 -0
  64. package/types/engine/system-block.d.mts +28 -2
  65. package/types/sohl/actors.d.mts +3 -3
@@ -30,10 +30,13 @@
30
30
  * any other: the macro pass reads the same page independently, and withholds
31
31
  * nothing from the journal (#1514).
32
32
  *
33
- * Folder placement is identical to the items pack: `sohl.folder` in
34
- * frontmatter is the target folder's id (from folders.yaml), resolved
35
- * against a folders.yaml list via the constructor's `folderResolver`. A
36
- * documentation entry reuses its document's folder id verbatim.
33
+ * Folder placement is identical to the items pack: `sohl.packFolder` in
34
+ * frontmatter is a folder **note's address**, resolved through the shared
35
+ * address index by the constructor's `folderResolver` (#255, #260). A folder
36
+ * materialises in every pack holding a document that names it, so a journals
37
+ * pack needs to declare nothing (#257) — which is what stopped this pass
38
+ * filing documentation into folders its own pack had never heard of. A
39
+ * documentation entry reuses its document's folder verbatim.
37
40
  *
38
41
  * Not a standalone script — exports the `Journals` compiler class, imported
39
42
  * and driven by `packages/content-build/engine/generate.mjs` (via `npm run build:compiledb`).
@@ -311,6 +314,20 @@ export class Journals extends BasePackCompiler {
311
314
  */
312
315
  static requiresId = false;
313
316
 
317
+ /**
318
+ * **None.** A JournalEntry has no artwork — no `img` property, and no
319
+ * nested place for one — so a note whose whole document is prose has
320
+ * nowhere to put an authored path (#349).
321
+ *
322
+ * The emptiness is the declaration, in the sense `JOURNAL_ONLY_FIELDS` is:
323
+ * it is what separates a pass that emits no art from one that has simply
324
+ * not said, and it is the fact the frontmatter lint reports a `lore` note's
325
+ * inert `img:` from.
326
+ *
327
+ * @type {readonly string[]}
328
+ */
329
+ static emitsArt = Object.freeze([]);
330
+
314
331
  /**
315
332
  * How many of the compiled entries were documentation for a document
316
333
  * compiled elsewhere, for the summary.
package/engine/macros.mjs CHANGED
@@ -295,6 +295,14 @@ export class Macros extends BasePackCompiler {
295
295
  */
296
296
  static convertsWikilinks = false;
297
297
 
298
+ /**
299
+ * A Macro carries an `img` — the tile art Foundry shows on the hotbar —
300
+ * defaulting to {@link DEFAULT_MACRO_IMG} where the note names none.
301
+ *
302
+ * @type {readonly string[]}
303
+ */
304
+ static emitsArt = Object.freeze(["img"]);
305
+
298
306
  /**
299
307
  * @param {object} fm - The note's frontmatter.
300
308
  * @returns {boolean} True for a `macro` note.
@@ -56,9 +56,9 @@ import { compendiumUuid, makeId, MAP_SUBTYPES, MAP_TYPES } from "./ids.mjs";
56
56
  // bridge (`SohlRegionTriggerBehavior`), so an event this build accepts is
57
57
  // exactly one the bridge forwards.
58
58
  import { CURATED_REGION_EVENTS, EXCLUDED_REGION_EVENTS } from "./region-events.mjs";
59
- // A map's background art is `img`, as every other note type's art is; `image`
60
- // is the retired spelling, still read through the retirement window (#142).
61
- import { readAliasedField } from "./retired-fields.mjs";
59
+ // A map's background art is `img`, as every other note type's art is. `image`,
60
+ // the spelling a map alone once used, is retired and gone (#149).
61
+ import { sohlField } from "./frontmatter.mjs";
62
62
 
63
63
  /* -------------------------------------------------------------------- */
64
64
  /* Note types and their canvas profiles */
@@ -907,7 +907,7 @@ export function buildScene(fm, ctx) {
907
907
  // Read from the note rather than from its `sohl:` block: art is not
908
908
  // system-specific, so `img` is authored at the top level like every other
909
909
  // type's, and `sohlField` honours the block for anything already there.
910
- const img = readAliasedField(fm, "img");
910
+ const img = sohlField(fm, "img");
911
911
  if (!img) throw new Error("a map note needs an `img`");
912
912
 
913
913
  const warn = (message) => {
@@ -981,11 +981,11 @@ export function buildScene(fm, ctx) {
981
981
  * @param {string} sceneId - The owning scene's `_id`.
982
982
  * @param {string} [img] - The background art, already resolved from the note.
983
983
  * Passed by {@link buildScene}, which reads it from the note rather than from
984
- * the block; defaults to whichever spelling the block itself carries, so a
985
- * direct two-argument call still works (#142).
984
+ * the block; defaults to the block's own `img`, so a direct two-argument call
985
+ * still works.
986
986
  * @returns {object} The Level document, keyed for the pack.
987
987
  */
988
- export function buildLevel(sohl, sceneId, img = readAliasedField({ sohl }, "img")) {
988
+ export function buildLevel(sohl, sceneId, img = sohlField({ sohl }, "img")) {
989
989
  const level = {
990
990
  _id: DEFAULT_LEVEL_ID,
991
991
  name: sohl.levelName ?? "Ground",
@@ -44,6 +44,11 @@ import { documentId } from "./content-address.mjs";
44
44
  import { systemOf } from "./document-subtypes.mjs";
45
45
  import { contentPackage } from "./content-package.mjs";
46
46
  import { KNOWN_DOCUMENT_SUBTYPE_MAPS } from "./subtype-registry.mjs";
47
+ // The folder id's derivation, taken from the pass that owns it rather than
48
+ // restated here — see the `folder` branch below. `folder-notes.mjs` reaches
49
+ // only `content-address`, `address-charset`, `ids` and `retired-fields`, none
50
+ // of which reach this module, so the direction closes no cycle.
51
+ import { FOLDER_TYPE, folderDocId } from "./folder-notes.mjs";
47
52
 
48
53
  /**
49
54
  * A frontmatter value read as a non-blank string, or `undefined`.
@@ -64,6 +69,20 @@ function text(value) {
64
69
  /**
65
70
  * The document id a note compiles under: its pin, or its address.
66
71
  *
72
+ * **One type hashes its address differently, and that is not an exception to
73
+ * the rule but an application of it.** A `Folder` is a document of its own
74
+ * class, and its id is hashed under the `folder` namespace so that a folder and
75
+ * an item sharing a shortcode cannot derive one id — a collision Foundry would
76
+ * not report, since it keys folders and documents in separate collections
77
+ * (#258). So the answer for a folder comes from
78
+ * {@link module:engine/folder-notes.folderDocId}, the pass that emits those
79
+ * documents, rather than from a second derivation here.
80
+ *
81
+ * That this function ever answered differently was invisible from inside a
82
+ * build — no pass reads a folder's id from here — and surfaced only in the
83
+ * content index, which is read from outside and had no way to be checked
84
+ * against what shipped (#310).
85
+ *
67
86
  * Returns `undefined` for a file with **no address** — no `type`, or no
68
87
  * `shortcode`. Such a file is not an addressable note, so it has no document
69
88
  * and inventing an id for one would file it under nothing. Every caller already
@@ -88,7 +107,12 @@ export function noteDocId(fm, { pkg, maps = KNOWN_DOCUMENT_SUBTYPE_MAPS } = {})
88
107
  const type = text(fm.type);
89
108
  const shortcode = text(fm.shortcode);
90
109
  if (!type || !shortcode) return undefined;
91
- return documentId(pkg ?? contentPackage(), systemOf(type, maps), type, shortcode);
110
+ const owner = pkg ?? contentPackage();
111
+ // Lowercased because `collectFolderNotes` matches the type that way, and
112
+ // the two must answer alike about the same note or the divergence this
113
+ // branch closes reopens under a capitalised `type: Folder`.
114
+ if (type.toLowerCase() === FOLDER_TYPE) return folderDocId(owner, shortcode);
115
+ return documentId(owner, systemOf(type, maps), type, shortcode);
92
116
  }
93
117
 
94
118
  /**
@@ -422,7 +422,14 @@ export const NOTE_VOCABULARY = Object.freeze({
422
422
  // values here would put a second, weaker answer beside the real one.
423
423
  subTypes: null,
424
424
  data: Object.freeze([
425
- { name: "portrait", ...TEXT, describe: "Path to the portrait image." },
425
+ {
426
+ name: "portrait",
427
+ ...TEXT,
428
+ describe:
429
+ "Path to the portrait image. Its first segment says which package owns " +
430
+ "the file: `systems/…` and `modules/…` are emitted unchanged, anything " +
431
+ "else is this package's own and is rooted under its assets.",
432
+ },
426
433
  TEMPLATE_PRIORITY,
427
434
  { name: "archetypes", ...LIST, describe: "Archetypal behaviours the being fits." },
428
435
  { name: "occupation", ...TEXT, describe: "What the being does for a living." },
@@ -466,7 +473,14 @@ export const NOTE_VOCABULARY = Object.freeze({
466
473
  vehicle: Object.freeze({
467
474
  subTypes: null,
468
475
  data: Object.freeze([
469
- { name: "portrait", ...TEXT, describe: "Path to the portrait image." },
476
+ {
477
+ name: "portrait",
478
+ ...TEXT,
479
+ describe:
480
+ "Path to the portrait image. Its first segment says which package owns " +
481
+ "the file: `systems/…` and `modules/…` are emitted unchanged, anything " +
482
+ "else is this package's own and is rooted under its assets.",
483
+ },
470
484
  TEMPLATE_PRIORITY,
471
485
  ]),
472
486
  }),
@@ -577,16 +591,31 @@ export const NOTE_VOCABULARY = Object.freeze({
577
591
  ...TEXT,
578
592
  describe: "Roll formula for the delay between contraction and onset.",
579
593
  },
594
+ {
595
+ name: "onsetDurationBase",
596
+ ...NUM,
597
+ describe: "That delay in seconds, stated outright instead of rolled.",
598
+ },
580
599
  {
581
600
  name: "healingCheckDurationFormula",
582
601
  ...TEXT,
583
602
  describe: "Roll formula for the interval between healing checks.",
584
603
  },
604
+ {
605
+ name: "healingCheckDurationBase",
606
+ ...NUM,
607
+ describe: "That interval in seconds, stated outright instead of rolled.",
608
+ },
585
609
  {
586
610
  name: "resolutionDurationFormula",
587
611
  ...TEXT,
588
612
  describe: "Roll formula for the time from onset to resolution.",
589
613
  },
614
+ {
615
+ name: "resolutionDurationBase",
616
+ ...NUM,
617
+ describe: "That time in seconds, stated outright instead of rolled.",
618
+ },
590
619
  ]),
591
620
  }),
592
621
 
@@ -719,7 +748,39 @@ export const NOTE_VOCABULARY = Object.freeze({
719
748
  "shock",
720
749
  "coma",
721
750
  ]),
722
- data: Object.freeze([TEMPLATE_PRIORITY]),
751
+ data: Object.freeze([
752
+ TEMPLATE_PRIORITY,
753
+ {
754
+ name: "healingCheckDurationFormula",
755
+ ...TEXT,
756
+ describe: "Roll formula for the interval between healing checks.",
757
+ },
758
+ {
759
+ name: "healingCheckDurationBase",
760
+ ...NUM,
761
+ describe: "That interval in seconds, stated outright instead of rolled.",
762
+ },
763
+ {
764
+ name: "bloodLossAdvanceDurationFormula",
765
+ ...TEXT,
766
+ describe: "Roll formula for the interval between blood-loss advances.",
767
+ },
768
+ {
769
+ name: "bloodLossAdvanceDurationBase",
770
+ ...NUM,
771
+ describe: "That interval in seconds. Setting it is what makes the wound bleed.",
772
+ },
773
+ {
774
+ name: "courseDurationFormula",
775
+ ...TEXT,
776
+ describe: "Roll formula for the interval between course tests.",
777
+ },
778
+ {
779
+ name: "courseDurationBase",
780
+ ...NUM,
781
+ describe: "That interval in seconds, stated outright instead of rolled.",
782
+ },
783
+ ]),
723
784
  }),
724
785
 
725
786
  weapongear: Object.freeze({
@@ -809,6 +870,7 @@ export const NOTE_VOCABULARY = Object.freeze({
809
870
  "folk",
810
871
  "culture",
811
872
  "bestiary",
873
+ "gathering",
812
874
  ]),
813
875
  // Nothing of its own: a lore note is prose, and what it *is* about is
814
876
  // its subType. The specification declares an empty table for it, and
@@ -881,12 +943,17 @@ export const NOTE_VOCABULARY = Object.freeze({
881
943
  // derived for them, which is precisely what a subType decides (#174).
882
944
  subTypes: Object.freeze(["battlemap", "localmap", "regionalmap"]),
883
945
  data: Object.freeze([
884
- // The specification spells this `img`, matching every other
885
- // note type, while the map compiler reads `image` from
886
- // `sohl:` today. It says outright that one of the two has
887
- // to move; the container takes the specification's name,
888
- // and moving the authored key is the migration's business.
889
- { name: "img", ...TEXT, describe: "Path to the map art." },
946
+ // `img`, as every other note type spells its artwork. A map alone
947
+ // read `image` out of its `sohl:` block; that spelling is retired
948
+ // and gone (#149), so the two names are one again.
949
+ {
950
+ name: "img",
951
+ ...TEXT,
952
+ describe:
953
+ "Path to the map art, owned by whichever package its first segment " +
954
+ "names — `systems/…` and `modules/…` unchanged, anything else this " +
955
+ "package's own.",
956
+ },
890
957
  {
891
958
  name: "dimensions",
892
959
  ...LIST,
@@ -80,10 +80,19 @@
80
80
  * still compiles, correctly, and refusing it would fail a build over a document
81
81
  * that is not wrong. Those retire in the three steps `package:` took (#56), and
82
82
  * this module carries the **first**: both spellings are read, the current one
83
- * wins, and the retired one is *reported* rather than refused. The sweep and
84
- * the refusal come later, once no tree writes it. See
83
+ * wins, and the retired one is *reported* rather than refused. See
85
84
  * {@link RETIRED_FIELD_ALIASES}.
86
85
  *
86
+ * **The third step is deletion, and it needs no code (#149).** `image`, a map's
87
+ * background art, is the first rename to have run all three: reported (#142),
88
+ * swept (SoHL#1801 and the position move that followed), then dropped from the
89
+ * table. Removing the entry is the whole of it — with no alias, the spelling is
90
+ * an ordinary unknown key in the `sohl:` block, which the frontmatter lint
91
+ * already refuses as an error alongside the required field it failed to supply.
92
+ * So nothing here *records* a finished retirement: the absence of an entry is
93
+ * the record, and a retirement that needed a standing refusal would mean the
94
+ * replacement never arrived. Do not keep a tombstone for one.
95
+ *
87
96
  * **A retired *position* is the same case, and reads the same (#305).** A field
88
97
  * whose shared source moved under `data:` is not renamed — `data.species` and
89
98
  * `hm3.species` are one field written in two places — but the retirement has
@@ -93,6 +102,14 @@
93
102
  * {@link module:engine/system-block.resolveFieldValue}'s answer; this module
94
103
  * only says what an author is told about it.
95
104
  *
105
+ * **A field has two retiring positions, not one (#332).** The in-block key is
106
+ * the obvious one; the other is the note's **top level**, because #128 did not
107
+ * invent the facts `data:` holds — it gathered them from exactly there. So
108
+ * `portrait:` beside `img:` is the pre-`data:` spelling of `data.portrait`,
109
+ * read for the same reason and reported by {@link retiredTopLevelMessage}. Both
110
+ * are needed, and separately: a note may have moved one and not the other, and
111
+ * a single finding covering both would name the wrong line half the time.
112
+ *
96
113
  * @module
97
114
  */
98
115
 
@@ -100,6 +117,7 @@ import fs from "node:fs";
100
117
 
101
118
  import { positionInFrontmatter } from "./diagnostics.mjs";
102
119
  import { sohlField } from "./frontmatter.mjs";
120
+ import { retiredTopLevelKey } from "./system-block.mjs";
103
121
 
104
122
  /**
105
123
  * What a note declaring `draft:` is told, in one place.
@@ -417,8 +435,8 @@ export function locateFrontmatterKey(absPath, key, value = undefined, { topLevel
417
435
  * and what every reader asks for; the value is the spelling still honoured.
418
436
  * The table is therefore scoped by the schema without saying so twice: an alias
419
437
  * applies to a note only where that note's type declares the current field, so
420
- * `image` is retired on a map — which declares `img` — and remains an unknown
421
- * key anywhere else.
438
+ * `relation` is retired on an affiliation — which declares `relations` — and
439
+ * remains an unknown key anywhere else.
422
440
  *
423
441
  * **`templatePriority` (#266).** The number that decides which of several
424
442
  * competing templates the Create dialog offers was called `archetype`, and
@@ -433,18 +451,9 @@ export function locateFrontmatterKey(absPath, key, value = undefined, { topLevel
433
451
  * read past. Only `affiliation` declares the field, so the alias is reported
434
452
  * there and the old spelling stays an ordinary unknown key everywhere else.
435
453
  *
436
- * **`img` (#142).** Every note type names its artwork `img`, at the note's top
437
- * level, and resolves it the same way. A map alone named its background art
438
- * `image` and read it out of the `sohl:` block — two spellings for one idea,
439
- * with nothing to reconcile them, and a specification that had to hedge rather
440
- * than state a rule. Art is not system-specific: a Scene is a core Foundry
441
- * document and HM3 would want the identical one, so the field belongs beside
442
- * every other note's `img`, not inside a system block.
443
- *
444
454
  * @type {Readonly<Record<string, string>>}
445
455
  */
446
456
  export const RETIRED_FIELD_ALIASES = Object.freeze({
447
- img: "image",
448
457
  templatePriority: "archetype",
449
458
  relations: "relation",
450
459
  });
@@ -507,6 +516,38 @@ export function legacyKeyMessage(block, field, file) {
507
516
  );
508
517
  }
509
518
 
519
+ /**
520
+ * What a note writing a field at the **top-level key `data:` gathered it off**
521
+ * is told (#332).
522
+ *
523
+ * {@link legacyKeyMessage}'s counterpart for the other retiring position. #128
524
+ * did not invent the facts `data:` holds — it collected them out of the note's
525
+ * open top level — so `portrait:` beside `img:` is the *pre-`data:`* spelling
526
+ * of `data.portrait`, and both are read for the same reason both in-block
527
+ * spellings are: a package moves its corpus when it is ready, not on a flag day.
528
+ *
529
+ * It says nothing about which value is emitted, because that is not what an
530
+ * author needs from it. The value is the same either way; what the finding
531
+ * counts is one more note still on the old position.
532
+ *
533
+ * @param {{name?: string}} field - The declaration, which names the current
534
+ * position; the retiring one is derived from it.
535
+ * @param {string} [file] - The note's path, named in the message. Omit it where
536
+ * the caller emits through a diagnostic, whose locator already starts the
537
+ * line — repeating it prints the path twice.
538
+ * @returns {string} The message, unpunctuated at the end as a finding is.
539
+ */
540
+ export function retiredTopLevelMessage(field, file) {
541
+ const retiring = retiredTopLevelKey(field);
542
+ return (
543
+ `top-level \`${retiring}:\` is the pre-\`data:\` position of the shared ` +
544
+ `\`${field.name}:\` — move it under \`data:\` instead` +
545
+ (file ? ` — ${file}` : "") +
546
+ `. Both are read and \`${field.name}\` wins, so the note compiles ` +
547
+ `identically either way; the top-level key is removed in a later release`
548
+ );
549
+ }
550
+
510
551
  /**
511
552
  * Whether a note writes the retired spelling of a field, wherever it put it.
512
553
  *
@@ -539,9 +580,9 @@ export function declaresRetiredAlias(fm, current) {
539
580
  * first, then the note's top level — so a renamed field keeps working wherever
540
581
  * it was already written while the canonical home is the top level.
541
582
  *
542
- * A blank value counts as absent: `img:` cleared in an editor means the note
543
- * names no art there, and falling through to the retired spelling is what an
544
- * author part-way through the rename means by it.
583
+ * A blank value counts as absent: `relations:` cleared in an editor means the
584
+ * note records no standings there, and falling through to the retired spelling
585
+ * is what an author part-way through the rename means by it.
545
586
  *
546
587
  * @param {object|null|undefined} fm - Parsed frontmatter.
547
588
  * @param {string} current - The field's current name.
@@ -0,0 +1,204 @@
1
+ /*
2
+ * This file is part of the Song of Heroic Lands (SoHL) system for Foundry VTT.
3
+ * Copyright (c) 2024-2026 Tom Rodriguez ("Toasty") — <toasty@heroiclands.org>
4
+ *
5
+ * This work is licensed under the GNU General Public License v3.0 (GPLv3).
6
+ * You may copy, modify, and distribute it under the terms of that license.
7
+ *
8
+ * For full terms, see the LICENSE.md file in the project root or visit:
9
+ * https://www.gnu.org/licenses/gpl-3.0.html
10
+ *
11
+ * SPDX-License-Identifier: GPL-3.0-or-later
12
+ */
13
+
14
+ /**
15
+ * Schema fields a note may **never** author, because the document writes them
16
+ * in play (#330).
17
+ *
18
+ * `retired-fields.mjs` refuses a field a note may no longer declare; this
19
+ * refuses one it never could. The two read alike deliberately — a note says one
20
+ * thing, the build does another, and nothing says so — but they are different
21
+ * facts, and only one of them is ever swept: a retired field goes away, while
22
+ * `onsetDate` is a permanent part of `affliction`'s schema that simply is not
23
+ * content.
24
+ *
25
+ * ## What was going wrong
26
+ *
27
+ * A DataModel declares plenty of fields a *compiled* document has no business
28
+ * carrying. SoHL's timed phases are the case that prompted this: each phase of
29
+ * an `affliction` or a `trauma` stores a `{…DurationFormula, …DurationBase,
30
+ * …Date}` triplet, and the third of them is instance state, crystallized when
31
+ * the phase fires. World time does not exist while content is compiled, and `0`
32
+ * is itself a valid world time — which is why the field is nullable rather than
33
+ * sentinelled, and why no default could stand in for the missing value.
34
+ *
35
+ * Nothing stopped a note writing one, and the build emitted it. Three checks
36
+ * each declined to catch it, every one of them for its own correct reason:
37
+ *
38
+ * - {@link module:engine/system-block.unknownBlockKeys} inspects the **top
39
+ * level** of a system block and deliberately never descends into `system:`,
40
+ * which is a passthrough for the system's own vocabulary.
41
+ * - {@link module:engine/system-block.mergeSystemData} writes every authored
42
+ * `system.*` path that no declared field claims — and no field claimed
43
+ * `contractDate`, so it passed through verbatim.
44
+ * - The schema check's fatal direction is *undeclared* — emitting a key the
45
+ * system does not define. `contractDate` **is** in the schema, so as far as
46
+ * that check can see the emitted key is legitimate.
47
+ *
48
+ * The gap was that no rule expressed "declared by the system, but never
49
+ * authorable". This module is that rule, and it is **declarative**: it knows no
50
+ * field names, only the {@link module:engine/field-spec.FieldSpec} property
51
+ * `runtimeOnly`, so it holds for any future runtime-only field of any system
52
+ * without being taught about it.
53
+ *
54
+ * ## Why a refusal rather than a drop
55
+ *
56
+ * Declaring the field claims its path, so the passthrough would leave it alone
57
+ * and the authored value would simply vanish — which is the silent-disagreement
58
+ * failure this package spends its time removing. And the consequence of getting
59
+ * it wrong is not a missing value but a shipped one: a compiled document
60
+ * carrying a world-time stamp is one world's play state, installed into every
61
+ * world that loads the pack.
62
+ *
63
+ * @module
64
+ */
65
+
66
+ import { runtimeOnlyFields } from "./field-spec.mjs";
67
+ import { getFrontmatter } from "./frontmatter.mjs";
68
+ import { locateFrontmatterKey } from "./retired-fields.mjs";
69
+ import { SYSTEM_DATA_KEY, systemData } from "./system-block.mjs";
70
+
71
+ /**
72
+ * What a note authoring a runtime-only field is told, in one place.
73
+ *
74
+ * Shared by every caller that can meet one, because an author meets whichever
75
+ * runs first and they should read the same. It says what the field holds and
76
+ * that deleting the key is the whole fix — there is no value to correct, which
77
+ * is what separates this from an out-of-range one.
78
+ *
79
+ * The reason comes from the declaration rather than from here: this module
80
+ * knows no field names, and a message written per field would be a second
81
+ * statement of the fact the declaration already carries.
82
+ *
83
+ * @param {string} key - The **whole key the note wrote**, from the region it
84
+ * sits in down to the field: `sohl.system.onsetDate` on the item's own note,
85
+ * `sohl.items[2].system.contractDate` on an actor's embedded entry. Composed
86
+ * by the caller, because only it knows where it found the value — and a
87
+ * message naming the leaf alone leaves an author a note to search.
88
+ * @param {import("./field-spec.mjs").FieldSpec} field - The declaration, which
89
+ * carries the reason.
90
+ * @param {string} [file] - The note's path, named in the message. Omit it where
91
+ * the caller emits through a diagnostic, whose locator already starts the
92
+ * line — repeating it prints the path twice.
93
+ * @returns {string} The message, unpunctuated at the end as a finding is.
94
+ */
95
+ export function runtimeOnlyMessage(key, field, file) {
96
+ return (
97
+ `\`${key}:\` is runtime state, not ` +
98
+ `content — delete it` +
99
+ (file ? ` — ${file}` : "") +
100
+ `. It holds ${field.runtimeOnly}, so no value for it exists at compile ` +
101
+ `time, and a compiled document carrying one ships a fact about a world ` +
102
+ `the pack has never been loaded into. The key is left out of the ` +
103
+ `document entirely, so the DataModel's own initial value stands`
104
+ );
105
+ }
106
+
107
+ /**
108
+ * The runtime-only fields a note actually writes, in declaration order.
109
+ *
110
+ * **Presence is the whole test**, as it is for every retired field: an authored
111
+ * `onsetDate: null` is as much a claim about play state as a number is, and it
112
+ * is exactly the belief the message exists to correct. So the question is
113
+ * whether the path resolves to anything at all, never whether the value is a
114
+ * usable one.
115
+ *
116
+ * Only `<block>.system.<to>` is searched, because it is the only position a
117
+ * runtime-only field is reachable at. Such a declaration carries no `name`, so
118
+ * it has neither a legacy in-block key nor a shared top-level source — and a
119
+ * bare `<block>.onsetDate` is an unrecognized block key, which
120
+ * {@link module:engine/system-block.unknownBlockKeys} already reports as an
121
+ * error naming the note and the line.
122
+ *
123
+ * @param {object|null|undefined} fm - Parsed frontmatter.
124
+ * @param {readonly import("./field-spec.mjs").FieldSpec[]} [fields] - The
125
+ * type's field declaration.
126
+ * @param {object} options - Options.
127
+ * @param {string} options.block - The system block to look in.
128
+ * @returns {import("./field-spec.mjs").FieldSpec[]} The offending declarations.
129
+ */
130
+ export function authoredRuntimeOnlyFields(fm, fields, { block } = {}) {
131
+ if (!fm || typeof fm !== "object" || !block) return [];
132
+ return runtimeOnlyIn(systemData(fm, block), fields);
133
+ }
134
+
135
+ /**
136
+ * The same question asked of a `system` block directly.
137
+ *
138
+ * A note's own block is reached through {@link authoredRuntimeOnlyFields}, but
139
+ * it is not the only place an author writes one: an actor note's `items:`
140
+ * entries carry a `system:` overlay that is deep-merged onto the template
141
+ * verbatim, with no field declaration in the path at all. That overlay is a
142
+ * `system` block by every meaning except where it sits, and a `contractDate`
143
+ * written there ships exactly as one written on the trauma's own note.
144
+ *
145
+ * @param {Record<string, unknown>|null|undefined} data - The authored `system`
146
+ * data.
147
+ * @param {readonly import("./field-spec.mjs").FieldSpec[]} [fields] - The
148
+ * type's field declaration.
149
+ * @returns {import("./field-spec.mjs").FieldSpec[]} The offending declarations.
150
+ */
151
+ export function runtimeOnlyIn(data, fields) {
152
+ if (!data || typeof data !== "object") return [];
153
+ return runtimeOnlyFields(fields).filter(
154
+ (field) =>
155
+ typeof field.to === "string" &&
156
+ field.to !== "" &&
157
+ getFrontmatter(data, field.to, undefined) !== undefined,
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Refuse a note that authors any of its type's runtime-only fields.
163
+ *
164
+ * Refused rather than reported: the note is not compiled, so nothing it would
165
+ * have emitted reaches a pack. What that costs is the caller's to decide — each
166
+ * of them counts the refused note and emits a located diagnostic, so a refusal
167
+ * is never a silent skip.
168
+ *
169
+ * The **first** offending field is thrown on. A note authoring a whole phase
170
+ * triplet would otherwise produce three findings that are one mistake, and the
171
+ * build stops on this note either way; the fix for the first is the fix for all
172
+ * of them.
173
+ *
174
+ * @param {object|null|undefined} fm - Parsed frontmatter, or nothing when it
175
+ * could not be parsed.
176
+ * @param {readonly import("./field-spec.mjs").FieldSpec[]} [fields] - The
177
+ * type's field declaration. A type that declares none — or declares no
178
+ * runtime-only field — passes.
179
+ * @param {object} options - Options.
180
+ * @param {string} options.block - The system block to look in.
181
+ * @param {string} [options.file] - The note's path, named in the message. Omit
182
+ * it where the caller emits through a diagnostic, which puts the locator at
183
+ * the start of the line already — repeating it prints the path twice.
184
+ * @param {string} [options.absPath] - The note's file on disk, read only on the
185
+ * failing path to locate the offending line and column. The position rides on
186
+ * the thrown error as `position`, for a caller that emits a diagnostic.
187
+ * @returns {void}
188
+ * @throws {Error} When the note authors one.
189
+ */
190
+ export function assertNoRuntimeOnlyFields(fm, fields, { block, file, absPath } = {}) {
191
+ const [field] = authoredRuntimeOnlyFields(fm, fields, { block });
192
+ if (!field) return;
193
+
194
+ const key = `${block}.${SYSTEM_DATA_KEY}.${field.to}`;
195
+ const err = new Error(`${runtimeOnlyMessage(key, field, file)}.`);
196
+ // The **leaf** of the destination path, which is the key as the note writes
197
+ // it: `to` is dotted for a nested field, and a locator handed
198
+ // `charges.value` would find nothing. Deliberately not anchored at column 1
199
+ // — the key lives two levels in, under `<block>.system`.
200
+ const leaf = /** @type {string} */ (field.to).split(".").pop();
201
+ const position = locateFrontmatterKey(absPath, /** @type {string} */ (leaf));
202
+ if (position) err.position = position;
203
+ throw err;
204
+ }
package/engine/scenes.mjs CHANGED
@@ -73,13 +73,6 @@ import { packRouter } from "./pack-router.mjs";
73
73
  import { foundryPackageId } from "./content-package.mjs";
74
74
  import { itemDocEntryId } from "./item-docs.mjs";
75
75
  import { behaviorDocId, buildScene, isMapType, regionDocId } from "./map-notes.mjs";
76
- import {
77
- RETIRED_FIELD_ALIASES,
78
- declaresRetiredAlias,
79
- locateFrontmatterKey,
80
- readAliasedField,
81
- retiredAliasMessage,
82
- } from "./retired-fields.mjs";
83
76
 
84
77
  /**
85
78
  * Every SoHL action name this build knows about, for the `action:` warning on a
@@ -127,6 +120,17 @@ export class Scenes extends BasePackCompiler {
127
120
  static id = "scenes";
128
121
  static label = "map";
129
122
 
123
+ /**
124
+ * A map note's `img` is its background art, and it is **required**: the map
125
+ * compiler refuses a note without one. It lands on the scene's level rather
126
+ * than on a property spelled `img`, which makes no difference to the
127
+ * question this declaration answers — the authored path reaches the output
128
+ * (#349). The place Adventure this pass bundles carries it too.
129
+ *
130
+ * @type {readonly string[]}
131
+ */
132
+ static emitsArt = Object.freeze(["img"]);
133
+
130
134
  /** @type {string} */
131
135
  adventureDir;
132
136
 
@@ -410,17 +414,6 @@ export class Scenes extends BasePackCompiler {
410
414
  const entryId = hasBody ? itemDocEntryId(fm.id) : undefined;
411
415
  const { value: authoredFolder } = folderField(fm);
412
416
  const folder = this.folderResolver(authoredFolder, { isAddress: true });
413
- // The retired spelling of the background art, reported where an author
414
- // meets it soonest — every consumer runs the compile, and not every
415
- // one runs the lint (#142). Located by reading the note back, which is
416
- // what the other retired-field reports do: this is the one path that
417
- // needs the position, so it is paid for only here.
418
- if (declaresRetiredAlias(fm, "img")) {
419
- this.noteWarn(
420
- retiredAliasMessage(RETIRED_FIELD_ALIASES.img, "img"),
421
- locateFrontmatterKey(this.currentNote?.absPath, RETIRED_FIELD_ALIASES.img),
422
- );
423
- }
424
417
  const warnings = [];
425
418
  const scene = buildScene(fm, {
426
419
  packageId: foundryPackageId(),
@@ -471,7 +464,7 @@ export class Scenes extends BasePackCompiler {
471
464
  this.places.set(placeKey, {
472
465
  key: placeKey,
473
466
  name: sohlField(fm, "placeName", null) || name,
474
- img: readAliasedField(fm, "img") ?? null,
467
+ img: sohlField(fm, "img", null),
475
468
  pinned: false,
476
469
  scenes: [],
477
470
  journal: [],