Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions test/deleted-section.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>): Record<string, unknown> => ({
...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<string, unknown>), 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<string, unknown>).physicality, "", JSON.stringify(r.sent));
});
5 changes: 5 additions & 0 deletions test/element-transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
});
3 changes: 2 additions & 1 deletion vault/element-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,8 @@ export function toV2WireKeys(element: Record<string, unknown>): Record<string, u
const out: Record<string, unknown> = {};
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
Expand Down
Loading