@simetrajs/designer 0.2.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/dist/{command-BCAw6Fsb.js → command-CHk1P9Dp.js} +42 -123
- package/dist/errors-D1P2kKbL.js +62 -0
- package/dist/{report-DV4deFdu.js → invoke-BwP_5iN6.js} +931 -314
- package/dist/main.js +4 -4
- package/dist/{mcp-ChltmHBb.js → mcp-jLOz0W7f.js} +26 -84
- package/dist/{package-Dg3MXPve.js → package-hA0J8AMK.js} +1 -1
- package/dist/{schema-engine-DPPnife2.js → schema-engine-8rVHcVYO.js} +627 -122
- package/dist/{types-iWavtmdS.js → types-CMcZhIci.js} +2 -0
- package/package.json +6 -3
- package/skills/simetra-adoption/SKILL.md +67 -2
- package/skills/simetra-metadata/SKILL.md +74 -87
- package/skills/simetra-metadata/references/agents-over-mcp.md +120 -3
- 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 +20 -2
- package/skills/simetra-metadata/references/people-and-rights.md +106 -14
- package/skills/simetra-metadata/references/plan-and-apply.md +81 -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 +41 -10
- package/dist/errors-Brw6UjAD.js +0 -35
|
@@ -7,6 +7,7 @@ const TOOL_NAMES = [
|
|
|
7
7
|
"fix",
|
|
8
8
|
"create",
|
|
9
9
|
"add",
|
|
10
|
+
"declare-function",
|
|
10
11
|
"rename",
|
|
11
12
|
"delete",
|
|
12
13
|
"promote",
|
|
@@ -16,6 +17,7 @@ const TOOL_NAMES = [
|
|
|
16
17
|
"apply",
|
|
17
18
|
"roles",
|
|
18
19
|
"rights-maintenance",
|
|
20
|
+
"signals-config",
|
|
19
21
|
"data-read",
|
|
20
22
|
"data-command"
|
|
21
23
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simetrajs/designer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-next.1",
|
|
4
4
|
"description": "Simetra developer tools: command line and MCP server over the metadata compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"simetra",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"@supabase/pg-delta": "1.0.0-alpha.60",
|
|
35
35
|
"citty": "0.2.2",
|
|
36
36
|
"pg": "8.23.1",
|
|
37
|
+
"pg-connection-string": "2.14.1",
|
|
37
38
|
"smol-toml": "1.9.1",
|
|
38
39
|
"zod": "^4.6.7",
|
|
39
|
-
"simetra": "0.
|
|
40
|
+
"simetra": "0.3.0-next.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@arethetypeswrong/cli": "0.18.5",
|
|
@@ -65,6 +66,8 @@
|
|
|
65
66
|
"test": "vitest run --project unit",
|
|
66
67
|
"test:watch": "vitest --project unit",
|
|
67
68
|
"test:db": "vitest run --project db",
|
|
68
|
-
"test:
|
|
69
|
+
"test:db:supabase": "vitest run --project db-supabase",
|
|
70
|
+
"test:packaging": "vitest run --project packaging",
|
|
71
|
+
"bench:signals": "vitest run --project bench signals"
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: simetra-adoption
|
|
3
|
-
description: Use when bringing an existing live PostgreSQL database under Simetra metadata for the first time
|
|
3
|
+
description: "Use when bringing an existing live PostgreSQL database under Simetra metadata for the first time: `simetra introspect`, then `simetra diff` to prove they match. Not for everyday metadata edits (`simetra-metadata`)."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Simetra adoption — introspect a live database, then diff
|
|
7
7
|
|
|
8
|
+
Covers: the scope (`--schemas`, `--tables`), the connection and shadow
|
|
9
|
+
database settings, exit codes, unrepresentable objects and non-empty results,
|
|
10
|
+
and the first screen after adoption: one-line list and card routes
|
|
11
|
+
(`entityListRoute`, `entityCardRoute`).
|
|
12
|
+
|
|
8
13
|
Adoption is a one-time onboarding: the database already exists, and the
|
|
9
14
|
metadata is derived from it. `introspect` reads the database into metadata;
|
|
10
15
|
`diff` compares the database with the metadata through a throwaway shadow
|
|
@@ -112,7 +117,8 @@ not express through metadata (CustomTable and PgEnum modules, shared
|
|
|
112
117
|
`metadata/sql/`, statements a closed form does not accept).
|
|
113
118
|
|
|
114
119
|
- The list is a ratchet and only shrinks. `introspect` is the only writer and
|
|
115
|
-
derives it from the database; `fix`
|
|
120
|
+
derives it from the database; `fix` removes stale entries (and repairs function
|
|
121
|
+
declarations, see below); `compile`
|
|
116
122
|
fails with `sql.debt-grows` on a debt unit that is not listed and with
|
|
117
123
|
`sql.debt-stale` on an entry that is no longer debt. Without that, verbatim
|
|
118
124
|
SQL would grow back unnoticed.
|
|
@@ -128,6 +134,37 @@ not express through metadata (CustomTable and PgEnum modules, shared
|
|
|
128
134
|
kind fails with `sql.kind-table-verbatim`. Rewrite such a function with
|
|
129
135
|
static SQL or remove it.
|
|
130
136
|
|
|
137
|
+
## SECURITY DEFINER functions
|
|
138
|
+
|
|
139
|
+
A `SECURITY DEFINER` function that an API role can execute is written next to
|
|
140
|
+
its `.sql` as a declaration (`<name>.functions.json`) with `callers` derived
|
|
141
|
+
from the database `EXECUTE` facts. The folder is then not clean yet, but the
|
|
142
|
+
errors are only of the repair class (`sql.declaration-check-missing`,
|
|
143
|
+
`sql.declaration-check-not-applied`, `sql.definer-caller-unchecked`), and
|
|
144
|
+
`introspect` writes it anyway. Bring it to a clean state in this order:
|
|
145
|
+
|
|
146
|
+
1. `declare-function` with `{function, callers, check}`: names the rights check
|
|
147
|
+
the function applies (an object with rights, an action, at most one target
|
|
148
|
+
parameter). An adopted `CustomTable` has no rights contract, so `promote` it
|
|
149
|
+
into a Catalog or Document first. It replaces the record of that function and refuses when the
|
|
150
|
+
result would add any other error. A function that already has a platform
|
|
151
|
+
form (a scope kind set function, a dimension values function, a subscription
|
|
152
|
+
handler) is refused.
|
|
153
|
+
2. `fix`: inserts a `PERFORM simetra.rights_require` (or `rights_require_scope`) call as the first
|
|
154
|
+
statement of the body from the declared `check`. It only inserts into a
|
|
155
|
+
`plpgsql` body without `DECLARE` and `EXCEPTION` and without any guard call;
|
|
156
|
+
in any other body write the guard yourself. In the same run `fix` also cuts
|
|
157
|
+
verbatim `GRANT EXECUTE` statements and `ALTER DEFAULT PRIVILEGES … ON FUNCTIONS`
|
|
158
|
+
that contradict the platform, and removes the declaration of a function that
|
|
159
|
+
became a platform form, unless that would widen `EXECUTE`: then the record
|
|
160
|
+
stays and a warning names the roles a person must decide on. `fix` never
|
|
161
|
+
widens `EXECUTE`.
|
|
162
|
+
3. `compile` must show no errors; then `plan` and `apply`. The next `plan` is
|
|
163
|
+
empty.
|
|
164
|
+
|
|
165
|
+
`explain` with `{function: {schema?, name}}` shows callers, the roles that get
|
|
166
|
+
`EXECUTE`, and whether the check is applied.
|
|
167
|
+
|
|
131
168
|
## Adopted triggers
|
|
132
169
|
|
|
133
170
|
An adopted trigger stays verbatim debt while its table is a `CustomTable`.
|
|
@@ -183,3 +220,31 @@ class `platform` only when the kind replaces it, and `plan` refuses
|
|
|
183
220
|
- `diff` also reports `applyState`: `absent` while the database holds none of
|
|
184
221
|
the platform's apply state (the first `apply` creates it, so it is not a
|
|
185
222
|
difference), `present` otherwise.
|
|
223
|
+
|
|
224
|
+
## First screen: one-line routes
|
|
225
|
+
|
|
226
|
+
After adoption, an object gets a standard list and card screen from one line
|
|
227
|
+
per route in the template app (`src/routes/`). `entity` is the descriptor the
|
|
228
|
+
app exports for the object (`Client` in the example); the route files stay
|
|
229
|
+
under TanStack Router's file naming:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
// src/routes/clients/index.tsx
|
|
233
|
+
export const Route = createFileRoute("/clients/")(entityListRoute(Client))
|
|
234
|
+
|
|
235
|
+
// src/routes/clients/$id.tsx
|
|
236
|
+
export const Route = createFileRoute("/clients/$id")(entityCardRoute(Client))
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
- Both helpers come from `simetra/shell`. The list route preloads the list
|
|
240
|
+
view and renders `ListHost`; the card route preloads the card and its
|
|
241
|
+
tabular sections for the `id` path parameter and renders `CardHost`. Both
|
|
242
|
+
set `ssr: true`, so the first paint already carries the user's own rows.
|
|
243
|
+
- `entityListRoute(entity, { orderBy, include })` takes optional `orderBy`
|
|
244
|
+
(for example `[{ attribute: "description", direction: "asc" }]`) and
|
|
245
|
+
`include` references.
|
|
246
|
+
- Do not add a data-fetching loader, a query or a store by hand: the data
|
|
247
|
+
runtime of the request is already in the router context, and the route
|
|
248
|
+
helpers use it.
|
|
249
|
+
- The card edits header attributes only; creating rows and editing tabular
|
|
250
|
+
sections are not part of these routes.
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: simetra-metadata
|
|
3
|
-
description: Use when you
|
|
3
|
+
description: "Use when you create, change, validate or explain Simetra metadata (a `metadata/` directory) with the `simetra` tools: compile, explain, fix, edit, diff, plan, apply, MCP — or when a pre-commit or CI metadata check fails."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Simetra metadata — compile, explain, fix, create, add, rename, delete, promote, introspect, diff, plan, apply
|
|
7
7
|
|
|
8
|
+
Covers: a compiler diagnostic (`file:line:col`, `--format json`, `--locale`);
|
|
9
|
+
the compiled picture of an object; missing ids and `physicalName`; creating,
|
|
10
|
+
adding, renaming, deleting elements and promoting an adopted table through
|
|
11
|
+
checked operations; `diff`, `plan`, `apply`; `simetra mcp` (`--read-only`),
|
|
12
|
+
including application data of the development database as a user
|
|
13
|
+
(`data-read`, `data-command`). For bringing an existing database under
|
|
14
|
+
metadata (`introspect`), use `simetra-adoption`.
|
|
15
|
+
|
|
8
16
|
The tools are one catalog served by the command line and by the MCP server,
|
|
9
17
|
with the same tool names and the same input in both. Run the CLI
|
|
10
18
|
from the project root as `pnpm exec simetra …` (or `node_modules/.bin/simetra …`).
|
|
@@ -23,6 +31,7 @@ diagnostics themselves.
|
|
|
23
31
|
| New elements miss `id` / `physicalName` / `kindLabel`, or files are not canonical | `fix` | `simetra fix [dir]` | `fix` with `{}` |
|
|
24
32
|
| New object | `create` | `simetra create '<json>' [dir]` | `create` with `{kind, name, data?}` |
|
|
25
33
|
| New element in a collection of an object or of the project root | `add` | `simetra add '<json>' [dir]` | `add` with `{target, collection, element}` |
|
|
34
|
+
| Declare who may execute a SQL function and which rights check it applies | `declare-function` | `simetra declare-function '<json>' [dir]` | `declare-function` with `{function, callers, check?}` |
|
|
26
35
|
| Rename an object or a nested element | `rename` | `simetra rename '<json>' [dir]` | `rename` with `{target, newName}` |
|
|
27
36
|
| Remove an object or a nested element | `delete` | `simetra delete '<json>' [dir] --yes` | `delete` with `{target, confirm}` |
|
|
28
37
|
| Turn an adopted `CustomTable` into a Catalog, Document or InformationRegister | `promote` | `simetra promote <json\|-> [dir]` | `promote` with `{target, into, columns, …}` |
|
|
@@ -32,10 +41,11 @@ diagnostics themselves.
|
|
|
32
41
|
| Apply a reviewed plan to the database | `apply` | `simetra apply <plan> [dir] --plan-hash <hex> --yes` | `apply` with `{plan, planHash, allow?, confirm}` |
|
|
33
42
|
| Create the platform's cluster roles once per server (before the first `plan`); reads the project file | `roles` | `simetra roles` | `roles` with `{}` |
|
|
34
43
|
| Restore rights access outside commands: the first global assignment, a global or tenant `fullAccess` owner nobody holds (as the migrator) | `rights-maintenance` | `simetra rights-maintenance '<json>' [dir] --yes` | not available: command line only |
|
|
44
|
+
| Generate the Centrifugo config of the project's signals (no secret in it) | `signals-config` | `simetra signals-config '<json>' [dir]` | `signals-config` with `{origin, issuer, jwksUrl}` |
|
|
35
45
|
| Read application data of the development database as a user, with that user's rights | `data-read` | `simetra data-read '<json>' [dir] --data-url-env <VAR> --as <uuid>` | `data-read` with `{query}` |
|
|
36
46
|
| Change application data of the development database as a user (seed test data, reproduce a bug) | `data-command` | `simetra data-command '<json>' [dir] --data-url-env <VAR> --as <uuid>` | `data-command` with `{operations}` |
|
|
37
47
|
|
|
38
|
-
`fix`, `create`, `add`, `rename`, `delete`, `promote`, `introspect` change files;
|
|
48
|
+
`fix`, `create`, `add`, `declare-function`, `rename`, `delete`, `promote`, `introspect` change files;
|
|
39
49
|
`plan` writes only its plan file; others only read files. `introspect`, `diff`,
|
|
40
50
|
`plan` read the database; `apply`, `roles`, `rights-maintenance` write to it.
|
|
41
51
|
|
|
@@ -188,7 +198,7 @@ offending field (for example `target.kind`); nothing is written.
|
|
|
188
198
|
location are identical in both.
|
|
189
199
|
- Start from the first error: one root cause often produces several follow-ups.
|
|
190
200
|
- Artifacts (`snapshot.json`, `desired-state.sql`, `entities.d.ts`,
|
|
191
|
-
`runtime-catalog.json`) are written
|
|
201
|
+
`runtime-catalog.json`, `client-catalog.json`) are written
|
|
192
202
|
only with `compile --out <dir>`, and `--out` takes one metadata directory per run.
|
|
193
203
|
|
|
194
204
|
## Mutations are checked, never raw
|
|
@@ -234,12 +244,18 @@ Attribute properties (an element of `attributes`):
|
|
|
234
244
|
character as itself or as `\uXXXX`.
|
|
235
245
|
- `personalData: true` marks personal data (a name, a phone, an address):
|
|
236
246
|
anonymization sets it to `NULL`, so it cannot also be `required`.
|
|
247
|
+
- `load`: `"lazy"` keeps a heavy value (a file, a long body) out of list
|
|
248
|
+
reads; a card read still returns it. `maxBytes` caps what a command may
|
|
249
|
+
write to a `Text`, `Json`, `Bytes` or array value; raise it for a long
|
|
250
|
+
`Text`. Details of both, the response budget and its compiler errors:
|
|
251
|
+
`references/attribute-load-and-size.md`.
|
|
237
252
|
|
|
238
253
|
Object properties:
|
|
239
254
|
|
|
240
255
|
- `indexes` on a Catalog, a Document and their tabular sections: a list of
|
|
241
|
-
composite indexes, each `{ "attributes": [name | { "name": …, "order": "desc" }] }`.
|
|
242
|
-
- `
|
|
256
|
+
composite indexes, each `{ "attributes": [name | { "name": …, "order": "desc" }] }`; like `indexed`, a list-order index: `references/list-order-indexes.md`.
|
|
257
|
+
- `search`: fields and mode of the object's search: `references/search-fields.md`.
|
|
258
|
+
- `publicRead`: `"authenticated"` or `"anon"` on kinds with row-level security, or the conditional form `{ "role": …, "published": true }` that opens only published rows: `references/people-and-rights.md` § "Who reads what".
|
|
243
259
|
- Project file: `storageBuckets`, a list of `{ "bucket": …, "scopeKind": … }`.
|
|
244
260
|
|
|
245
261
|
An attribute with properties, added through the tool:
|
|
@@ -274,9 +290,9 @@ No event is insert-only; `TG_OP` tells insert from update. The same events as
|
|
|
274
290
|
TypeScript hooks of a command (object modules): `references/object-modules.md`.
|
|
275
291
|
|
|
276
292
|
Catalogs and Documents get the row mechanics trigger `<table>_simetra_touch`
|
|
277
|
-
(the single platform function `simetra.touch()`):
|
|
278
|
-
an update
|
|
279
|
-
on a table with carrier copies the update is `<table>_simetra_touch_update`,
|
|
293
|
+
(the single platform function `simetra.touch()`): `version` comes from the
|
|
294
|
+
sequence `simetra.row_version` (an update: at least old version plus 1), `updatedAt` is `now()`, whatever
|
|
295
|
+
the client writes; on a table with carrier copies the update is `<table>_simetra_touch_update`,
|
|
280
296
|
firing on a content change only. Never maintain them (`moddatetime`) or list
|
|
281
297
|
them in `whenChanged`. A `beforeWrite` handler never assigns `NEW.updated_at`
|
|
282
298
|
or `NEW.version` and never replaces the row (`NEW := …`, `SELECT … INTO NEW`):
|
|
@@ -343,6 +359,20 @@ A row rule shape:
|
|
|
343
359
|
ALTER TABLE <schema>.<own_table> ADD CONSTRAINT <rule_name> CHECK (<rule>);
|
|
344
360
|
```
|
|
345
361
|
|
|
362
|
+
## Function declarations: `declare-function` and `fix`
|
|
363
|
+
|
|
364
|
+
`declare-function` creates or replaces the record of one function in the
|
|
365
|
+
sibling `<name>.functions.json` (full replacement of `callers` and `check`, the
|
|
366
|
+
`id` is kept). It writes only when the folder gets no new repair-class error;
|
|
367
|
+
the one allowed change is the declared function's own error becoming
|
|
368
|
+
`sql.declaration-check-not-applied (firstStatement)`, which `fix` then repairs
|
|
369
|
+
by inserting the guard call as the first statement of the body. `fix` never
|
|
370
|
+
invents a right: the guard comes only from the declared `check`. In a folder
|
|
371
|
+
with repair-class errors `fix` writes when it removes at least one of them and
|
|
372
|
+
adds none (and the folder has no error outside the class). `declare-function`
|
|
373
|
+
also cuts the verbatim `GRANT EXECUTE` of the declared function: its ACL now
|
|
374
|
+
belongs to the platform. See `simetra-adoption` for the full chain.
|
|
375
|
+
|
|
346
376
|
## SQL debt
|
|
347
377
|
|
|
348
378
|
`metadata/sql-debt.json` lists the verbatim SQL units that the compiler still
|
|
@@ -357,9 +387,9 @@ tolerates. It only shrinks:
|
|
|
357
387
|
function; moving it to another file does not make it acceptable.
|
|
358
388
|
- A project with an existing `sql/` folder and no list is seeded by running
|
|
359
389
|
`introspect` again (see `simetra-adoption`).
|
|
360
|
-
- Debt SQL must not write `simetra
|
|
361
|
-
|
|
362
|
-
`
|
|
390
|
+
- Debt SQL must not write `simetra.*`; its function bodies follow
|
|
391
|
+
`sql.function-body-statement` (`references/sql-trust-boundary.md`); for
|
|
392
|
+
`SECURITY DEFINER` and views see `references/people-and-rights.md`.
|
|
363
393
|
|
|
364
394
|
## The database: introspect and diff
|
|
365
395
|
|
|
@@ -373,76 +403,13 @@ creates and `diff` does not count as a difference; `present` otherwise.
|
|
|
373
403
|
|
|
374
404
|
## The database: plan and apply
|
|
375
405
|
|
|
376
|
-
`plan`
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
cluster, not in the database, so `plan` does not create them. Without one on
|
|
384
|
-
the target or the shadow server, `plan`, `diff` and `rehearse` refuse with
|
|
385
|
-
`plan.platform-role-missing`: run `simetra roles` once with a role that has
|
|
386
|
-
`CREATEROLE` (with a project file it also creates the login role: "Platform
|
|
387
|
-
roles" in `references/people-and-rights.md`). It only checks an existing role;
|
|
388
|
-
an unsafe shape (`plan.platform-role-shape`) is fixed by hand, not by `roles`.
|
|
389
|
-
|
|
390
|
-
`apply` applies exactly that file in one transaction. It needs the `planHash`
|
|
391
|
-
of the reviewed plan, confirmation (`--yes`, MCP `confirm: true`), and in
|
|
392
|
-
`allow` the id of every step that drops data or relaxes a guarantee and
|
|
393
|
-
`drift` when the plan carries drift; the plan output says which items need
|
|
394
|
-
it. `rehearse` runs the plan and rolls it back, but still takes the same
|
|
395
|
-
locks as `apply`. It also builds the desired shadow database and proves on the
|
|
396
|
-
same connection that the catalog equals the desired state, so it holds the
|
|
397
|
-
plan's locks a little longer. A successful `rehearse` writes its report to
|
|
398
|
-
`plans/<from>-<to>.rehearsal.json` next to the plan.
|
|
399
|
-
|
|
400
|
-
Before the end of the transaction, `apply` and `rehearse` re-validate function
|
|
401
|
-
bodies and fire deferred constraints; an invalid constraint or index that the
|
|
402
|
-
desired state does not have is refused. An `apply.function-check-blind` warning lists
|
|
403
|
-
functions the check cannot see (another language, no `EXECUTE` for the role, a
|
|
404
|
-
trigger function without a trigger): nothing proved their bodies, so review
|
|
405
|
-
them by hand.
|
|
406
|
-
|
|
407
|
-
When the role has global default privileges, a plan also ends with environment
|
|
408
|
-
steps: explicit GRANT/REVOKE that cancel them on the objects the plan creates.
|
|
409
|
-
The output shows them as their own group, `environment rights: the global
|
|
410
|
-
default privileges of role <role>`; review them with the rest of the plan.
|
|
411
|
-
If the environment changes before the apply, it is refused
|
|
412
|
-
(`apply.target-changed`); plan again. A plan file from an older tool version is
|
|
413
|
-
refused too: rebuild it with `plan`.
|
|
414
|
-
|
|
415
|
-
A promotion plan's `allow` also takes its listed `access:<table>`, `remove:<t>`,
|
|
416
|
-
`repair:<t>`, `delete:<t>.<constraint>` and `update:<t>.<constraint>` items; a
|
|
417
|
-
repair rewrites existing values with the fill expression shown.
|
|
418
|
-
A promotion is applied only with a valid rehearsal report: rehearse the plan on
|
|
419
|
-
a copy of the target with data first. Point the rehearsal at the copy through
|
|
420
|
-
the connection variable: `simetra apply --rehearse --database-url-env <VAR>`
|
|
421
|
-
on the command line, or an MCP server launched with
|
|
422
|
-
`simetra mcp --database-url-env <VAR>` (an MCP server's database is fixed at
|
|
423
|
-
launch). Make the copy from the target after the plan, restore it as the plan's
|
|
424
|
-
role with `pg_restore --no-owner`, on a server with the same PostgreSQL major
|
|
425
|
-
version, encoding and collation; otherwise the rehearsal is refused as not a
|
|
426
|
-
copy of the plan's target (`apply.target-changed`). Rehearsing on the target
|
|
427
|
-
itself is allowed, but it holds the target's locks for the whole run: make it
|
|
428
|
-
a deliberate choice of the owner, not a default. `apply` refuses without a
|
|
429
|
-
report (`apply.rehearsal-required`), with a stale one (`apply.rehearsal-stale`:
|
|
430
|
-
another plan, report format, server, ledger head, or not one row count per
|
|
431
|
-
promoted table), and when a table has rows on the target but none on the copy
|
|
432
|
-
(`apply.rehearsal-copy-empty`); it warns when the copy has fewer rows
|
|
433
|
-
(`apply.rehearsal-fewer-rows`) or when the statement timeout computed from the
|
|
434
|
-
report exceeds what Postgres accepts (`apply.rehearsal-timeout-unbounded`).
|
|
435
|
-
|
|
436
|
-
Which connection to use:
|
|
437
|
-
|
|
438
|
-
- Reads of the target (`introspect`, `diff`, `plan`) run in short read-only
|
|
439
|
-
transactions and work through a transaction-mode pooler.
|
|
440
|
-
- The shadow database of `diff` and `plan` needs a direct or session-mode
|
|
441
|
-
connection: it is created, reached by name and loaded with session settings
|
|
442
|
-
that a transaction-mode pooler is not guaranteed to keep. With a pooled target
|
|
443
|
-
connection, point `--shadow-url-env` at a direct one.
|
|
444
|
-
- A long `apply` wants a direct or session-mode connection too: a pooler may
|
|
445
|
-
cut the transaction with its own timeouts.
|
|
406
|
+
`plan` reads the database and writes `plans/<from>-<to>.plan.json`; show it to
|
|
407
|
+
the owner. `apply` applies exactly that file in one transaction, with the
|
|
408
|
+
reviewed `planHash`, confirmation and every `allow` item the plan names;
|
|
409
|
+
`rehearse` runs it and rolls back. Platform roles, re-validation, warnings,
|
|
410
|
+
refusals and recovery: `references/plan-and-apply.md`; platform roles —
|
|
411
|
+
`references/people-and-rights.md` ("Platform roles"); the row version epoch
|
|
412
|
+
after a restore — `references/row-version-epoch.md`. An MCP `apply` input:
|
|
446
413
|
|
|
447
414
|
```json simetra:apply
|
|
448
415
|
{
|
|
@@ -453,13 +420,33 @@ Which connection to use:
|
|
|
453
420
|
}
|
|
454
421
|
```
|
|
455
422
|
|
|
456
|
-
|
|
457
|
-
|
|
423
|
+
## Signals: the Centrifugo config
|
|
424
|
+
|
|
425
|
+
Signals of committed commands reach clients through Centrifugo, which reads the
|
|
426
|
+
outbox table `simetra.signal_outbox`. Generate its config from the project
|
|
427
|
+
instead of writing it by hand:
|
|
428
|
+
|
|
429
|
+
```sh
|
|
430
|
+
pnpm exec simetra signals-config '{"origin":"https://app.example.com","issuer":"https://app.example.com","jwksUrl":"http://app:3000/simetra/signals/jwks"}' > centrifugo.json
|
|
431
|
+
```
|
|
458
432
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
433
|
+
- `origin` is the browser origin of the application, `issuer` the host origin
|
|
434
|
+
that signs the tokens; the token audience is `centrifugo:<project name>`.
|
|
435
|
+
`jwksUrl` is where the host serves its JWKS: `https:`, or `http:` only on a
|
|
436
|
+
loopback address or an internal single-label service name. Anything else, or
|
|
437
|
+
a hand-edited config that leaves the tool's whitelist, is refused.
|
|
438
|
+
- The config holds no secret. Give Centrifugo the DSN of the login role
|
|
439
|
+
`simetra_signals` in its environment, in the two variables the tool names
|
|
440
|
+
(`--format json` lists them): a direct connection, or a pooler in session
|
|
441
|
+
mode only (the consumer needs `LISTEN`). Set the HTTP listener through the
|
|
442
|
+
environment as well (`CENTRIFUGO_HTTP_SERVER_ADDRESS`,
|
|
443
|
+
`CENTRIFUGO_HTTP_SERVER_PORT`).
|
|
444
|
+
- Run exactly one Centrifugo per application: history lives in its memory, so
|
|
445
|
+
a second instance reading the same outbox would take signals its clients
|
|
446
|
+
never see.
|
|
447
|
+
- While Centrifugo is down the outbox grows; it publishes the backlog when it
|
|
448
|
+
is back. Trim old rows on your own schedule (`pg_cron` or an external cron)
|
|
449
|
+
as the owner role: `SELECT simetra.signal_outbox_prune('1 hour');`.
|
|
463
450
|
|
|
464
451
|
## Agents over MCP
|
|
465
452
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Agents over MCP
|
|
2
2
|
|
|
3
3
|
Contents: launch flags; data of the development database (connect, flags,
|
|
4
|
-
examples, the database marker, limits).
|
|
4
|
+
examples, tabular section arrays, the database marker, limits).
|
|
5
5
|
|
|
6
6
|
`simetra mcp` serves the tool catalog to an agent over stdio. `simetra init`
|
|
7
7
|
writes its entry in the MCP client config; flags added to that entry's `args`
|
|
@@ -38,7 +38,7 @@ variable are the owner's choice. The CLI takes the same flags per call:
|
|
|
38
38
|
```sh
|
|
39
39
|
pnpm exec simetra mcp --data-url-env SIMETRA_DEV_DATA_URL --as <user-uuid>
|
|
40
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"},"
|
|
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
42
|
```
|
|
43
43
|
|
|
44
44
|
- The variable holds the connection string of the runtime login role
|
|
@@ -68,6 +68,56 @@ pnpm exec simetra data-read '{"query":{"object":{"kind":"Catalog","name":"Curren
|
|
|
68
68
|
`plan` and `apply` it.
|
|
69
69
|
- A runtime refusal comes back as `error` with a `code` (and a `reason`);
|
|
70
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.
|
|
71
121
|
|
|
72
122
|
Read a page of rows:
|
|
73
123
|
|
|
@@ -75,12 +125,37 @@ Read a page of rows:
|
|
|
75
125
|
{
|
|
76
126
|
"query": {
|
|
77
127
|
"object": { "kind": "Catalog", "name": "Currency" },
|
|
78
|
-
"where": { "symbol": "$" },
|
|
128
|
+
"where": { "attribute": "symbol", "op": "eq", "value": "$" },
|
|
129
|
+
"orderBy": [{ "attribute": "description", "direction": "asc" }],
|
|
79
130
|
"limit": 50
|
|
80
131
|
}
|
|
81
132
|
}
|
|
82
133
|
```
|
|
83
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
|
+
|
|
84
159
|
Seed rows in one transaction (`id` is a new UUID you generate; `update`,
|
|
85
160
|
`markDeletion` and `delete` also need `expectedVersion`):
|
|
86
161
|
|
|
@@ -97,6 +172,48 @@ Seed rows in one transaction (`id` is a new UUID you generate; `update`,
|
|
|
97
172
|
}
|
|
98
173
|
```
|
|
99
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
|
+
|
|
100
217
|
The tools work only on a development database. Before connecting they check
|
|
101
218
|
that the host is this machine (`localhost`, `127.0.0.0/8`, `::1` or a unix
|
|
102
219
|
socket); after connecting, that the database itself carries
|
|
@@ -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`.
|