diff --git a/README.md b/README.md index 9c8427f..9746567 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ A player or guest may know of an element without seeing all of it: your Characte **World units.** `World.md` has a Units section: Length Unit, Mass Unit and Distance Unit, free text such as `cm`, `kg` or `leagues`. They are labels only; nothing converts. Properties shows the unit beside the nine numbers that use one: height and weight on Characters and Creatures, Creature speed, weight on Objects and Species, Ability range and Location elevation. Download world writes the server's units into `World.md`. Upload world sends them when you changed them; only the world's owner can. +**What a note leaves unsaid.** A field's section deleted from a note says nothing about the field: Save element sends nothing for it, the world keeps its text, and the next Download writes the section back. To clear a field, empty its section and leave the heading. The `### Depends on` section is written by the plugin from the element's dependency list and is never read: a line you type there (`- [[Name]]` reads as one the plugin wrote) is not sent, and the next Download writes the section again from the world's list, after keeping your note whole in `Kept edits` if you had typed in it. A link's alias (`[[Name|shown]]`) is only for reading: the plugin takes the name before the bar, and Download writes the element's own name back. A property of your own that ends in `_id` or `_ids` keeps its name when it goes to the world (`x_ship_id` stays `x_ship_id`). + The ribbon icon and the desktop status bar show the sync state: idle, dirty, syncing, synced or error. ## Bases diff --git a/test/deleted-section.test.ts b/test/deleted-section.test.ts new file mode 100644 index 0000000..6720039 --- /dev/null +++ b/test/deleted-section.test.ts @@ -0,0 +1,38 @@ +/** + * A note that lacks a field's section says nothing about that field; an emptied section says the field is empty (README, "What a + * note leaves unsaid"). Pinned so the sentence in the README stays true. + */ +import "./support/obsidian-shim"; // MUST stay first: routes `obsidian` to the mock +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { harnessSave } from "./support/save-harness"; +import { getCategorySchema } from "../vault/element-transform"; + +const ID = "0199c000-0000-7000-8000-0000000000b2"; +const whole = (over: Record): Record => ({ + ...Object.fromEntries(Object.keys(getCategorySchema("character") ?? {}).map((k) => [k, null])), + id: ID, + name: "Ireena", + ...over, +}); +const note = (physicality: string | null) => + `---\nname: Ireena\nid: ${ID}\nchange_seq: 5\n---\n\n### Description\n\nA noble.\n\n${physicality === null ? "" : `### Physicality\n\n${physicality}\n\n`}### Mentality\n\n\n`; +const save = (physicality: string | null) => + harnessSave({ + notes: { "Character/Ireena.md": note(physicality), "~/.ow-seq.json": JSON.stringify({ [ID]: 5 }) }, + save: "Character/Ireena.md", + server: { [ID]: whole({ description: "A noble.", physicality: "Tall.", change_seq: 5 }) }, + answer: { [ID]: whole({ description: "A noble.", physicality: "Tall.", change_seq: 6 }) }, + }); + +test("★ a deleted section sends nothing for its field: the world keeps the text", async () => { + const r = await save(null); + assert.equal(r.sent.length, 1, r.notices.join(" | ")); + assert.equal("physicality" in (r.sent[0] as Record), false, JSON.stringify(r.sent)); +}); + +test("the control: an emptied section clears the world's field (the run can send it)", async () => { + const r = await save(""); + assert.equal(r.sent.length, 1, r.notices.join(" | ")); + assert.equal((r.sent[0] as Record).physicality, "", JSON.stringify(r.sent)); +}); diff --git a/test/element-transform.test.ts b/test/element-transform.test.ts index f6d01bb..b22424f 100644 --- a/test/element-transform.test.ts +++ b/test/element-transform.test.ts @@ -1036,3 +1036,8 @@ test("character: the wire rename still strips v1 suffixes", () => { const out = toV2WireKeys({ location_id: "l1", abilities_ids: ["a"], world: "w" }); assert.deepEqual(out, { location: "l1", abilities: ["a"] }); }); + +test("★ an extension key ending in _id or _ids keeps its name on the wire (x_ship_id is not x_ship)", () => { + const out = toV2WireKeys({ x_ship_id: "1", atlas_foo_ids: ["2"], shadow_bar_id: "3", x_id_id: "4", location_id: "l1" }); + assert.deepEqual(out, { x_ship_id: "1", atlas_foo_ids: ["2"], shadow_bar_id: "3", x_id_id: "4", location: "l1" }); +}); diff --git a/vault/element-transform.ts b/vault/element-transform.ts index 993d6ab..277ab46 100644 --- a/vault/element-transform.ts +++ b/vault/element-transform.ts @@ -1487,7 +1487,8 @@ export function toV2WireKeys(element: Record): Record = {}; for (const [key, value] of Object.entries(element)) { if (key === "world" || key === "world_id") continue; - if (GENERIC_PAIR_KEYS.has(key)) { + // An extension key (x_, atlas_, shadow_) is no schema link field: `x_ship_id` stays `x_ship_id`, never `x_ship` (a second key). + if (GENERIC_PAIR_KEYS.has(key) || isExtensionKey(key)) { out[key] = value; } else if (key.endsWith("_ids") || key.endsWith("_id")) { // A stripped suffix names a link field. `id` and `world` are no link field: `id_id` is a text