@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// src/tools/types.ts
|
|
3
3
|
/** Імена окремо від записів каталогу: `main.ts` реєструє лінощі підкоманди, не тягнучи компілятор. */
|
|
4
4
|
const TOOL_NAMES = [
|
|
5
5
|
"compile",
|
|
@@ -7,13 +7,19 @@ const TOOL_NAMES = [
|
|
|
7
7
|
"fix",
|
|
8
8
|
"create",
|
|
9
9
|
"add",
|
|
10
|
+
"declare-function",
|
|
10
11
|
"rename",
|
|
11
12
|
"delete",
|
|
12
13
|
"promote",
|
|
13
14
|
"introspect",
|
|
14
15
|
"diff",
|
|
15
16
|
"plan",
|
|
16
|
-
"apply"
|
|
17
|
+
"apply",
|
|
18
|
+
"roles",
|
|
19
|
+
"rights-maintenance",
|
|
20
|
+
"signals-config",
|
|
21
|
+
"data-read",
|
|
22
|
+
"data-command"
|
|
17
23
|
];
|
|
18
24
|
/**
|
|
19
25
|
* Каталог артефактів плану в корені проєкту, поруч із текою метаданих:
|
|
@@ -24,5 +30,4 @@ const PLANS_DIR = "plans";
|
|
|
24
30
|
function defineTool(tool) {
|
|
25
31
|
return tool;
|
|
26
32
|
}
|
|
27
|
-
//#endregion
|
|
28
33
|
export { TOOL_NAMES as n, defineTool as r, PLANS_DIR as t };
|
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",
|
|
@@ -30,27 +30,29 @@
|
|
|
30
30
|
"simetra": "./dist/main.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@modelcontextprotocol/server": "2.
|
|
34
|
-
"@supabase/pg-delta": "1.0.0-alpha.
|
|
33
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
34
|
+
"@supabase/pg-delta": "1.0.0-alpha.60",
|
|
35
35
|
"citty": "0.2.2",
|
|
36
36
|
"pg": "8.23.1",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"pg-connection-string": "2.14.1",
|
|
38
|
+
"smol-toml": "1.9.1",
|
|
39
|
+
"zod": "^4.6.7",
|
|
40
|
+
"simetra": "0.3.0-next.1"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@arethetypeswrong/cli": "0.18.5",
|
|
42
44
|
"@eslint/js": "^10.0.1",
|
|
43
|
-
"@modelcontextprotocol/client": "2.
|
|
44
|
-
"@types/node": "^24.
|
|
45
|
+
"@modelcontextprotocol/client": "2.4.0",
|
|
46
|
+
"@types/node": "^24.19.2",
|
|
45
47
|
"@types/pg": "^8.23.1",
|
|
46
48
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
47
|
-
"eslint": "^10.
|
|
49
|
+
"eslint": "^10.14.0",
|
|
48
50
|
"publint": "0.3.25",
|
|
49
|
-
"tsdown": "0.23.
|
|
51
|
+
"tsdown": "0.23.5",
|
|
50
52
|
"tsx": "4.23.15",
|
|
51
53
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
52
|
-
"typescript-eslint": "^8.
|
|
53
|
-
"vitest": "^5.0
|
|
54
|
+
"typescript-eslint": "^8.72.1",
|
|
55
|
+
"vitest": "^5.1.0"
|
|
54
56
|
},
|
|
55
57
|
"publishConfig": {
|
|
56
58
|
"access": "public"
|
|
@@ -64,6 +66,8 @@
|
|
|
64
66
|
"test": "vitest run --project unit",
|
|
65
67
|
"test:watch": "vitest --project unit",
|
|
66
68
|
"test:db": "vitest run --project db",
|
|
67
|
-
"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"
|
|
68
72
|
}
|
|
69
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
|
|
@@ -57,6 +62,10 @@ are served by `simetra mcp` with the same input.
|
|
|
57
62
|
`<table>_simetra_touch` triggers calling it) are never written, even into
|
|
58
63
|
a directory without metadata: the platform generates them. Another trigger
|
|
59
64
|
that calls `simetra.touch()` is the table's own and is written.
|
|
65
|
+
A foreign key to the table of an object of a kind is written by its key —
|
|
66
|
+
`references: { object, key: "ref" }` or `key: "scopedRef"` for the
|
|
67
|
+
in-tenant pair (scope column, key); a foreign key on other columns of such
|
|
68
|
+
a table is unrepresentable.
|
|
60
69
|
5. **Diff.** Run `diff` on the same directory. **An empty diff right after
|
|
61
70
|
introspect is the baseline; any non-empty result is a finding** — report it
|
|
62
71
|
instead of editing the metadata until it disappears.
|
|
@@ -108,7 +117,8 @@ not express through metadata (CustomTable and PgEnum modules, shared
|
|
|
108
117
|
`metadata/sql/`, statements a closed form does not accept).
|
|
109
118
|
|
|
110
119
|
- The list is a ratchet and only shrinks. `introspect` is the only writer and
|
|
111
|
-
derives it from the database; `fix`
|
|
120
|
+
derives it from the database; `fix` removes stale entries (and repairs function
|
|
121
|
+
declarations, see below); `compile`
|
|
112
122
|
fails with `sql.debt-grows` on a debt unit that is not listed and with
|
|
113
123
|
`sql.debt-stale` on an entry that is no longer debt. Without that, verbatim
|
|
114
124
|
SQL would grow back unnoticed.
|
|
@@ -117,6 +127,43 @@ not express through metadata (CustomTable and PgEnum modules, shared
|
|
|
117
127
|
`simetra-metadata`), then run `fix`: it removes the entry that became stale.
|
|
118
128
|
- A project that already has a `sql/` folder but no list is seeded by running
|
|
119
129
|
`introspect` again on the same directory.
|
|
130
|
+
- Debt is not a free pass. A function with DDL, a non-literal `EXECUTE`
|
|
131
|
+
(partition maintenance, statistics through `EXECUTE format(…)`), a call of
|
|
132
|
+
a function that executes SQL text, or a body in another language fails
|
|
133
|
+
`compile` with `sql.function-body-statement`; SQL that writes a table of a
|
|
134
|
+
kind fails with `sql.kind-table-verbatim`. Rewrite such a function with
|
|
135
|
+
static SQL or remove it.
|
|
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.
|
|
120
167
|
|
|
121
168
|
## Adopted triggers
|
|
122
169
|
|
|
@@ -129,7 +176,11 @@ class `platform` only when the kind replaces it, and `plan` refuses
|
|
|
129
176
|
`updatedAt` → the row mechanics (`<table>_simetra_touch`). The mechanics also
|
|
130
177
|
fires on insert, which only makes the date and the version right there too.
|
|
131
178
|
- A trigger calling the same handler with the same timing, level and events →
|
|
132
|
-
an `EventSubscription` with that handler (see `simetra-metadata`)
|
|
179
|
+
an `EventSubscription` with that handler (see `simetra-metadata`), but only
|
|
180
|
+
when the handler only checks and assigns `NEW`. A handler that writes a
|
|
181
|
+
table, runs `EXECUTE` or calls a function that writes is refused
|
|
182
|
+
(`sql.head-not-allowed`): move the write into a command or a TypeScript
|
|
183
|
+
hook first, or keep the table a `CustomTable`.
|
|
133
184
|
- `INSERT OR UPDATE OF <columns>` → a subscription with `whenChanged` on the
|
|
134
185
|
same columns. The plan warns (`plan.update-of-narrowed`): the subscription
|
|
135
186
|
fires only when a value actually changes, not on every `UPDATE` that sets
|
|
@@ -169,3 +220,31 @@ class `platform` only when the kind replaces it, and `plan` refuses
|
|
|
169
220
|
- `diff` also reports `applyState`: `absent` while the database holds none of
|
|
170
221
|
the platform's apply state (the first `apply` creates it, so it is not a
|
|
171
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, …}` |
|
|
@@ -30,11 +39,15 @@ diagnostics themselves.
|
|
|
30
39
|
| Does the database match the metadata? | `diff` | `simetra diff [dir] --tables a,b` | `diff` with `{tables?}` |
|
|
31
40
|
| Plan bringing the database to the metadata (writes `plans/…plan.json`) | `plan` | `simetra plan [dir]` | `plan` with `{}` |
|
|
32
41
|
| Apply a reviewed plan to the database | `apply` | `simetra apply <plan> [dir] --plan-hash <hex> --yes` | `apply` with `{plan, planHash, allow?, confirm}` |
|
|
42
|
+
| Create the platform's cluster roles once per server (before the first `plan`); reads the project file | `roles` | `simetra roles` | `roles` with `{}` |
|
|
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}` |
|
|
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}` |
|
|
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}` |
|
|
33
47
|
|
|
34
|
-
`
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
writes to it.
|
|
48
|
+
`fix`, `create`, `add`, `declare-function`, `rename`, `delete`, `promote`, `introspect` change files;
|
|
49
|
+
`plan` writes only its plan file; others only read files. `introspect`, `diff`,
|
|
50
|
+
`plan` read the database; `apply`, `roles`, `rights-maintenance` write to it.
|
|
38
51
|
|
|
39
52
|
## Examples
|
|
40
53
|
|
|
@@ -140,9 +153,10 @@ says why a mapping is wrong, so read its diagnostics):
|
|
|
140
153
|
(`plan.service-role-access-lost`); keep the table a `CustomTable` until
|
|
141
154
|
platform commands exist. An explicit adopted grant to the service role takes
|
|
142
155
|
the class `removed`.
|
|
143
|
-
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
- Closed-shell query functions move to the kind's module; functions reading
|
|
157
|
+
the promoted tables are rewritten in place. Other SQL that reads or writes
|
|
158
|
+
them is refused (`promote.debt-writes-table`): rewrite or drop it first.
|
|
159
|
+
Incoming cascades become `restrict`: `references/sql-trust-boundary.md`.
|
|
146
160
|
- `sharedFunctions` lists identities of those module functions that move to
|
|
147
161
|
`sql/<schema>/<function>.sql` instead; `consumerLabels` the values by which
|
|
148
162
|
the consumer's data encodes the object (the record's `labelTranslation`
|
|
@@ -170,11 +184,10 @@ offending field (for example `target.kind`); nothing is written.
|
|
|
170
184
|
- Exit code: `0` ok (warnings allowed), `1` the result has error diagnostics
|
|
171
185
|
(this includes refused operations such as `operation.delete-referenced`)
|
|
172
186
|
or, for `diff`, differences or errors — `0` from `diff` means the database
|
|
173
|
-
matches the metadata,
|
|
174
|
-
|
|
175
|
-
(bad
|
|
176
|
-
|
|
177
|
-
`isError`, with diagnostics for the exit-1 ones.
|
|
187
|
+
matches the metadata, `2` the call itself was refused: input that does not match
|
|
188
|
+
the tool's schema (bad JSON, unknown field), a missing `--yes`, a usage or I/O
|
|
189
|
+
error (bad flag, missing directory) or an unknown `explain` target. In MCP the
|
|
190
|
+
same cases are `isError`, with diagnostics for the exit-1 ones.
|
|
178
191
|
- Text diagnostics look like `path/File.meta.json:LINE:COL severity code message`.
|
|
179
192
|
A diagnostic without a position (the input as a whole, a missing file) has no
|
|
180
193
|
`LINE:COL`. The code (`file.kind-mismatch`, …) is the stable handle; do not
|
|
@@ -184,7 +197,8 @@ offending field (for example `target.kind`); nothing is written.
|
|
|
184
197
|
- `--locale en|uk` picks the message language (default `en`); code and
|
|
185
198
|
location are identical in both.
|
|
186
199
|
- Start from the first error: one root cause often produces several follow-ups.
|
|
187
|
-
- Artifacts (`snapshot.json`, `desired-state.sql`, `entities.d.ts
|
|
200
|
+
- Artifacts (`snapshot.json`, `desired-state.sql`, `entities.d.ts`,
|
|
201
|
+
`runtime-catalog.json`, `client-catalog.json`) are written
|
|
188
202
|
only with `compile --out <dir>`, and `--out` takes one metadata directory per run.
|
|
189
203
|
|
|
190
204
|
## Mutations are checked, never raw
|
|
@@ -194,8 +208,7 @@ offending field (for example `target.kind`); nothing is written.
|
|
|
194
208
|
- `create`, `add`, `rename`, `delete` also need the current metadata to compile
|
|
195
209
|
cleanly (`operation.input-invalid` otherwise): run `fix` or repair the file by
|
|
196
210
|
hand first.
|
|
197
|
-
- `--dry-run` (MCP: `dryRun: true`) reports the changes without writing. Use it
|
|
198
|
-
before the real run.
|
|
211
|
+
- `--dry-run` (MCP: `dryRun: true`) reports the changes without writing. Use it first.
|
|
199
212
|
- `delete` is destructive: it needs `--yes` (MCP: `confirm: true`) and is refused
|
|
200
213
|
while anything references the target: the result then carries
|
|
201
214
|
`operation.delete-referenced` listing every reference (exit 1, nothing
|
|
@@ -223,7 +236,7 @@ Attribute properties (an element of `attributes`):
|
|
|
223
236
|
`{ "empty": "object" | "array" }` on a scalar `Json`.
|
|
224
237
|
- `unique`: `true`, or `"ignoreCase"` on a scalar String or Text. `uniqueWithin`: `"owner"` or `"parent"`,
|
|
225
238
|
only on a catalog's own attributes and only when the catalog has owners or a
|
|
226
|
-
hierarchy.
|
|
239
|
+
hierarchy. Write no cycle check: the database rejects a `parent` cycle from any writer; a `parent` change needs `READ COMMITTED`.
|
|
227
240
|
- Numbers (scalar only): `nonNegative`, `positive`, `minValue`, `maxValue`.
|
|
228
241
|
- Strings and text (scalar only): `minLength`, `pattern`. The pattern must
|
|
229
242
|
mean the same in JavaScript and Postgres: no named groups, `\p{}`, `\k<>`,
|
|
@@ -231,12 +244,18 @@ Attribute properties (an element of `attributes`):
|
|
|
231
244
|
character as itself or as `\uXXXX`.
|
|
232
245
|
- `personalData: true` marks personal data (a name, a phone, an address):
|
|
233
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`.
|
|
234
252
|
|
|
235
253
|
Object properties:
|
|
236
254
|
|
|
237
255
|
- `indexes` on a Catalog, a Document and their tabular sections: a list of
|
|
238
|
-
composite indexes, each `{ "attributes": [name | { "name": …, "order": "desc" }] }`.
|
|
239
|
-
- `
|
|
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".
|
|
240
259
|
- Project file: `storageBuckets`, a list of `{ "bucket": …, "scopeKind": … }`.
|
|
241
260
|
|
|
242
261
|
An attribute with properties, added through the tool:
|
|
@@ -264,18 +283,20 @@ events only) and `handler` (`{ schema?, name }`, a no-argument function that
|
|
|
264
283
|
`FOR EACH ROW` triggers, named after `physicalName`, on every source: `before*`
|
|
265
284
|
is `BEFORE`, `on*` is `AFTER`, `*Write` is `INSERT OR UPDATE`, `*Delete` is
|
|
266
285
|
`DELETE`. With `whenChanged`, `<physicalName>` fires on an `UPDATE` that changes
|
|
267
|
-
a listed column (`IS DISTINCT FROM`), `<physicalName>_insert` on every `INSERT
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
286
|
+
a listed column (`IS DISTINCT FROM`), `<physicalName>_insert` on every `INSERT`;
|
|
287
|
+
on a table with carrier copies (below) a subscription without `whenChanged`
|
|
288
|
+
gets the same pair, its `UPDATE` trigger firing on a content change only.
|
|
289
|
+
No event is insert-only; `TG_OP` tells insert from update. The same events as
|
|
290
|
+
TypeScript hooks of a command (object modules): `references/object-modules.md`.
|
|
271
291
|
|
|
272
292
|
Catalogs and Documents get the row mechanics trigger `<table>_simetra_touch`
|
|
273
|
-
(the single platform function `simetra.touch()`):
|
|
274
|
-
an update
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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`,
|
|
296
|
+
firing on a content change only. Never maintain them (`moddatetime`) or list
|
|
297
|
+
them in `whenChanged`. A `beforeWrite` handler never assigns `NEW.updated_at`
|
|
298
|
+
or `NEW.version` and never replaces the row (`NEW := …`, `SELECT … INTO NEW`):
|
|
299
|
+
it returns `NEW`, or `NULL` to skip the write, never `OLD` or a copy of the row.
|
|
279
300
|
|
|
280
301
|
## Users, membership and rights
|
|
281
302
|
|
|
@@ -289,8 +310,10 @@ declarations too: `customActions`, `ownership`, `rightsContainer`,
|
|
|
289
310
|
them is a reference, so `rename` rewrites it and `delete` refuses while it is
|
|
290
311
|
used; the compiler checks them (rules `users.*`, `rights.*`) and `explain`
|
|
291
312
|
shows the derived rights contract, a role's contract and the rows of the
|
|
292
|
-
rights projection. Forms of each field
|
|
293
|
-
`references/people-and-rights.md
|
|
313
|
+
rights projection. Forms of each field, who reads what, and what carrier copies
|
|
314
|
+
forbid a `beforeWrite` handler: `references/people-and-rights.md` (also the
|
|
315
|
+
system rights catalogs and tenant creation: a scope root whose creator gets a
|
|
316
|
+
`rootCreator` role, with `creatorMember`).
|
|
294
317
|
|
|
295
318
|
```json simetra:add
|
|
296
319
|
{
|
|
@@ -300,41 +323,35 @@ rights projection. Forms of each field:
|
|
|
300
323
|
}
|
|
301
324
|
```
|
|
302
325
|
|
|
303
|
-
The
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
event handler or SQL unit may use it, and there is no `metadata/sql/simetra/`
|
|
307
|
-
folder (`schema.reserved`). In SQL, the
|
|
308
|
-
current user is `(select simetra.current_user_id())`, written exactly so in a
|
|
309
|
-
policy (`sql.bare-current-user` rejects a bare call there); it is `NULL` for
|
|
310
|
-
an anonymous session or an anonymous sign-in of the provider, a service
|
|
311
|
-
session and an invalid user.
|
|
326
|
+
The PG schema `simetra` (identities, the current user, provisioning) belongs
|
|
327
|
+
to the platform and is reserved (`schema.reserved`); in SQL the current user is
|
|
328
|
+
`(select simetra.current_user_id())`. Both rules in full: the same reference.
|
|
312
329
|
|
|
313
330
|
## The SQL module: closed forms only
|
|
314
331
|
|
|
315
332
|
The `.sql` module of an object of a 1C kind accepts only:
|
|
316
333
|
|
|
317
|
-
- Functions in the closed shell
|
|
318
|
-
volatility
|
|
319
|
-
|
|
334
|
+
- Functions in the closed shell, with `SET search_path = ''`, an explicit
|
|
335
|
+
volatility and no overloads: a subscription handler in `plpgsql` that only
|
|
336
|
+
checks, any other function a query function (`LANGUAGE sql`, one `SELECT`).
|
|
320
337
|
- Row rules: `ALTER TABLE <own table> ADD CONSTRAINT <name> CHECK (<rule>)`
|
|
321
338
|
within a small grammar. The constraint needs a name and must target the
|
|
322
339
|
object's own table or one of its own tabular-section tables.
|
|
323
340
|
- Movement query blocks in a document module.
|
|
324
341
|
|
|
342
|
+
A verbatim policy or trigger on a table of a kind, or SQL that writes one, is
|
|
343
|
+
an error, never debt (`sql.kind-table-verbatim`): use a right, an
|
|
344
|
+
`EventSubscription` or a command. Function bodies, session settings
|
|
345
|
+
(`sql.command-context-write`), code inside a command (`sql.head-not-allowed`),
|
|
346
|
+
domains, foreign keys, scope roots, extensions and promotion gates:
|
|
347
|
+
`references/sql-trust-boundary.md`.
|
|
348
|
+
|
|
325
349
|
Any other statement is rejected (`sql.statement-not-allowed`, `sql.closed-shell`,
|
|
326
350
|
`sql.row-rule-grammar`, …) with a hint that names the property that replaces it.
|
|
327
351
|
Follow the hint instead of rewording the statement. `CustomTable` and `PgEnum`
|
|
328
352
|
modules and the shared `metadata/sql/` folder are not closed: their content is
|
|
329
|
-
debt (below).
|
|
330
|
-
|
|
331
|
-
Privileges on what the platform owns are generated: `EXECUTE` on a declared
|
|
332
|
-
scope set function and on a subscription handler, and every grant on a kind's
|
|
333
|
-
tables. In debt SQL (a `CustomTable` or `PgEnum` module, the shared
|
|
334
|
-
`metadata/sql/`) a verbatim `GRANT`/`REVOKE` on them fails with
|
|
335
|
-
`sql.generated-grant` (a kind's own module rejects any). `simetra fix` removes
|
|
336
|
-
the statement (and its file, if left empty) only when every target belongs to
|
|
337
|
-
the platform; one that also names other objects you split by hand. A grant on another overload of the same name is not affected.
|
|
353
|
+
debt (below). Privileges on what the platform owns are generated
|
|
354
|
+
(`sql.generated-grant`).
|
|
338
355
|
|
|
339
356
|
A row rule shape:
|
|
340
357
|
|
|
@@ -342,6 +359,20 @@ A row rule shape:
|
|
|
342
359
|
ALTER TABLE <schema>.<own_table> ADD CONSTRAINT <rule_name> CHECK (<rule>);
|
|
343
360
|
```
|
|
344
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
|
+
|
|
345
376
|
## SQL debt
|
|
346
377
|
|
|
347
378
|
`metadata/sql-debt.json` lists the verbatim SQL units that the compiler still
|
|
@@ -356,6 +387,9 @@ tolerates. It only shrinks:
|
|
|
356
387
|
function; moving it to another file does not make it acceptable.
|
|
357
388
|
- A project with an existing `sql/` folder and no list is seeded by running
|
|
358
389
|
`introspect` again (see `simetra-adoption`).
|
|
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`.
|
|
359
393
|
|
|
360
394
|
## The database: introspect and diff
|
|
361
395
|
|
|
@@ -369,68 +403,13 @@ creates and `diff` does not count as a difference; `present` otherwise.
|
|
|
369
403
|
|
|
370
404
|
## The database: plan and apply
|
|
371
405
|
|
|
372
|
-
`plan`
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
of the reviewed plan, confirmation (`--yes`, MCP `confirm: true`), and in
|
|
380
|
-
`allow` the id of every step that drops data or relaxes a guarantee and
|
|
381
|
-
`drift` when the plan carries drift; the plan output says which items need
|
|
382
|
-
it. `rehearse` runs the plan and rolls it back, but still takes the same
|
|
383
|
-
locks as `apply`. It also builds the desired shadow database and proves on the
|
|
384
|
-
same connection that the catalog equals the desired state, so it holds the
|
|
385
|
-
plan's locks a little longer. A successful `rehearse` writes its report to
|
|
386
|
-
`plans/<from>-<to>.rehearsal.json` next to the plan.
|
|
387
|
-
|
|
388
|
-
Before the end of the transaction, `apply` and `rehearse` re-validate function
|
|
389
|
-
bodies and fire deferred constraints; an invalid constraint or index that the
|
|
390
|
-
desired state does not have is refused. An `apply.function-check-blind` warning lists
|
|
391
|
-
functions the check cannot see (another language, no `EXECUTE` for the role, a
|
|
392
|
-
trigger function without a trigger): nothing proved their bodies, so review
|
|
393
|
-
them by hand.
|
|
394
|
-
|
|
395
|
-
When the role has global default privileges, a plan also ends with environment
|
|
396
|
-
steps: explicit GRANT/REVOKE that cancel them on the objects the plan creates.
|
|
397
|
-
The output shows them as their own group, `environment rights: the global
|
|
398
|
-
default privileges of role <role>`; review them with the rest of the plan.
|
|
399
|
-
If the environment changes before the apply, it is refused
|
|
400
|
-
(`apply.target-changed`); plan again. A plan file from an older tool version is
|
|
401
|
-
refused too: rebuild it with `plan`.
|
|
402
|
-
|
|
403
|
-
A promotion plan's `allow` also takes the `access:<table>`,
|
|
404
|
-
`delete:<table>.<constraint>`, `remove:<table>` and `repair:<table>` items its
|
|
405
|
-
output lists; a repair rewrites existing values with the fill expression shown.
|
|
406
|
-
A promotion is applied only with a valid rehearsal report: rehearse the plan on
|
|
407
|
-
a copy of the target with data first. Point the rehearsal at the copy through
|
|
408
|
-
the connection variable: `simetra apply --rehearse --database-url-env <VAR>`
|
|
409
|
-
on the command line, or an MCP server launched with
|
|
410
|
-
`simetra mcp --database-url-env <VAR>` (an MCP server's database is fixed at
|
|
411
|
-
launch). Make the copy from the target after the plan, restore it as the plan's
|
|
412
|
-
role with `pg_restore --no-owner`, on a server with the same PostgreSQL major
|
|
413
|
-
version, encoding and collation; otherwise the rehearsal is refused as not a
|
|
414
|
-
copy of the plan's target (`apply.target-changed`). Rehearsing on the target
|
|
415
|
-
itself is allowed, but it holds the target's locks for the whole run: make it
|
|
416
|
-
a deliberate choice of the owner, not a default. `apply` refuses without a
|
|
417
|
-
report (`apply.rehearsal-required`), with a stale one (`apply.rehearsal-stale`:
|
|
418
|
-
another plan, report format, server, ledger head, or not one row count per
|
|
419
|
-
promoted table), and when a table has rows on the target but none on the copy
|
|
420
|
-
(`apply.rehearsal-copy-empty`); it warns when the copy has fewer rows
|
|
421
|
-
(`apply.rehearsal-fewer-rows`) or when the statement timeout computed from the
|
|
422
|
-
report exceeds what Postgres accepts (`apply.rehearsal-timeout-unbounded`).
|
|
423
|
-
|
|
424
|
-
Which connection to use:
|
|
425
|
-
|
|
426
|
-
- Reads of the target (`introspect`, `diff`, `plan`) run in short read-only
|
|
427
|
-
transactions and work through a transaction-mode pooler.
|
|
428
|
-
- The shadow database of `diff` and `plan` needs a direct or session-mode
|
|
429
|
-
connection: it is created, reached by name and loaded with session settings
|
|
430
|
-
that a transaction-mode pooler is not guaranteed to keep. With a pooled target
|
|
431
|
-
connection, point `--shadow-url-env` at a direct one.
|
|
432
|
-
- A long `apply` wants a direct or session-mode connection too: a pooler may
|
|
433
|
-
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:
|
|
434
413
|
|
|
435
414
|
```json simetra:apply
|
|
436
415
|
{
|
|
@@ -441,13 +420,33 @@ Which connection to use:
|
|
|
441
420
|
}
|
|
442
421
|
```
|
|
443
422
|
|
|
444
|
-
|
|
445
|
-
|
|
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
|
+
```
|
|
446
432
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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');`.
|
|
451
450
|
|
|
452
451
|
## Agents over MCP
|
|
453
452
|
|
|
@@ -456,23 +455,14 @@ pnpm exec simetra mcp
|
|
|
456
455
|
pnpm exec simetra mcp --read-only
|
|
457
456
|
pnpm exec simetra mcp --database-url-env STAGING_DATABASE_URL
|
|
458
457
|
pnpm exec simetra mcp --allow-database-write
|
|
458
|
+
pnpm exec simetra mcp --data-url-env SIMETRA_DEV_DATA_URL --as <user-uuid>
|
|
459
459
|
```
|
|
460
460
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
-
|
|
466
|
-
with a hint to remove `--read-only` from the server's args. Ask the owner
|
|
467
|
-
before restarting the server without it.
|
|
468
|
-
- `apply` writes to the database only when the server runs with
|
|
469
|
-
`--allow-database-write`; without it `apply` is refused with a hint to add
|
|
470
|
-
the flag. Ask the owner; never add it yourself. `--read-only` refuses
|
|
471
|
-
`plan` and `apply` too: they write their files under `plans/`.
|
|
472
|
-
- `plan` and `apply` have no `dryRun`: review with `plan`, and check on the
|
|
473
|
-
database with `rehearse`.
|
|
474
|
-
- The server reads the disk on every call, so edits made by hand between calls
|
|
475
|
-
are seen.
|
|
461
|
+
`simetra mcp` serves the same tools as the CLI and reads the disk on every
|
|
462
|
+
call. Its launch flags are the owner's decision: a refused call names the flag
|
|
463
|
+
that would allow it; ask the owner, never change the server's args yourself.
|
|
464
|
+
What each flag allows, and the data tools over the development database:
|
|
465
|
+
`references/agents-over-mcp.md`.
|
|
476
466
|
|
|
477
467
|
## Pre-commit and CI
|
|
478
468
|
|
|
@@ -488,4 +478,4 @@ pnpm exec simetra compile --all --staged
|
|
|
488
478
|
|
|
489
479
|
A rejected commit means the staged content does not compile: run
|
|
490
480
|
`simetra compile --all` for the working tree, fix, `git add`, commit again. Do
|
|
491
|
-
not bypass the hook with `--no-verify`.
|
|
481
|
+
not bypass the hook with `--no-verify`. Setup and CI: `references/project-setup.md`.
|