@simetrajs/designer 0.1.0 → 0.3.0-next.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/README.md +39 -4
- package/dist/{command-CRUaUglx.js → command-CHk1P9Dp.js} +91 -108
- package/dist/default-dir-DerxTbci.js +158 -0
- package/dist/errors-D1P2kKbL.js +62 -0
- package/dist/init-jr0Xsrpp.js +832 -0
- package/dist/invoke-BwP_5iN6.js +2676 -0
- package/dist/main.js +6 -6
- package/dist/mcp-args-D63akJ97.js +56 -0
- package/dist/mcp-jLOz0W7f.js +219 -0
- package/dist/package-hA0J8AMK.js +4 -0
- package/dist/{schema-engine-DAsJEc8K.js → schema-engine-8rVHcVYO.js} +704 -195
- package/dist/{types-CSc8XWLd.js → types-CMcZhIci.js} +8 -3
- package/package.json +16 -12
- package/skills/simetra-adoption/SKILL.md +82 -3
- package/skills/simetra-metadata/SKILL.md +126 -136
- package/skills/simetra-metadata/references/agents-over-mcp.md +236 -0
- package/skills/simetra-metadata/references/attribute-load-and-size.md +57 -0
- package/skills/simetra-metadata/references/list-order-indexes.md +17 -0
- package/skills/simetra-metadata/references/object-modules.md +78 -0
- package/skills/simetra-metadata/references/people-and-rights.md +702 -9
- package/skills/simetra-metadata/references/plan-and-apply.md +81 -0
- package/skills/simetra-metadata/references/project-setup.md +28 -0
- package/skills/simetra-metadata/references/row-version-epoch.md +39 -0
- package/skills/simetra-metadata/references/search-fields.md +28 -0
- package/skills/simetra-metadata/references/sql-trust-boundary.md +225 -0
- package/dist/errors-D5pJLrjP.js +0 -36
- package/dist/mcp-CJDCleh-.js +0 -241
- package/dist/package-DDuGk6yE.js +0 -5
- package/dist/report-D2jBS_04.js +0 -1550
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Agents over MCP
|
|
2
|
+
|
|
3
|
+
Contents: launch flags; data of the development database (connect, flags,
|
|
4
|
+
examples, tabular section arrays, the database marker, limits).
|
|
5
|
+
|
|
6
|
+
`simetra mcp` serves the tool catalog to an agent over stdio. `simetra init`
|
|
7
|
+
writes its entry in the MCP client config; flags added to that entry's `args`
|
|
8
|
+
are kept on the next `init`.
|
|
9
|
+
|
|
10
|
+
## Launch flags
|
|
11
|
+
|
|
12
|
+
- By default the write tools change files in the served directory, under the
|
|
13
|
+
same rules as the CLI: the metadata is in git, and nothing is written unless
|
|
14
|
+
the result compiles. `--read-only` is a flag of `simetra mcp` only; the CLI
|
|
15
|
+
has none (preview with `--dry-run`).
|
|
16
|
+
- With `--read-only` every tool is still listed, but a write tool is refused
|
|
17
|
+
with a hint to remove `--read-only` from the server's args. Ask the owner
|
|
18
|
+
before restarting the server without it.
|
|
19
|
+
- `apply` and `roles` write to the database only when the server runs with
|
|
20
|
+
`--allow-database-write`; without it they are refused with a hint to add
|
|
21
|
+
the flag. Ask the owner; never add it yourself. `--read-only` refuses
|
|
22
|
+
`plan` and `apply` too: they write their files under `plans/`.
|
|
23
|
+
- `plan` and `apply` have no `dryRun`: review with `plan`, and check on the
|
|
24
|
+
database with `rehearse`.
|
|
25
|
+
|
|
26
|
+
## Data of the development database
|
|
27
|
+
|
|
28
|
+
`data-read` and `data-command` read and change application data through the
|
|
29
|
+
same runtime commands as the application server, as the user named by `--as`
|
|
30
|
+
and with that user's rights. `--agent <uuid>` only records the agent in the
|
|
31
|
+
session (`act` claim); it grants nothing. Use them to seed test data, to
|
|
32
|
+
check what different users may see and do, and to reproduce a bug.
|
|
33
|
+
|
|
34
|
+
The owner turns them on by adding flags to the server's `args` in the MCP
|
|
35
|
+
client config; `simetra init` does not add them, because the user and the
|
|
36
|
+
variable are the owner's choice. The CLI takes the same flags per call:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pnpm exec simetra mcp --data-url-env SIMETRA_DEV_DATA_URL --as <user-uuid>
|
|
40
|
+
pnpm exec simetra mcp --data-url-env SIMETRA_DEV_DATA_URL --as <user-uuid> --allow-data-write
|
|
41
|
+
pnpm exec simetra data-read '{"query":{"object":{"kind":"Catalog","name":"Currency"},"limit":50}}' --data-url-env SIMETRA_DEV_DATA_URL --as <user-uuid>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- The variable holds the connection string of the runtime login role
|
|
45
|
+
`simetra_runtime` (the platform gives it no password: the owner sets one on
|
|
46
|
+
the development database). A login that is a superuser, bypasses RLS, or
|
|
47
|
+
belongs to the migrator or the provider's service role is refused.
|
|
48
|
+
- Without `--data-url-env` and `--as` the data tools are refused with a hint;
|
|
49
|
+
there is no default variable.
|
|
50
|
+
- `--allow-data-write` (MCP only): without it `data-command` is refused with a
|
|
51
|
+
hint. Ask the owner; never add it yourself. The CLI writes data without it:
|
|
52
|
+
the person who runs the command is the decision. `--read-only` refuses
|
|
53
|
+
`data-command` and keeps `data-read`.
|
|
54
|
+
- `--allow-rights-write` (MCP and CLI): without it `data-command` refuses to
|
|
55
|
+
write the rights catalogs (roles, role assignments) and to create a scope
|
|
56
|
+
root whose creator receives a role. Membership catalogs are written without
|
|
57
|
+
it, under the rights of `--as`; active membership is what makes a role
|
|
58
|
+
assignment effective, so writing membership still changes who holds rights.
|
|
59
|
+
- An object with a module (`<Name>.module.ts` next to its `.meta.json`) is
|
|
60
|
+
refused with `command.invalid`, reason `object-module`, until a later
|
|
61
|
+
version: the tools do not load modules, so its hooks would not run.
|
|
62
|
+
Creating a scope root whose creator receives a role (with or without
|
|
63
|
+
`creatorMember`) also inserts the creator's membership row, so it needs both
|
|
64
|
+
`--allow-data-write` and `--allow-rights-write`, and it is refused the same
|
|
65
|
+
way when the membership catalog of that scope kind has a module.
|
|
66
|
+
- Every call compiles the directory and checks it against the applied model.
|
|
67
|
+
After a metadata change the call gets `command.model-mismatch` until you
|
|
68
|
+
`plan` and `apply` it.
|
|
69
|
+
- A runtime refusal comes back as `error` with a `code` (and a `reason`);
|
|
70
|
+
`BigInt` values come as decimal strings and may be passed back as strings.
|
|
71
|
+
`DateTime` values come in UTC as `YYYY-MM-DDTHH:MM:SS.ffffffZ`.
|
|
72
|
+
- `data-command` returns `{ rows, changes }`: one row per operation, in the
|
|
73
|
+
shape of a card read. The tabular sections that the operation wrote come
|
|
74
|
+
under `tabularSections.<name>`, not at the top level of the row.
|
|
75
|
+
|
|
76
|
+
A query takes one of these forms:
|
|
77
|
+
|
|
78
|
+
- a card `{ object, id, tabularSections?, include? }` — the whole row;
|
|
79
|
+
- a page `{ object, where?, orderBy?, offset?, limit, include? }`;
|
|
80
|
+
- a count `{ object, where?, count: true }`;
|
|
81
|
+
- the lines of an owner `{ object, tabularSection, owner }`;
|
|
82
|
+
- a page of lines `{ object, tabularSection, where?, orderBy?, offset?, limit }`;
|
|
83
|
+
- a count of lines `{ object, tabularSection, where?, count: true }`.
|
|
84
|
+
|
|
85
|
+
The result is `{ rows, included?, ownerVersion? }` or `{ count, capped? }`;
|
|
86
|
+
a count stops at 10000 and then comes `capped`.
|
|
87
|
+
|
|
88
|
+
- `where` is a tree: `{ "and": [...] }`, `{ "or": [...] }`, `{ "not": ... }`
|
|
89
|
+
and conditions `{ "attribute", "op", "value" }`. Operators: `eq`, `ne`,
|
|
90
|
+
`lt`, `lte`, `gt`, `gte`, `in` (up to 200 values), `isNull` (no value),
|
|
91
|
+
`contains` and `startsWith` (strings, case-insensitive). `eq` or `ne` with
|
|
92
|
+
`null` is refused (reason `use-isNull`): use `isNull`.
|
|
93
|
+
- An attribute is a logical name, the key name or the version name. A
|
|
94
|
+
polymorphic reference takes `{ "type": "<Kind>.<Name>", "id" }`.
|
|
95
|
+
- `orderBy` takes up to 4 attributes; the key goes only last, and without it
|
|
96
|
+
the server adds the key ascending. `limit` is 1 to 200; `offset` is up to
|
|
97
|
+
10000, past it page by a key condition (`{ "attribute": "<key>", "op":
|
|
98
|
+
"gt", "value": <last key> }`). That condition holds only for a page sorted
|
|
99
|
+
by the key alone. With `orderBy` on an attribute, the condition covers the
|
|
100
|
+
whole sort tuple plus the key, from the last row of the previous page. For
|
|
101
|
+
`orderBy: [{ "attribute": "code", "direction": "asc" }]`:
|
|
102
|
+
`{ "or": [{ "attribute": "code", "op": "gt", "value": <last code> },
|
|
103
|
+
{ "and": [{ "attribute": "code", "op": "eq", "value": <last code> },
|
|
104
|
+
{ "attribute": "<key>", "op": "gt", "value": <last key> }] }] }`.
|
|
105
|
+
- A page leaves out lazy attributes (`load: "lazy"`, `Bytes` by default);
|
|
106
|
+
a card returns them. Filter or sort by a lazy attribute is refused (reason
|
|
107
|
+
`lazy`).
|
|
108
|
+
- `include` names up to 16 single-target `Ref` attributes. The rows they
|
|
109
|
+
reference, as the user may see them, come in `included` under
|
|
110
|
+
`"<Kind>.<Name>"` of the target; an invisible target is just missing. A
|
|
111
|
+
page cannot include a lazy `Ref` (reason `lazy`).
|
|
112
|
+
- `tabularSections` (`true` or a list of names) puts the lines of a card
|
|
113
|
+
under `tabularSections.<name>`, ordered by line number. The lines of an
|
|
114
|
+
owner come with `ownerVersion`, read by the same statement; an invisible
|
|
115
|
+
owner gives `{ "rows": [] }` without it. A section over 5000 lines is
|
|
116
|
+
refused (reason `tabular-too-large`, `path` — the section), never cut.
|
|
117
|
+
- A page of lines filters by the owner (`parent`), the line number and the
|
|
118
|
+
section attributes, ordered by line number by default. With a top-level
|
|
119
|
+
`parent eq <id>` it also returns `ownerVersion`, and its count is not
|
|
120
|
+
capped.
|
|
121
|
+
|
|
122
|
+
Read a page of rows:
|
|
123
|
+
|
|
124
|
+
```json simetra:data-read
|
|
125
|
+
{
|
|
126
|
+
"query": {
|
|
127
|
+
"object": { "kind": "Catalog", "name": "Currency" },
|
|
128
|
+
"where": { "attribute": "symbol", "op": "eq", "value": "$" },
|
|
129
|
+
"orderBy": [{ "attribute": "description", "direction": "asc" }],
|
|
130
|
+
"limit": 50
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Read the lines of one owner with the owner version:
|
|
136
|
+
|
|
137
|
+
```json simetra:data-read
|
|
138
|
+
{
|
|
139
|
+
"query": {
|
|
140
|
+
"object": { "kind": "Document", "name": "Invoice" },
|
|
141
|
+
"tabularSection": "lines",
|
|
142
|
+
"owner": "0b9d4c5e-8f1a-4c3b-9e2d-6a7f8b9c0d1e"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Read a card with the rows its references point to:
|
|
148
|
+
|
|
149
|
+
```json simetra:data-read
|
|
150
|
+
{
|
|
151
|
+
"query": {
|
|
152
|
+
"object": { "kind": "Document", "name": "Invoice" },
|
|
153
|
+
"id": "0b9d4c5e-8f1a-4c3b-9e2d-6a7f8b9c0d1e",
|
|
154
|
+
"include": ["customer", "currency"]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Seed rows in one transaction (`id` is a new UUID you generate; `update`,
|
|
160
|
+
`markDeletion` and `delete` also need `expectedVersion`):
|
|
161
|
+
|
|
162
|
+
```json simetra:data-command
|
|
163
|
+
{
|
|
164
|
+
"operations": [
|
|
165
|
+
{
|
|
166
|
+
"action": "create",
|
|
167
|
+
"object": { "kind": "Catalog", "name": "Currency" },
|
|
168
|
+
"id": "0b9d4c5e-8f1a-4c3b-9e2d-6a7f8b9c0d1e",
|
|
169
|
+
"values": { "description": "US dollar", "symbol": "$" }
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A tabular section array in `update` replaces the section. Name every
|
|
176
|
+
existing line by its key (`ref`), either in the array or in `deleteIds`;
|
|
177
|
+
otherwise the command is refused with `command.invalid`, reason
|
|
178
|
+
`tabular-rows-missing`, `path` — the section. Build the array only from a
|
|
179
|
+
card read with that section or from the lines of the owner, and pass the
|
|
180
|
+
`ownerVersion` you read as `expectedVersion`. A line in both the array and
|
|
181
|
+
`deleteIds` is refused; an id in `deleteIds` that is already gone is
|
|
182
|
+
ignored. Keep one line and delete another:
|
|
183
|
+
|
|
184
|
+
```json simetra:data-command
|
|
185
|
+
{
|
|
186
|
+
"operations": [
|
|
187
|
+
{
|
|
188
|
+
"action": "update",
|
|
189
|
+
"object": { "kind": "Document", "name": "Invoice" },
|
|
190
|
+
"id": "0b9d4c5e-8f1a-4c3b-9e2d-6a7f8b9c0d1e",
|
|
191
|
+
"expectedVersion": 3,
|
|
192
|
+
"tabularSections": {
|
|
193
|
+
"lines": [
|
|
194
|
+
{ "ref": "6f1c2a3b-4d5e-4f60-8a7b-9c0d1e2f3a4b", "quantity": 2 }
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
"deleteIds": { "lines": ["7a2b3c4d-5e6f-4a70-8b8c-9d0e1f2a3b4c"] }
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
A set of lines over the tabular section limit (5000 lines), or one that is
|
|
204
|
+
edited in parts, does not belong in a tabular section: model it as a
|
|
205
|
+
separate object or a register.
|
|
206
|
+
|
|
207
|
+
Limits of one `data-command`, checked before the database is touched; each
|
|
208
|
+
refusal is `command.invalid` with the `reason` below:
|
|
209
|
+
|
|
210
|
+
- up to 500 operations (`batch-too-large`); split a larger seed into
|
|
211
|
+
several calls, each its own transaction;
|
|
212
|
+
- up to 5000 lines in one tabular section of an operation
|
|
213
|
+
(`tabular-too-large`, `path` — the section);
|
|
214
|
+
- a value within its attribute's `maxBytes` (`too-large`, `path` — the
|
|
215
|
+
attribute).
|
|
216
|
+
|
|
217
|
+
The tools work only on a development database. Before connecting they check
|
|
218
|
+
that the host is this machine (`localhost`, `127.0.0.0/8`, `::1` or a unix
|
|
219
|
+
socket); after connecting, that the database itself carries
|
|
220
|
+
`simetra.environment = 'development'` (a session setting such as
|
|
221
|
+
`options=-c …` does not count). Only a superuser sets it. On a local Supabase
|
|
222
|
+
stack, once per database volume (`<project_id>` is from
|
|
223
|
+
`supabase/config.toml`):
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
docker exec -i supabase_db_<project_id> psql -U supabase_admin -d postgres -c "ALTER DATABASE postgres SET simetra.environment = 'development'"
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Never set it on a shared or hosted database: agent access to other databases
|
|
230
|
+
comes in a later version.
|
|
231
|
+
|
|
232
|
+
These checks are accident guards, not a security boundary. They stop a
|
|
233
|
+
launch against the wrong database; they do not stop an agent: an agent with
|
|
234
|
+
a shell can call the CLI itself, flags included. The boundary is the
|
|
235
|
+
`simetra_runtime` credentials: whoever holds them can act as any user. Keep
|
|
236
|
+
them only in the environment of the development database.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Attribute load and size
|
|
2
|
+
|
|
3
|
+
How `load` and `maxBytes` of an attribute shape what the runtime reads and
|
|
4
|
+
writes, and what to do when the compiler or a command refuses a size.
|
|
5
|
+
|
|
6
|
+
## `load`: keep heavy values out of list reads
|
|
7
|
+
|
|
8
|
+
- `"lazy"` keeps a heavy value (a file, a long body) out of list reads. A
|
|
9
|
+
card read (`{ object, id }`) still returns it, but a list read cannot
|
|
10
|
+
filter or sort by it: that query is refused with `command.invalid`.
|
|
11
|
+
- Without the field, a header `Bytes` attribute is lazy and every other
|
|
12
|
+
attribute is eager. Set `"eager"` to list a header `Bytes`.
|
|
13
|
+
- `load` emits no DDL, and changing it does not make open browser tabs
|
|
14
|
+
stale: an old tab's list simply stops showing the value.
|
|
15
|
+
- Not allowed on a polymorphic `Ref` (the pair is read as a whole), a tabular
|
|
16
|
+
section attribute (a section array without the field would erase it), a
|
|
17
|
+
rights carrier (`ownership`, `containerBinding`, `access`;
|
|
18
|
+
`rights.carrier-lazy`), or a register attribute
|
|
19
|
+
(`attribute.load-not-allowed`): the runtime does not read registers yet.
|
|
20
|
+
|
|
21
|
+
## `maxBytes`: the most a command may write
|
|
22
|
+
|
|
23
|
+
- Applies to `Text`, `Json`, `Bytes` and arrays (`"array": true`); on any
|
|
24
|
+
other type the compiler reports `type.max-bytes-type`, on a register
|
|
25
|
+
attribute `attribute.max-bytes-not-allowed`. A `String` is limited by
|
|
26
|
+
`length` instead.
|
|
27
|
+
- The measure is the UTF-8 bytes of the JSON value as it goes over the wire:
|
|
28
|
+
an array counts as a whole, `Bytes` as its `\x…` hex text.
|
|
29
|
+
- Defaults: 1 MiB for `Json` and `Bytes`, 64 KiB for `Text` and arrays.
|
|
30
|
+
Standard attributes get the default of their type and cannot set their own.
|
|
31
|
+
- A command whose value is over the limit is refused with `command.invalid`,
|
|
32
|
+
`reason: "too-large"`, `path` — the attribute. Only command input is
|
|
33
|
+
checked: a stored value over the limit still reads.
|
|
34
|
+
|
|
35
|
+
To store a long `Text` (an article body, a long description), raise its
|
|
36
|
+
limit, for example `"maxBytes": 1048576` for 1 MiB, and make the attribute
|
|
37
|
+
`"load": "lazy"` if it is on the header, so that list reads stay small.
|
|
38
|
+
|
|
39
|
+
## The response budget
|
|
40
|
+
|
|
41
|
+
Every response the application server sends to the browser has a budget of
|
|
42
|
+
4 MiB, measured the same way as `maxBytes`. The compiler checks the metadata
|
|
43
|
+
against it:
|
|
44
|
+
|
|
45
|
+
- `attribute.row-over-budget` (error): one list row or one tabular section
|
|
46
|
+
row can be larger than the budget. The size of a column is its `maxBytes`,
|
|
47
|
+
the `length` of a `String`, or the fixed size of its type. Lower `maxBytes`
|
|
48
|
+
or `length`, or make header attributes lazy; a tabular section attribute
|
|
49
|
+
cannot be lazy, so lower its limits or move the data to a separate object.
|
|
50
|
+
- `attribute.lazy-over-budget` (warning): the lazy attributes of an object
|
|
51
|
+
together can exceed the budget of a card read. A card past the budget is
|
|
52
|
+
refused, not cut, so lower their `maxBytes` if real values can get there.
|
|
53
|
+
|
|
54
|
+
In the browser a page of a list over the budget comes back shorter, marked
|
|
55
|
+
`more: true`; a read by key, a card and the lines of an owner past the
|
|
56
|
+
budget are refused with `command.invalid`, `reason: "response-too-large"`.
|
|
57
|
+
`data-read` over MCP has no response budget.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# List-order indexes
|
|
2
|
+
|
|
3
|
+
`indexed: true` on an attribute and a composite `indexes` entry both give a
|
|
4
|
+
list-order index: the scope column first (on a scoped table), the attribute
|
|
5
|
+
columns in the declared order, the row key last. A keyset page then reads
|
|
6
|
+
from the index without sorting the visible set.
|
|
7
|
+
|
|
8
|
+
- A table without a one-column row key (a register movement or totals) gets no
|
|
9
|
+
key column.
|
|
10
|
+
- A `unique` attribute already has such an index, so no second one is made.
|
|
11
|
+
- An `indexed` `Ref` uses one index for both the foreign key and the order.
|
|
12
|
+
- Changing an existing index to this shape is a drop and a create in the
|
|
13
|
+
apply plan; it needs no permission, but the table is locked while the
|
|
14
|
+
index builds.
|
|
15
|
+
- A catalog's standard `description` is `NOT NULL DEFAULT ''` and indexed
|
|
16
|
+
whenever the catalog has it (`descriptionLength` above 0). A command may
|
|
17
|
+
omit it (the default `''` is stored) but must not send an explicit `null`.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Object modules: TypeScript hooks of a command
|
|
2
|
+
|
|
3
|
+
How the server code of an application adds behaviour to the generated
|
|
4
|
+
commands of an object; the router is `SKILL.md`. The full contract is §6.9 of
|
|
5
|
+
the P4 runtime spec in the Simetra repository
|
|
6
|
+
(`docs/superpowers/specs/2026-10-26-p4-runtime-design.md`).
|
|
7
|
+
|
|
8
|
+
## Shape
|
|
9
|
+
|
|
10
|
+
An object module is a plain object typed by the generated entity type
|
|
11
|
+
(`entities.d.ts` from `compile --out`) and keyed by 1C write events:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineObjectModule } from "simetra/model"
|
|
15
|
+
import type { Catalogs } from "./generated/entities" // the compile --out file
|
|
16
|
+
|
|
17
|
+
export const client = defineObjectModule<Catalogs.Client>({
|
|
18
|
+
beforeWrite({ ctx, draft }) {
|
|
19
|
+
return draft
|
|
20
|
+
},
|
|
21
|
+
onWrite({ ctx, row }) {},
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `beforeWrite` (1C `ПередЗаписью`) runs before the core function and returns
|
|
26
|
+
the draft `{ values?, tabularSections? }` the phase writes. It never adds
|
|
27
|
+
`id` or `mark`; the runtime checks the returned draft again.
|
|
28
|
+
- `onWrite` (1C `ПриЗаписи`) sees the written row in the same transaction.
|
|
29
|
+
The row has the shape of a card read: the tabular sections that the phase
|
|
30
|
+
wrote are under `row.tabularSections.<name>`.
|
|
31
|
+
- Both run on the operations `create`, `update` and `markDeletion`;
|
|
32
|
+
`delete` raises no module event. On `markDeletion` the draft is empty and
|
|
33
|
+
the mark is `ctx.mark`.
|
|
34
|
+
- The host passes modules to `createCommandRuntime` (`simetra/server`) as
|
|
35
|
+
`objectModules`, keyed `"<Kind>.<Name>"` (`"Catalog.Client"`). An unknown
|
|
36
|
+
object or hook key fails runtime creation, not the first command.
|
|
37
|
+
|
|
38
|
+
## The context
|
|
39
|
+
|
|
40
|
+
- `ctx.action` is the operation (`create`, `update`, `markDeletion`),
|
|
41
|
+
`ctx.isNew` is `create`; `ctx.user` is the current user.
|
|
42
|
+
- `ctx.additionalProperties` is shared by the hooks of one phase only.
|
|
43
|
+
- `ctx.run(operation)` runs a phase of another object in the same
|
|
44
|
+
transaction, with its own rights check and hooks, and returns the written
|
|
45
|
+
row in the same shape as `onWrite` sees it; `ctx.read(query)` reads in
|
|
46
|
+
that transaction. It takes the query of `data-read` and returns `{ rows }`
|
|
47
|
+
or `{ count, capped? }`, e.g.
|
|
48
|
+
`ctx.read({ object, where: { attribute: "code", op: "eq", value }, limit: 1 })`.
|
|
49
|
+
- A tabular section array in an `update` passed to `ctx.run` replaces the
|
|
50
|
+
section: every existing row must be in the array or in `deleteIds`,
|
|
51
|
+
otherwise the command fails with `command.invalid`
|
|
52
|
+
`reason: "tabular-rows-missing"` — the same rule as `data-command`.
|
|
53
|
+
`ctx.run` always checks this. Build the array from a `ctx.read` of the
|
|
54
|
+
owner's lines.
|
|
55
|
+
- One command transaction may start at most `BATCH_MAX` phases through
|
|
56
|
+
`ctx.run`; past it the command fails with `command.depth`
|
|
57
|
+
`reason: "phases"`. Nesting deeper than the runtime's depth limit is
|
|
58
|
+
`command.depth` too.
|
|
59
|
+
- Hook time counts toward the command's time budget: a command past it
|
|
60
|
+
fails with `command.timeout`, and a lock wait past the lock timeout with
|
|
61
|
+
`command.busy`. Keep hooks short.
|
|
62
|
+
- `ctx.reject(code, path?)` fails the command with `command.rejected`.
|
|
63
|
+
- A `ctx` method works only while its hook runs. Never keep `ctx` for later:
|
|
64
|
+
a late call fails the command (`command.internal`).
|
|
65
|
+
- A failure the hook catches still fails the command; await every `ctx.run`.
|
|
66
|
+
|
|
67
|
+
## No external I/O in a hook
|
|
68
|
+
|
|
69
|
+
A serialization failure or a deadlock reruns the whole transaction, hooks
|
|
70
|
+
included. A hook never calls HTTP, mail or a queue outside the database. Put
|
|
71
|
+
such work into `ctx.afterCommit(fn)`: it runs after `COMMIT`, at most once,
|
|
72
|
+
and only for non-critical work (a crash after `COMMIT` loses it); its error
|
|
73
|
+
does not undo the command. On a serverless host, pass `defer` (`waitUntil`) to
|
|
74
|
+
`createCommandRuntime`, or `run` waits for this work before it returns.
|
|
75
|
+
|
|
76
|
+
A hook gets no database client and no SQL text. A row rule that must hold for
|
|
77
|
+
every writer belongs in the database (`EventSubscription`, row rules, rights),
|
|
78
|
+
not in a hook.
|