taflor-protocol 0.1.0__tar.gz

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 (97) hide show
  1. taflor_protocol-0.1.0/.gitignore +16 -0
  2. taflor_protocol-0.1.0/PKG-INFO +109 -0
  3. taflor_protocol-0.1.0/README.md +101 -0
  4. taflor_protocol-0.1.0/conformance/FORMAT.md +117 -0
  5. taflor_protocol-0.1.0/conformance/v2/core/gm-only-key.yaml +52 -0
  6. taflor_protocol-0.1.0/conformance/v2/core/join.yaml +37 -0
  7. taflor_protocol-0.1.0/conformance/v2/core/object-create.yaml +24 -0
  8. taflor_protocol-0.1.0/conformance/v2/core/object-move.yaml +32 -0
  9. taflor_protocol-0.1.0/conformance/v2/core/protocol-mismatch.yaml +18 -0
  10. taflor_protocol-0.1.0/data/capabilities.json +80 -0
  11. taflor_protocol-0.1.0/index.js +33 -0
  12. taflor_protocol-0.1.0/package-lock.json +113 -0
  13. taflor_protocol-0.1.0/package.json +37 -0
  14. taflor_protocol-0.1.0/pyproject.toml +33 -0
  15. taflor_protocol-0.1.0/schemas/common/v1.json +110 -0
  16. taflor_protocol-0.1.0/schemas/conformance/v2/scenario.json +320 -0
  17. taflor_protocol-0.1.0/schemas/extension/v1.json +31 -0
  18. taflor_protocol-0.1.0/schemas/manifest/v1.json +391 -0
  19. taflor_protocol-0.1.0/schemas/protocol/v2/capabilities.json +36 -0
  20. taflor_protocol-0.1.0/schemas/protocol/v2/client/battlemap.remove.json +19 -0
  21. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.activate.json +19 -0
  22. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.add.json +24 -0
  23. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.begin.json +15 -0
  24. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.end.json +15 -0
  25. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.next.json +15 -0
  26. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.prev.json +15 -0
  27. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.remove.json +24 -0
  28. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.roll.json +48 -0
  29. taflor_protocol-0.1.0/schemas/protocol/v2/client/combat.set_initiative.json +25 -0
  30. taflor_protocol-0.1.0/schemas/protocol/v2/client/cursor.json +23 -0
  31. taflor_protocol-0.1.0/schemas/protocol/v2/client/cursor.leave.json +15 -0
  32. taflor_protocol-0.1.0/schemas/protocol/v2/client/die.roll.json +19 -0
  33. taflor_protocol-0.1.0/schemas/protocol/v2/client/die.set.json +26 -0
  34. taflor_protocol-0.1.0/schemas/protocol/v2/client/doc.create.json +52 -0
  35. taflor_protocol-0.1.0/schemas/protocol/v2/client/doc.delete.json +23 -0
  36. taflor_protocol-0.1.0/schemas/protocol/v2/client/doc.subscribe.json +35 -0
  37. taflor_protocol-0.1.0/schemas/protocol/v2/client/doc.update.json +32 -0
  38. taflor_protocol-0.1.0/schemas/protocol/v2/client/fog.reset.json +19 -0
  39. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.convert.json +29 -0
  40. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.create.json +62 -0
  41. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.delete.json +19 -0
  42. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.duplicate.json +31 -0
  43. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.preview.json +55 -0
  44. taflor_protocol-0.1.0/schemas/protocol/v2/client/object.update.json +41 -0
  45. taflor_protocol-0.1.0/schemas/protocol/v2/client/ping.json +23 -0
  46. taflor_protocol-0.1.0/schemas/protocol/v2/client/plugin.error.json +46 -0
  47. taflor_protocol-0.1.0/schemas/protocol/v2/client/presence.ping.json +29 -0
  48. taflor_protocol-0.1.0/schemas/protocol/v2/client/ruler.json +60 -0
  49. taflor_protocol-0.1.0/schemas/protocol/v2/client/saved_views.set.json +23 -0
  50. taflor_protocol-0.1.0/schemas/protocol/v2/client/showcase.hide.json +15 -0
  51. taflor_protocol-0.1.0/schemas/protocol/v2/client/showcase.show.json +19 -0
  52. taflor_protocol-0.1.0/schemas/protocol/v2/client/table.update.json +28 -0
  53. taflor_protocol-0.1.0/schemas/protocol/v2/client/tokens.gather.json +23 -0
  54. taflor_protocol-0.1.0/schemas/protocol/v2/client/view.pull.json +33 -0
  55. taflor_protocol-0.1.0/schemas/protocol/v2/client-message.json +585 -0
  56. taflor_protocol-0.1.0/schemas/protocol/v2/common.json +276 -0
  57. taflor_protocol-0.1.0/schemas/protocol/v2/envelope.json +18 -0
  58. taflor_protocol-0.1.0/schemas/protocol/v2/error.json +24 -0
  59. taflor_protocol-0.1.0/schemas/protocol/v2/object.json +76 -0
  60. taflor_protocol-0.1.0/schemas/protocol/v2/server/combat.json +26 -0
  61. taflor_protocol-0.1.0/schemas/protocol/v2/server/cursor.json +36 -0
  62. taflor_protocol-0.1.0/schemas/protocol/v2/server/cursor.leave.json +19 -0
  63. taflor_protocol-0.1.0/schemas/protocol/v2/server/dice.rolled.json +130 -0
  64. taflor_protocol-0.1.0/schemas/protocol/v2/server/doc.deleted.json +22 -0
  65. taflor_protocol-0.1.0/schemas/protocol/v2/server/doc.upserted.json +22 -0
  66. taflor_protocol-0.1.0/schemas/protocol/v2/server/looks.json +19 -0
  67. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.converted.json +25 -0
  68. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.created.json +23 -0
  69. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.deleted.json +19 -0
  70. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.duplicated.json +26 -0
  71. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.preview.json +27 -0
  72. taflor_protocol-0.1.0/schemas/protocol/v2/server/object.upserted.json +54 -0
  73. taflor_protocol-0.1.0/schemas/protocol/v2/server/ping.json +36 -0
  74. taflor_protocol-0.1.0/schemas/protocol/v2/server/presence.json +22 -0
  75. taflor_protocol-0.1.0/schemas/protocol/v2/server/presence.pong.json +19 -0
  76. taflor_protocol-0.1.0/schemas/protocol/v2/server/protocol.json +20 -0
  77. taflor_protocol-0.1.0/schemas/protocol/v2/server/ruler.json +47 -0
  78. taflor_protocol-0.1.0/schemas/protocol/v2/server/saved_views.updated.json +22 -0
  79. taflor_protocol-0.1.0/schemas/protocol/v2/server/showcase.json +26 -0
  80. taflor_protocol-0.1.0/schemas/protocol/v2/server/table.updated.json +19 -0
  81. taflor_protocol-0.1.0/schemas/protocol/v2/server/tokens.gathered.json +25 -0
  82. taflor_protocol-0.1.0/schemas/protocol/v2/server/view.pull.json +22 -0
  83. taflor_protocol-0.1.0/schemas/protocol/v2/server-message.json +425 -0
  84. taflor_protocol-0.1.0/schemas/protocol/v2/state.json +75 -0
  85. taflor_protocol-0.1.0/schemas/sheet/v1/message.json +156 -0
  86. taflor_protocol-0.1.0/taflor_protocol/__init__.py +91 -0
  87. taflor_protocol-0.1.0/tests/fixtures/conformance.json +166 -0
  88. taflor_protocol-0.1.0/tests/fixtures/extension.json +62 -0
  89. taflor_protocol-0.1.0/tests/fixtures/manifest.json +2332 -0
  90. taflor_protocol-0.1.0/tests/fixtures/protocol-client.json +1560 -0
  91. taflor_protocol-0.1.0/tests/fixtures/protocol-core.json +2570 -0
  92. taflor_protocol-0.1.0/tests/fixtures/protocol-server.json +1197 -0
  93. taflor_protocol-0.1.0/tests/fixtures/sheet.json +270 -0
  94. taflor_protocol-0.1.0/tests/schemas.test.js +115 -0
  95. taflor_protocol-0.1.0/tests/test_schemas.py +322 -0
  96. taflor_protocol-0.1.0/uv.lock +180 -0
  97. taflor_protocol-0.1.0/version.js +13 -0
@@ -0,0 +1,16 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ *.egg-info/
6
+ build/
7
+ dist/
8
+
9
+ # Node
10
+ node_modules/
11
+
12
+ # Website build output
13
+ website/dist/
14
+
15
+ # Local data of a development server (TABLE_DATA_DIR default)
16
+ server/.data/
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.5
2
+ Name: taflor-protocol
3
+ Version: 0.1.0
4
+ Summary: Taflor's wire protocol, plugin manifest and sheet protocol as JSON Schemas, plus the conformance scenarios
5
+ License-Expression: MPL-2.0
6
+ Requires-Python: >=3.14
7
+ Description-Content-Type: text/markdown
8
+
9
+ # @taflor/protocol
10
+
11
+ The protocol package of Taflor (SPEC §3.1, §6.10): the JSON Schemas of the websocket protocol, the
12
+ plugin manifest, the server extension descriptor and the sheet protocol, the capability catalogue,
13
+ and the conformance scenarios. It is the single source of these schemas: server validation, the
14
+ client's types and the conformance suite are generated from it or checked against it.
15
+
16
+ Published as npm `@taflor/protocol` and pip `taflor-protocol` (Python package `taflor_protocol`),
17
+ both MPL-2.0. Nothing is published yet.
18
+
19
+ ## Contents
20
+
21
+ | path | what |
22
+ |---|---|
23
+ | `schemas/protocol/v2/` | protocol version 2 (SPEC §6): `envelope`, `error`, `state`, `object`, one schema per message in `client/` and `server/`, the dispatchers `client-message.json` and `server-message.json`, shared `common.json`, and the schema of the capability catalogue |
24
+ | `schemas/manifest/v1.json` | the plugin manifest `table-plugin.json`, `manifestVersion` 1 (SPEC §7.3) |
25
+ | `schemas/extension/v1.json` | the server extension descriptor (SPEC §9.2) |
26
+ | `schemas/sheet/v1/message.json` | the sheet and panel protocol v1, postMessage (SPEC §7.14) |
27
+ | `schemas/conformance/v2/scenario.json` | the conformance scenario format (SPEC §13.2) |
28
+ | `schemas/common/v1.json` | ids, versions and paths shared by all of them |
29
+ | `data/capabilities.json` | the capability catalogue (SPEC §6.4) |
30
+ | `conformance/FORMAT.md`, `conformance/v2/<capability>/*.yaml` | the scenario format and the scenarios |
31
+
32
+ Every schema is JSON Schema draft 2020-12. Its `$id` is `https://taflor.org/schemas/` plus its path
33
+ in `schemas/`; the folder carries the version (`protocol/v2/`, `manifest/v1.json`), so an `$id`
34
+ never changes its meaning. A schema references others by absolute `$id`; load all of them into
35
+ your validator first.
36
+
37
+ ## Versions
38
+
39
+ ```python
40
+ from taflor_protocol import PROTOCOL_VERSION, API_VERSION # 2, "1.0.0"
41
+ ```
42
+
43
+ ```js
44
+ import { PROTOCOL_VERSION, API_VERSION } from "@taflor/protocol";
45
+ ```
46
+
47
+ `PROTOCOL_VERSION` is the wire protocol (SPEC §6.2), `API_VERSION` the plugin API (§3.7).
48
+
49
+ `version.js` holds these constants and imports nothing, so the browser client loads it as it is
50
+ (no build step); the package's `.` export resolves to it outside Node. `index.js`, the `.` export
51
+ in Node, re-exports them and adds the schema loaders, which need `node:fs`.
52
+
53
+ The package version is the product's: `scripts/version.py` keeps `package.json` and
54
+ `taflor_protocol.__version__` (which the wheel reads) equal to `VERSION` in the repository root.
55
+
56
+ ## Validating
57
+
58
+ Python (needs `jsonschema`):
59
+
60
+ ```python
61
+ from taflor_protocol import validator
62
+
63
+ validator("protocol/v2/client-message.json").validate(
64
+ {"type": "ping", "x": 10, "y": 20}
65
+ )
66
+ ```
67
+
68
+ Node, with any 2020-12 validator, e.g. ajv:
69
+
70
+ ```js
71
+ import Ajv2020 from "ajv/dist/2020.js";
72
+ import addFormats from "ajv-formats";
73
+ import { loadSchemas, BASE_URI } from "@taflor/protocol";
74
+
75
+ const ajv = new Ajv2020({ strictTypes: false });
76
+ addFormats(ajv);
77
+ ajv.addKeyword({ keyword: "x-taflor-open", schemaType: "string" });
78
+ for (const schema of loadSchemas().values()) ajv.addSchema(schema);
79
+ const check = ajv.getSchema(BASE_URI + "protocol/v2/client-message.json");
80
+ ```
81
+
82
+ ## Rules the schemas follow
83
+
84
+ - **Extra fields.** Messages accept fields they don't define, in both directions: adding an
85
+ optional field does not raise `PROTOCOL_VERSION` (SPEC §6.2), so an older reader must not refuse
86
+ it. Patches (`object.update`, `object.preview`) and the manifest refuse unknown keys.
87
+ - **Namespaced messages** (`x.<id>.<name>`) pass the dispatchers with any payload. Their payload
88
+ schema comes from the plugin manifest or the server extension (SPEC §6.6).
89
+ - **What a schema can't check** stays with the server or the install pipeline: who may send what,
90
+ limits that depend on the object (a die's sides), data depth and size, file contents and the
91
+ trust tier (SPEC §10.2, §10.4).
92
+ - **v1 limits.** Where SPEC names a v2 message without its fields, the fields and limits come from
93
+ protocol v1 (`server/taflor_server/protocol.py` and friends), since v2 keeps v1's message set
94
+ (SPEC §6.6).
95
+ - **Open points.** Where SPEC is silent or ambiguous, the schema says so in an
96
+ `"x-taflor-open"` annotation instead of guessing quietly. Validators ignore it; ajv needs it
97
+ registered as a keyword (see above).
98
+
99
+ ## Tests
100
+
101
+ ```sh
102
+ uv run python -m unittest discover -s tests # jsonschema
103
+ npm ci && npm test # ajv
104
+ ```
105
+
106
+ `scripts/check.sh` runs both as the unit `protocol`. Both check that every schema is valid 2020-12 and every `$ref` resolves, that each schema accepts
107
+ its valid fixtures (`tests/fixtures/*.json`) and refuses its invalid ones, that the dispatchers
108
+ list exactly the messages of SPEC §6.6, and that the conformance scenarios match their schema and
109
+ their `send` messages validate as client messages.
@@ -0,0 +1,101 @@
1
+ # @taflor/protocol
2
+
3
+ The protocol package of Taflor (SPEC §3.1, §6.10): the JSON Schemas of the websocket protocol, the
4
+ plugin manifest, the server extension descriptor and the sheet protocol, the capability catalogue,
5
+ and the conformance scenarios. It is the single source of these schemas: server validation, the
6
+ client's types and the conformance suite are generated from it or checked against it.
7
+
8
+ Published as npm `@taflor/protocol` and pip `taflor-protocol` (Python package `taflor_protocol`),
9
+ both MPL-2.0. Nothing is published yet.
10
+
11
+ ## Contents
12
+
13
+ | path | what |
14
+ |---|---|
15
+ | `schemas/protocol/v2/` | protocol version 2 (SPEC §6): `envelope`, `error`, `state`, `object`, one schema per message in `client/` and `server/`, the dispatchers `client-message.json` and `server-message.json`, shared `common.json`, and the schema of the capability catalogue |
16
+ | `schemas/manifest/v1.json` | the plugin manifest `table-plugin.json`, `manifestVersion` 1 (SPEC §7.3) |
17
+ | `schemas/extension/v1.json` | the server extension descriptor (SPEC §9.2) |
18
+ | `schemas/sheet/v1/message.json` | the sheet and panel protocol v1, postMessage (SPEC §7.14) |
19
+ | `schemas/conformance/v2/scenario.json` | the conformance scenario format (SPEC §13.2) |
20
+ | `schemas/common/v1.json` | ids, versions and paths shared by all of them |
21
+ | `data/capabilities.json` | the capability catalogue (SPEC §6.4) |
22
+ | `conformance/FORMAT.md`, `conformance/v2/<capability>/*.yaml` | the scenario format and the scenarios |
23
+
24
+ Every schema is JSON Schema draft 2020-12. Its `$id` is `https://taflor.org/schemas/` plus its path
25
+ in `schemas/`; the folder carries the version (`protocol/v2/`, `manifest/v1.json`), so an `$id`
26
+ never changes its meaning. A schema references others by absolute `$id`; load all of them into
27
+ your validator first.
28
+
29
+ ## Versions
30
+
31
+ ```python
32
+ from taflor_protocol import PROTOCOL_VERSION, API_VERSION # 2, "1.0.0"
33
+ ```
34
+
35
+ ```js
36
+ import { PROTOCOL_VERSION, API_VERSION } from "@taflor/protocol";
37
+ ```
38
+
39
+ `PROTOCOL_VERSION` is the wire protocol (SPEC §6.2), `API_VERSION` the plugin API (§3.7).
40
+
41
+ `version.js` holds these constants and imports nothing, so the browser client loads it as it is
42
+ (no build step); the package's `.` export resolves to it outside Node. `index.js`, the `.` export
43
+ in Node, re-exports them and adds the schema loaders, which need `node:fs`.
44
+
45
+ The package version is the product's: `scripts/version.py` keeps `package.json` and
46
+ `taflor_protocol.__version__` (which the wheel reads) equal to `VERSION` in the repository root.
47
+
48
+ ## Validating
49
+
50
+ Python (needs `jsonschema`):
51
+
52
+ ```python
53
+ from taflor_protocol import validator
54
+
55
+ validator("protocol/v2/client-message.json").validate(
56
+ {"type": "ping", "x": 10, "y": 20}
57
+ )
58
+ ```
59
+
60
+ Node, with any 2020-12 validator, e.g. ajv:
61
+
62
+ ```js
63
+ import Ajv2020 from "ajv/dist/2020.js";
64
+ import addFormats from "ajv-formats";
65
+ import { loadSchemas, BASE_URI } from "@taflor/protocol";
66
+
67
+ const ajv = new Ajv2020({ strictTypes: false });
68
+ addFormats(ajv);
69
+ ajv.addKeyword({ keyword: "x-taflor-open", schemaType: "string" });
70
+ for (const schema of loadSchemas().values()) ajv.addSchema(schema);
71
+ const check = ajv.getSchema(BASE_URI + "protocol/v2/client-message.json");
72
+ ```
73
+
74
+ ## Rules the schemas follow
75
+
76
+ - **Extra fields.** Messages accept fields they don't define, in both directions: adding an
77
+ optional field does not raise `PROTOCOL_VERSION` (SPEC §6.2), so an older reader must not refuse
78
+ it. Patches (`object.update`, `object.preview`) and the manifest refuse unknown keys.
79
+ - **Namespaced messages** (`x.<id>.<name>`) pass the dispatchers with any payload. Their payload
80
+ schema comes from the plugin manifest or the server extension (SPEC §6.6).
81
+ - **What a schema can't check** stays with the server or the install pipeline: who may send what,
82
+ limits that depend on the object (a die's sides), data depth and size, file contents and the
83
+ trust tier (SPEC §10.2, §10.4).
84
+ - **v1 limits.** Where SPEC names a v2 message without its fields, the fields and limits come from
85
+ protocol v1 (`server/taflor_server/protocol.py` and friends), since v2 keeps v1's message set
86
+ (SPEC §6.6).
87
+ - **Open points.** Where SPEC is silent or ambiguous, the schema says so in an
88
+ `"x-taflor-open"` annotation instead of guessing quietly. Validators ignore it; ajv needs it
89
+ registered as a keyword (see above).
90
+
91
+ ## Tests
92
+
93
+ ```sh
94
+ uv run python -m unittest discover -s tests # jsonschema
95
+ npm ci && npm test # ajv
96
+ ```
97
+
98
+ `scripts/check.sh` runs both as the unit `protocol`. Both check that every schema is valid 2020-12 and every `$ref` resolves, that each schema accepts
99
+ its valid fixtures (`tests/fixtures/*.json`) and refuses its invalid ones, that the dispatchers
100
+ list exactly the messages of SPEC §6.6, and that the conformance scenarios match their schema and
101
+ their `send` messages validate as client messages.
@@ -0,0 +1,117 @@
1
+ # Conformance scenarios
2
+
3
+ A scenario describes one behaviour of the table protocol that every server and host has to show
4
+ (SPEC §13.2): a table set up with seats and objects, then messages sent and the messages each seat
5
+ must, or must never, receive. Runners play the scenarios against a server: in process against
6
+ `taflor_server`, over the network against any server started with `TABLE_CONFORMANCE=1`, and in
7
+ process against `OfflineSync`. The runners don't exist yet.
8
+
9
+ Files live in `conformance/v<PROTOCOL_VERSION>/<capability>/<scenario>.yaml` and validate against
10
+ the JSON Schema `https://taflor.org/schemas/conformance/v2/scenario.json`. A server claims a
11
+ capability only if it passes every scenario in that capability's folder.
12
+
13
+ ## Example
14
+
15
+ ```yaml
16
+ scenario: object-move # = the file name
17
+ title: A player moves the token they control; others may not
18
+ capability: core # = the folder name
19
+ protocol: 2
20
+ spec: ["§5.3", "§6.7"] # optional: what it checks
21
+ fixture:
22
+ seats:
23
+ gm: {role: gm}
24
+ alice: {role: player}
25
+ bob: {role: player}
26
+ objects:
27
+ - {ref: mira, kind: token, name: Mira, x: 100, y: 100, controlled_by: ["@alice"]}
28
+ steps:
29
+ - send:
30
+ from: alice
31
+ message: {type: object.update, id: "@mira", patch: {x: 160, y: 120}}
32
+ - expect:
33
+ to: all
34
+ message: {type: object.upserted, object: {id: "@mira", x: 160}}
35
+ - send:
36
+ from: bob
37
+ message: {type: object.update, id: "@mira", patch: {x: 0, y: 0}}
38
+ - expect:
39
+ to: bob
40
+ message: {type: error, code: "@*"}
41
+ - never:
42
+ to: all
43
+ message: {type: object.upserted, object: {id: "@mira", x: 0}}
44
+ ```
45
+
46
+ ## Fixture
47
+
48
+ - `table` (optional): `name`, `capabilities` (default: every core capability of
49
+ `data/capabilities.json`) and `settings`.
50
+ - `seats`: the users at the table by ref. `role` is `gm`, `player`, `viewer` or `denied`.
51
+ `anonymous: true` (viewers only) gives a visitor without a user id. `protocol` is the `?v=` the
52
+ seat connects with (default: the scenario's `protocol`). `connect: false` keeps the seat off
53
+ the table; it is there for its user id only. The ref `all` is reserved.
54
+ - `policies`: data-key policies (SPEC §5.3) the table has, as a host or plugin would declare them.
55
+ - `objects`: objects on the table before the first step, each with a `ref` and a `kind`. Fields not
56
+ given take the kind's defaults. `"@alice"` stands for the user id of seat `alice`.
57
+
58
+ Before the first step every seat with `connect` true connects, in the order given. The messages it
59
+ receives from then on, `state` included, go into its inbox.
60
+
61
+ ## Steps
62
+
63
+ Each step is an object with exactly one key.
64
+
65
+ | step | fields | meaning |
66
+ |---|---|---|
67
+ | `send` | `from`, `message` | the seat sends the message |
68
+ | `expect` | `to`, `message` | each seat in `to` receives a message that matches |
69
+ | `never` | `to`, `message` | no seat in `to` receives a matching message from the last `send` before this step to the end of the scenario (from connecting when there is none) |
70
+ | `expectClose` | `to`, `code` | the server closes each seat's socket with this close code |
71
+
72
+ `to` is a seat ref, a list of refs, or `all` (every seat that connected).
73
+
74
+ **Ordering per recipient.** Every seat's inbox is read in order. An `expect` looks at the messages
75
+ after the one the seat's previous `expect` matched and takes the first that matches; messages it
76
+ skips over are fine. So two `expect`s for one seat must come in the order the seat receives the
77
+ messages, while the order between seats is free. A runner waits for a matching message up to its
78
+ timeout, then fails the step.
79
+
80
+ **Settling.** Before the scenario ends, the runner waits until no message has arrived for its
81
+ settle time, then checks every `never`.
82
+
83
+ ## Matcher
84
+
85
+ A `message` in `expect` and `never` is a pattern:
86
+
87
+ - Objects match partially: every key in the pattern must match, other keys of the message are
88
+ ignored.
89
+ - Arrays match element by element and must have the same length. For other checks use the
90
+ operators below.
91
+ - Numbers match by value (`1` matches `1.0`). Other scalars must be equal.
92
+ - Strings starting with `@` are special:
93
+
94
+ | pattern | matches |
95
+ |---|---|
96
+ | `"@alice"` | the value the ref stands for: a seat's user id, a fixture object's id, or a bound value |
97
+ | `"@=name"` | any value, and binds it to `name` (the first match wins); later steps use `"@name"` |
98
+ | `"@*"` | any value, the key must be present |
99
+ | `"@absent"` | the key must be missing (only as the value of an object key) |
100
+ | `"@@text"` | the literal string `@text` |
101
+
102
+ - An object whose keys all start with `@` is a set of array operators, all of which must hold:
103
+
104
+ | operator | matches an array that |
105
+ |---|---|
106
+ | `{"@contains": [p, …]}` | has, for every pattern `p`, a different element matching it, in any order |
107
+ | `{"@excludes": [p, …]}` | has no element matching any of the patterns |
108
+
109
+ Refs in `send` messages are replaced by their values before sending. A ref that is not defined by
110
+ the fixture or bound by an earlier step is an error of the scenario.
111
+
112
+ ## Schema checks
113
+
114
+ Every `send` message, with its refs replaced, MUST validate against
115
+ `protocol/v2/client-message.json`; the package's tests check that. Patterns are partial, so the
116
+ runner validates every message a seat actually receives against
117
+ `protocol/v2/server-message.json` instead.
@@ -0,0 +1,52 @@
1
+ scenario: gm-only-key
2
+ title: A GM-only data key and a hidden token never reach players
3
+ description: >-
4
+ The policy is the example of SPEC §5.3. The GM sets the key and later hides the token: players
5
+ get the object without the key, then object.deleted, and never the key or the hidden object.
6
+ capability: core
7
+ protocol: 2
8
+ spec: ["§5.3", "§6.7"]
9
+ fixture:
10
+ seats:
11
+ gm: {role: gm}
12
+ alice: {role: player}
13
+ policies:
14
+ - {kind: token, key: health, writable_by: controller, visible_to: all}
15
+ - {kind: token, key: hide_status, writable_by: gm, visible_to: gm}
16
+ objects:
17
+ - {ref: goblin, kind: token, name: Goblin, x: 0, y: 0, data: {health: {value: 7, max: 7}}}
18
+ steps:
19
+ - send:
20
+ from: gm
21
+ message: {type: object.update, id: "@goblin", patch: {data: {hide_status: true}}}
22
+ - expect:
23
+ to: gm
24
+ message:
25
+ type: object.upserted
26
+ object: {id: "@goblin", data: {hide_status: true, health: {value: 7}}}
27
+ - expect:
28
+ to: alice
29
+ message:
30
+ type: object.upserted
31
+ object: {id: "@goblin", data: {hide_status: "@absent", health: {value: 7}}}
32
+ - never:
33
+ to: alice
34
+ message:
35
+ type: object.upserted
36
+ object: {data: {hide_status: "@*"}}
37
+ - send:
38
+ from: gm
39
+ message: {type: object.update, id: "@goblin", patch: {hidden: true}}
40
+ - expect:
41
+ to: gm
42
+ message:
43
+ type: object.upserted
44
+ object: {id: "@goblin", hidden: true}
45
+ - expect:
46
+ to: alice
47
+ message: {type: object.deleted, id: "@goblin"}
48
+ - never:
49
+ to: alice
50
+ message:
51
+ type: object.upserted
52
+ object: {id: "@goblin"}
@@ -0,0 +1,37 @@
1
+ scenario: join
2
+ title: Every seat gets a state shaped for its role
3
+ description: >-
4
+ The GM sees the hidden token, the player and the anonymous viewer do not. The viewer has no
5
+ user id.
6
+ capability: core
7
+ protocol: 2
8
+ spec: ["§4.3", "§6.4", "§6.7"]
9
+ fixture:
10
+ seats:
11
+ gm: {role: gm}
12
+ alice: {role: player}
13
+ visitor: {role: viewer, anonymous: true}
14
+ objects:
15
+ - {ref: map, kind: map, name: Ruins, x: 0, y: 0, width: 1200, height: 800, layer: map}
16
+ - {ref: trap, kind: token, name: Trap, x: 300, y: 200, hidden: true}
17
+ steps:
18
+ - expect:
19
+ to: gm
20
+ message:
21
+ type: state
22
+ me: {user_id: "@gm", role: gm, is_gm: true}
23
+ capabilities: {"@contains": [core]}
24
+ objects: {"@contains": [{id: "@map"}, {id: "@trap", hidden: true}]}
25
+ - expect:
26
+ to: alice
27
+ message:
28
+ type: state
29
+ me: {user_id: "@alice", role: player, is_gm: false}
30
+ objects: {"@contains": [{id: "@map"}], "@excludes": [{id: "@trap"}]}
31
+ - expect:
32
+ to: visitor
33
+ message:
34
+ type: state
35
+ me: {user_id: null, role: viewer, is_gm: false}
36
+ objects: {"@excludes": [{id: "@trap"}]}
37
+ saved_views: []
@@ -0,0 +1,24 @@
1
+ scenario: object-create
2
+ title: A created object reaches everyone, the answer only the sender
3
+ capability: core
4
+ protocol: 2
5
+ spec: ["§6.3", "§6.6"]
6
+ fixture:
7
+ seats:
8
+ gm: {role: gm}
9
+ alice: {role: player}
10
+ steps:
11
+ - send:
12
+ from: gm
13
+ message: {type: object.create, request: c1, kind: note, x: 40, y: 60, name: Clue}
14
+ - expect:
15
+ to: gm
16
+ message: {type: object.created, request: c1, id: "@=clue"}
17
+ - expect:
18
+ to: alice
19
+ message:
20
+ type: object.upserted
21
+ object: {id: "@clue", kind: note, name: Clue, hidden: false}
22
+ - never:
23
+ to: alice
24
+ message: {type: object.created}
@@ -0,0 +1,32 @@
1
+ scenario: object-move
2
+ title: A player moves the token they control; others may not
3
+ capability: core
4
+ protocol: 2
5
+ spec: ["§5.3", "§6.3", "§6.7"]
6
+ fixture:
7
+ seats:
8
+ gm: {role: gm}
9
+ alice: {role: player}
10
+ bob: {role: player}
11
+ objects:
12
+ - {ref: mira, kind: token, name: Mira, x: 100, y: 100, controlled_by: ["@alice"]}
13
+ steps:
14
+ - send:
15
+ from: alice
16
+ message: {type: object.update, id: "@mira", patch: {x: 160, y: 120}}
17
+ - expect:
18
+ to: all
19
+ message:
20
+ type: object.upserted
21
+ object: {id: "@mira", x: 160, y: 120, controlled_by: ["@alice"]}
22
+ - send:
23
+ from: bob
24
+ message: {type: object.update, id: "@mira", patch: {x: 0, y: 0}}
25
+ - expect:
26
+ to: bob
27
+ message: {type: error, code: "@*", id: "@mira"}
28
+ - never:
29
+ to: all
30
+ message:
31
+ type: object.upserted
32
+ object: {id: "@mira", x: 0}
@@ -0,0 +1,18 @@
1
+ scenario: protocol-mismatch
2
+ title: A client with another protocol version gets the server's version and close 4426
3
+ capability: core
4
+ protocol: 2
5
+ spec: ["§6.2", "§6.3"]
6
+ fixture:
7
+ seats:
8
+ old: {role: player, protocol: 1}
9
+ steps:
10
+ - expect:
11
+ to: old
12
+ message: {type: protocol, version: 2}
13
+ - expectClose:
14
+ to: old
15
+ code: 4426
16
+ - never:
17
+ to: old
18
+ message: {type: state}
@@ -0,0 +1,80 @@
1
+ {
2
+ "$schema": "https://taflor.org/schemas/protocol/v2/capabilities.json",
3
+ "capabilities": [
4
+ {
5
+ "name": "core",
6
+ "description": "The table itself: objects, layers, pings, rulers, the showcase, saved views and table settings. Every table has it; it gates nothing.",
7
+ "gates": [],
8
+ "since": "1.0.0"
9
+ },
10
+ {
11
+ "name": "players",
12
+ "description": "Player seats and player permissions. Without it the host seats no players (a GM-only table such as a master table) and the client hides the players tab; it gates no message.",
13
+ "gates": [],
14
+ "since": "1.0.0"
15
+ },
16
+ {
17
+ "name": "fog",
18
+ "description": "Fog of war on battlemaps.",
19
+ "gates": ["fog.reset"],
20
+ "since": "1.0.0"
21
+ },
22
+ {
23
+ "name": "combat",
24
+ "description": "The combat tracker and initiative.",
25
+ "gates": ["combat.*", "combat"],
26
+ "since": "1.0.0"
27
+ },
28
+ {
29
+ "name": "dice",
30
+ "description": "Placed dice: die objects, set and rolled on the table with the server's RNG (SPEC §8.5).",
31
+ "gates": ["die.set", "die.roll"],
32
+ "kinds": ["die"],
33
+ "since": "1.0.0"
34
+ },
35
+ {
36
+ "name": "paths",
37
+ "description": "Path objects (drawn lines and routes).",
38
+ "gates": [],
39
+ "kinds": ["path"],
40
+ "since": "1.0.0"
41
+ },
42
+ {
43
+ "name": "gminfo",
44
+ "description": "GM info objects: text only the GM sees, and turning notes into GM info and back.",
45
+ "gates": ["object.convert"],
46
+ "kinds": ["gminfo"],
47
+ "since": "1.0.0"
48
+ },
49
+ {
50
+ "name": "presence",
51
+ "description": "Who is at the table.",
52
+ "gates": ["presence.ping", "presence.pong", "presence"],
53
+ "since": "1.0.0"
54
+ },
55
+ {
56
+ "name": "cursors",
57
+ "description": "Other users' cursors.",
58
+ "gates": ["cursor", "cursor.leave"],
59
+ "since": "1.0.0"
60
+ },
61
+ {
62
+ "name": "view-pull",
63
+ "description": "The GM pulls everyone's view to theirs.",
64
+ "gates": ["view.pull"],
65
+ "since": "1.0.0"
66
+ },
67
+ {
68
+ "name": "docs",
69
+ "description": "The document store (SPEC §5.5).",
70
+ "gates": ["doc.*"],
71
+ "since": "1.0.0"
72
+ },
73
+ {
74
+ "name": "rolls",
75
+ "description": "The game keeps a roll log (TableHost.roll_log, SPEC §8.5): the dice log and its history over HTTP (§6.9). dice.rolled is sent with or without it; it gates no message.",
76
+ "gates": [],
77
+ "since": "1.0.0"
78
+ }
79
+ ]
80
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Taflor's protocol package: versions, the JSON Schemas and the conformance scenarios.
3
+ * The schemas are the normative definition of the wire protocol, the plugin manifest and the
4
+ * sheet protocol (SPEC §6.1, §6.10). This module only locates and loads them; validate with any
5
+ * JSON Schema 2020-12 validator. It needs Node (node:fs); browsers import version.js, which the
6
+ * package's "." export resolves to outside Node.
7
+ */
8
+ import { readFileSync, readdirSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ export { API_VERSION, BASE_URI, PROTOCOL_VERSION } from "./version.js";
13
+
14
+ const here = fileURLToPath(new URL(".", import.meta.url));
15
+ export const schemaDir = join(here, "schemas");
16
+ export const conformanceDir = join(here, "conformance");
17
+
18
+ /** @returns {Map<string, object>} all schemas, keyed by `$id` */
19
+ export function loadSchemas() {
20
+ const schemas = new Map();
21
+ for (const file of readdirSync(schemaDir, { recursive: true }).sort()) {
22
+ if (!String(file).endsWith(".json")) continue;
23
+ const data = JSON.parse(readFileSync(join(schemaDir, String(file)), "utf8"));
24
+ schemas.set(data.$id, data);
25
+ }
26
+ return schemas;
27
+ }
28
+
29
+ /** @returns {Map<string, object>} the capability catalogue (SPEC §6.4), keyed by name */
30
+ export function capabilities() {
31
+ const data = JSON.parse(readFileSync(join(here, "data", "capabilities.json"), "utf8"));
32
+ return new Map(data.capabilities.map((entry) => [entry.name, entry]));
33
+ }