@jskit-ai/agent-docs 0.1.318 → 0.1.320
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/guide/agent/app-setup/authentication.md +9 -4
- package/guide/agent/app-setup/multi-homing.md +24 -7
- package/guide/agent/framework/data-access.md +169 -14
- package/guide/agent/framework/typed-features.md +51 -9
- package/package.json +1 -1
- package/patterns/feature-package/example/booking-engine/package.json +1 -1
- package/patterns/minimal-foundation/example/package.json +4 -4
- package/patterns/shell-foundation/example/package.json +5 -5
- package/patterns/shell-foundation/example/packages/main/package.json +1 -1
- package/reference/autogen/KERNEL_MAP.md +4 -2
- package/reference/autogen/PATTERN_INDEX.md +38 -38
- package/reference/autogen/packages/auth-web.md +2 -0
- package/reference/autogen/packages/http-web.md +2 -0
- package/reference/autogen/packages/kernel.md +7 -4
- package/reference/autogen/packages/resource-runtime.md +6 -1
- package/skills/jskit/references/data-access.md +169 -14
- package/skills/jskit/references/heuristics/INDEX.md +2 -2
- package/skills/jskit/references/heuristics/live-actions.md +5 -0
- package/skills/jskit/references/heuristics/row-policies.md +3 -0
- package/skills/jskit/references/heuristics/server-search.md +1 -1
- package/skills/jskit/references/heuristics/typed-features.md +2 -0
- package/skills/jskit/references/multi-homing.md +24 -7
- package/skills/jskit/references/pattern-index.md +38 -38
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +4 -4
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +5 -5
- package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
- package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +4 -4
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
- package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
- package/skills/jskit/references/typed-features.md +51 -9
|
@@ -430,10 +430,13 @@ request, `{ kind: "anonymous" }` for one by no one, and `{ kind: "system" }` or
|
|
|
430
430
|
`reason`, for background work. A job names a user only as `actorId`, the
|
|
431
431
|
person it works for ([below](#background-work)), so never read a missing actor
|
|
432
432
|
as an anonymous request. The owner's policy also receives the capabilities its
|
|
433
|
-
feature requires (and its optional ones), by local name, as
|
|
434
|
-
same ones its setup receives: a policy that needs another
|
|
435
|
-
declares that feature's capability in `requires` and reads
|
|
436
|
-
|
|
433
|
+
feature requires (and its optional and late ones), by local name, as
|
|
434
|
+
`requires`, the same ones its setup receives: a policy that needs another
|
|
435
|
+
feature's answer declares that feature's capability in `requires` and reads
|
|
436
|
+
`requires.<name>`. When that feature requires the policy's own feature, the
|
|
437
|
+
two form a ring; the policy's feature declares the capability `late` instead
|
|
438
|
+
([Capability cycles](#capability-cycles)). A policy runs on every read, so
|
|
439
|
+
what it asks there must be cheap.
|
|
437
440
|
|
|
438
441
|
```js
|
|
439
442
|
// good: one predicate on the row being read
|
|
@@ -468,7 +471,12 @@ subquery to the row with `whereExists`: over `ownTable(name)`, which may join
|
|
|
468
471
|
the owner's other tables, or over another owner's join source. A policy is told
|
|
469
472
|
the call's `options`, `{ context, trx }` as the caller passed them, and passes
|
|
470
473
|
them on unchanged to `joinSource({ alias }, options)`, so the join source reads
|
|
471
|
-
in the caller's scope and transaction; never build them by hand.
|
|
474
|
+
in the caller's scope and transaction; never build them by hand. `options.trx`
|
|
475
|
+
names the transaction the read runs in: the caller's, or, for a write whose
|
|
476
|
+
caller named none, the one json-rest-api opens for it, which the lookup before
|
|
477
|
+
a patch and the read-back after a create run in. So an owner API the policy
|
|
478
|
+
calls with its `options` (a join source, or a handle read such as a role check)
|
|
479
|
+
joins that transaction and never waits for a second connection.
|
|
472
480
|
|
|
473
481
|
```js
|
|
474
482
|
// good: a member of the document's team sees it, through the teams owner's join source
|
|
@@ -490,6 +498,45 @@ function teamDocumentsPolicy({ query, caller, column }) {
|
|
|
490
498
|
}
|
|
491
499
|
```
|
|
492
500
|
|
|
501
|
+
A policy whose rule reads another owner's rows as stored (a document is
|
|
502
|
+
visible while its folder is open, whether or not the reader may see the folder
|
|
503
|
+
itself) reads them through that owner's API, never through a context it builds.
|
|
504
|
+
The owner answers a join source of its rows under its own `systemScope`,
|
|
505
|
+
narrowed to the call's workspace, so the rows stay that workspace's and `jskit
|
|
506
|
+
check` lists the reason. The policy passes its `options` on unchanged, as
|
|
507
|
+
always, and returns early for background work, whose own context already
|
|
508
|
+
decides. It still only narrows: the stored rows feed its predicate and are
|
|
509
|
+
never answered, so the reader sees no folder it could not see before.
|
|
510
|
+
|
|
511
|
+
```js
|
|
512
|
+
// good: the folders' owner API, in the folders feature, whose setup receives systemContext
|
|
513
|
+
function storedSource({ alias }, options) {
|
|
514
|
+
const context = systemContext("the documents' row policy reads each folder's status as stored")
|
|
515
|
+
.forWorkspace(resolveWorkspaceScopeValue(options.context));
|
|
516
|
+
return folders.joinSource({ alias }, { ...passedOn(options), context });
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// good: the documents' policy, which requires the folders' owner API
|
|
520
|
+
async function openFolderDocuments({ query, caller, column, options, requires }) {
|
|
521
|
+
if (caller.kind !== "user") {
|
|
522
|
+
return caller.kind !== "anonymous";
|
|
523
|
+
}
|
|
524
|
+
const folder = await requires.folders.storedSource({ alias: "f" }, options);
|
|
525
|
+
query.whereExists(folder.query.select(1).whereColumn(folder.column("id"), column("folderId")).where(folder.column("status"), "open"));
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
A policy never walks a tree with a recursive query (`withRecursive`). No builder
|
|
531
|
+
it holds takes a common table expression, and a walk that starts at the row
|
|
532
|
+
being read does not compile on MariaDB, which lets no outer column into a
|
|
533
|
+
recursive query's first member; a walk that starts elsewhere (the reader's
|
|
534
|
+
grants, walking down) reads the reader's whole subtree on every read. Keep the
|
|
535
|
+
tree's ancestry stored instead: its owner writes a closure table (each node's
|
|
536
|
+
ancestors, one row each, with their depth) in the same transaction that adds
|
|
537
|
+
or moves a node, and the policy ties one `whereExists` over that table's join
|
|
538
|
+
source to the row, on indexed columns, on every database.
|
|
539
|
+
|
|
493
540
|
A rule that depends on the caller's role reads `context.permissions` with
|
|
494
541
|
`hasPermission(context.permissions, "bookings.view-all")` from
|
|
495
542
|
`@jskit-ai/kernel/shared/support`, never with `includes()`. A role may hold
|
|
@@ -722,6 +769,21 @@ or a counter row taken with `lock(id)`. Every lock needs a transaction; SQLite
|
|
|
722
769
|
runs one transaction at a time, so there is no row lock to take. Take locks in
|
|
723
770
|
one order on every path, a parent before its children.
|
|
724
771
|
|
|
772
|
+
`lockWhere` takes that order from `sort` too: `lockWhere({ batchId }, {
|
|
773
|
+
...txOptions, sort: ["moduleKey"] })` locks the rows in `sort` order
|
|
774
|
+
(fields, `"-moduleKey"` for descending), then by id, and answers them in it,
|
|
775
|
+
so two paths that lock overlapping rows wait for each other instead of
|
|
776
|
+
deadlocking. `limit` locks only the first rows of that order, by id without a
|
|
777
|
+
`sort`: a check whether any row matches, or the lock of one row by a unique key
|
|
778
|
+
other than its id, takes `limit: 1`, one statement as `lock(id)` is
|
|
779
|
+
(`workspaces.memberships.lockByWorkspaceIdAndUserId` locks its membership so).
|
|
780
|
+
Without either, `lockWhere` locks every match in id order (on MySQL and MariaDB
|
|
781
|
+
in the order of the index it reads, below), at most 1,000 (more throw), and
|
|
782
|
+
PostgreSQL reads them once more under its locks, for a row that started to
|
|
783
|
+
match while it waited; with a `limit` it stops once it holds that many. A
|
|
784
|
+
`limit` outside 1 to 1,000, or a `sort` on no stored field, is refused before
|
|
785
|
+
any statement.
|
|
786
|
+
|
|
725
787
|
A lock answers the rows it locks, with the fields `fields` names. Its
|
|
726
788
|
`include` names belongs-to relationships (`include: ["customer"]`, or
|
|
727
789
|
`"batch.yard"` a level further): after its own rows, the lock locks the
|
|
@@ -767,7 +829,12 @@ from a request: every id listed is locked, a hidden one too, before it is left
|
|
|
767
829
|
out. And `lockWhere` needs an index that starts with the ownership columns (on
|
|
768
830
|
a table with no owners, with a column the filters compare); without one it
|
|
769
831
|
refuses with `RestApiBulkWriteUnsupportedError` naming the index to add in a
|
|
770
|
-
migration.
|
|
832
|
+
migration. With `sort` or `limit` the index must also read the rows in the
|
|
833
|
+
lock's order, since the database locks them in the order it reads them: after
|
|
834
|
+
the ownership columns and the columns the filters fix to one value, it holds
|
|
835
|
+
the sort's columns, ascending, and then nothing but the id, and the sort's
|
|
836
|
+
fields go one way (all ascending or all descending). A unique key the filters
|
|
837
|
+
fix whole, as a membership's workspace and user are, needs nothing more.
|
|
771
838
|
|
|
772
839
|
A worker taking the next job uses `claim({ filters, sort, take }, txOptions)`,
|
|
773
840
|
which skips rows another worker holds. A record that serializes work on a key
|
|
@@ -822,8 +889,15 @@ await memberships.patch(input.membershipId, { lastFiledAt: new Date() }, txOptio
|
|
|
822
889
|
```
|
|
823
890
|
|
|
824
891
|
Locks stay on the owner's handle and its owner API. A `scopedQuery()` or
|
|
825
|
-
`joinSource()` builder takes no lock,
|
|
826
|
-
|
|
892
|
+
`joinSource()` builder takes no lock, not even a shared one: PostgreSQL's `FOR
|
|
893
|
+
SHARE OF` an alias would lock only that source's rows, but MariaDB has no `FOR
|
|
894
|
+
SHARE OF` at all, and its `LOCK IN SHARE MODE` covers every row the statement
|
|
895
|
+
examines, in every table. A report that needs another
|
|
896
|
+
owner's rows unchanged until it commits first locks them through that owner's
|
|
897
|
+
handle or owner API with `lockMode: "share"` (by a unique key with `limit:
|
|
898
|
+
1`), then reads its join. A row policy is not told a read's lock mode, and
|
|
899
|
+
never takes a lock: it says which rows a caller may see, the same for every
|
|
900
|
+
read, and the lock call it narrows takes its own mode. Rows
|
|
827
901
|
of several owners are never locked in one statement over a join, which on
|
|
828
902
|
MySQL and MariaDB locks every joined row the read examines: lock each owner's
|
|
829
903
|
rows with its own `lock`, `lockMany` or `lockWhere`, the owners in one fixed
|
|
@@ -1095,7 +1169,10 @@ then narrowed is also wrong, since the row wanted can sit past it.
|
|
|
1095
1169
|
it.
|
|
1096
1170
|
- A CRUD list refuses a query key it does not take with a 400
|
|
1097
1171
|
(`crud.query.undeclaredKeys`). A list filter is declared in the feature's
|
|
1098
|
-
`listFilterQueryValidator` and the resource's searchSchema.
|
|
1172
|
+
`listFilterQueryValidator` and the resource's searchSchema. The person sees
|
|
1173
|
+
only that nothing was loaded and to reload or tell support, with no Retry;
|
|
1174
|
+
the keys refused, the keys the list takes and how to declare one are in the
|
|
1175
|
+
server log, as a warning, and in the error's `details`.
|
|
1099
1176
|
- Prove a capped read with a test that seeds past the cap and makes the row
|
|
1100
1177
|
the cap leaves out (the oldest, for a newest-first read) the one that
|
|
1101
1178
|
matches: the read that asks for it finds it; a read narrowed in code does
|
|
@@ -1240,8 +1317,11 @@ const SettlementFeature = defineFeature({
|
|
|
1240
1317
|
another feature's CRUD repository too (see [Layer
|
|
1241
1318
|
1](#layer-1-the-table-resource)). Never unhide it for the job.
|
|
1242
1319
|
- A request uses its own context. The exceptions are a console report
|
|
1243
|
-
behind a console permission, with bounded output,
|
|
1244
|
-
row it has proved it reaches ([Layer 1](#layer-1-the-table-resource))
|
|
1320
|
+
behind a console permission, with bounded output, the write of a shared
|
|
1321
|
+
row it has proved it reaches ([Layer 1](#layer-1-the-table-resource)), and
|
|
1322
|
+
an owner API that answers its own rows as stored to another owner's row
|
|
1323
|
+
policy, narrowed to the call's workspace ([Layer
|
|
1324
|
+
1](#layer-1-the-table-resource)).
|
|
1245
1325
|
- `jskit check` lists every system scope and every `systemContext` call with
|
|
1246
1326
|
its reason, read from the string literal at the call: a reason kept in a
|
|
1247
1327
|
constant reads as none.
|
|
@@ -1417,7 +1497,8 @@ without it.
|
|
|
1417
1497
|
|
|
1418
1498
|
A capability cycle is a ring of requires: feature A requires a capability that
|
|
1419
1499
|
feature B provides while B, directly or through others, requires one that A
|
|
1420
|
-
provides. An `optional` require closes a ring as a required one does
|
|
1500
|
+
provides. An `optional` require closes a ring as a required one does; a
|
|
1501
|
+
`late` one does not ([below](#late-requirements)). The
|
|
1421
1502
|
kernel sets features up in the order their requires give, so it cannot start a
|
|
1422
1503
|
ring: boot fails before any setup, naming it,
|
|
1423
1504
|
`Provider capability cycle detected: children -> parents -> children.`
|
|
@@ -1441,10 +1522,74 @@ Keep every require pointing one way:
|
|
|
1441
1522
|
definitions, move those table resources into a package of their own that
|
|
1442
1523
|
holds only shared definitions and depends on neither.
|
|
1443
1524
|
- Never break a ring with a value handed over later (a setter, a capability
|
|
1444
|
-
looked up at call time): a call's destination then depends on what
|
|
1445
|
-
before. A setter kept until the split carries typed features' `cycle:`
|
|
1525
|
+
looked up by name at call time): a call's destination then depends on what
|
|
1526
|
+
ran before. A setter kept until the split carries typed features' `cycle:`
|
|
1446
1527
|
exception ([Optional tokens](typed-features.md#optional-tokens)).
|
|
1447
1528
|
|
|
1529
|
+
### Late requirements
|
|
1530
|
+
|
|
1531
|
+
A ring that only a read at call time closes, most often a row policy's, and
|
|
1532
|
+
that you cannot or do not want to split, is broken with a late requirement:
|
|
1533
|
+
the kernel's declared alternative to a setter. An audit history whose row
|
|
1534
|
+
policy narrows through the evidence files' owner, while the evidence owner
|
|
1535
|
+
records each change in the audit history, is one: the evidence feature
|
|
1536
|
+
requires `audit.history` as usual, and the audit feature declares
|
|
1537
|
+
`late: { evidence: "evidence.files" }`.
|
|
1538
|
+
|
|
1539
|
+
- A late requirement takes no part in the order features start in, nor in the
|
|
1540
|
+
cycle check, so the ring starts. The kernel resolves it once, after every
|
|
1541
|
+
feature's `boot()`: its destination is declared, so it never depends on what
|
|
1542
|
+
ran before.
|
|
1543
|
+
- It is read at call time only: in a row policy (`requires.evidence`), a
|
|
1544
|
+
request handler, or a method setup builds that runs later, which keeps the
|
|
1545
|
+
capabilities object and reads the name when it runs. A read before every
|
|
1546
|
+
feature has booted (in setup or boot, or a late name destructured in setup's
|
|
1547
|
+
parameters) throws `Provider "audit" read its late requirement "evidence"
|
|
1548
|
+
(capability "evidence.files") before every provider booted: ...`, which
|
|
1549
|
+
says where it may be read. A shutdown reads it only after a start that
|
|
1550
|
+
finished.
|
|
1551
|
+
- It is required: when no feature or runtime input provides it, start fails at
|
|
1552
|
+
the end of boot, `Provider "audit" late-requires missing capability
|
|
1553
|
+
"evidence.files": no provider or runtime input provides it.`, and stops what
|
|
1554
|
+
started, as any startup failure does. The package manifest lists it under
|
|
1555
|
+
`requires`.
|
|
1556
|
+
- A feature never late-requires a capability it provides, nor one it already
|
|
1557
|
+
requires or takes as optional.
|
|
1558
|
+
- The one-way rules above still come first: split the ring when you can. A
|
|
1559
|
+
ring that both features' setup or boot needs cannot be broken this way,
|
|
1560
|
+
since a late requirement is never read there.
|
|
1561
|
+
|
|
1562
|
+
```js
|
|
1563
|
+
// good: the audit history's row policy reads the evidence owner's join source at call time
|
|
1564
|
+
const AuditFeature = defineFeature({
|
|
1565
|
+
id: "audit",
|
|
1566
|
+
owns: [{ resource: auditEntryResource, rowPolicy: auditEntriesPolicy }],
|
|
1567
|
+
late: {
|
|
1568
|
+
evidence: "evidence.files"
|
|
1569
|
+
},
|
|
1570
|
+
provides: {
|
|
1571
|
+
history: "audit.history"
|
|
1572
|
+
},
|
|
1573
|
+
setup({ resources }) {
|
|
1574
|
+
return { history: createAuditHistory({ entries: resources.auditEntries }) };
|
|
1575
|
+
}
|
|
1576
|
+
});
|
|
1577
|
+
|
|
1578
|
+
async function auditEntriesPolicy({ query, caller, column, options, requires }) {
|
|
1579
|
+
if (caller.kind !== "user") {
|
|
1580
|
+
return caller.kind !== "anonymous";
|
|
1581
|
+
}
|
|
1582
|
+
const file = await requires.evidence.joinSource({ alias: "ef" }, options);
|
|
1583
|
+
query.whereExists(file.query.select(1).whereColumn(file.column("id"), column("evidenceFileId")));
|
|
1584
|
+
return true;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// bad: the late name destructured in setup, before every feature has booted; boot fails
|
|
1588
|
+
setup({ resources, evidence }) {
|
|
1589
|
+
return { history: createAuditHistory({ entries: resources.auditEntries, evidence }) };
|
|
1590
|
+
}
|
|
1591
|
+
```
|
|
1592
|
+
|
|
1448
1593
|
## Check and judge
|
|
1449
1594
|
|
|
1450
1595
|
Before calling data work done, apply the
|
|
@@ -1601,6 +1746,16 @@ server code is server code. Neither `eslint-disable`, an inline
|
|
|
1601
1746
|
|
|
1602
1747
|
### Exceptions
|
|
1603
1748
|
|
|
1749
|
+
A data-access rule that refuses a statement points at a missing API, never at a
|
|
1750
|
+
statement to excuse: no rule takes a per-statement exception. When no owner
|
|
1751
|
+
API does what the work needs (locks in a given order, one row by a unique key,
|
|
1752
|
+
a check the row policy cannot write), ask for one: from the feature that owns
|
|
1753
|
+
the table, or from JSKIT for its own packages and for the handle itself. Only
|
|
1754
|
+
statements that are data access themselves go under an exception, in a file
|
|
1755
|
+
of their own declared as infrastructure (below), kept small and holding only
|
|
1756
|
+
those statements, so the exception hides nothing else: a repository, a row
|
|
1757
|
+
policy or a report never moves into such a file to pass lint.
|
|
1758
|
+
|
|
1604
1759
|
A module whose job is data access itself (a database runtime, a migration
|
|
1605
1760
|
runner, test-database setup, an operator's data import or cutover tool, a
|
|
1606
1761
|
database console that runs the person's own SQL) may opt out of
|
|
@@ -44,9 +44,9 @@ How to use it:
|
|
|
44
44
|
- [table-resource-fields.md](./table-resource-fields.md)
|
|
45
45
|
- data access, database table, knex, raw, SQL, repository, bulk, batch, many rows, set write, upsert, lock, claim, totals, report, aggregate, newest per group, transaction, `trx`, background job, system scope, `systemContext`, owner, owns, owner API, another feature's table, scope test, `expectFlatQueries`, `requireTestDatabase`, `jskit/no-direct-knex`, `jskit/no-transaction-reader`, `jskit/no-hand-scope`, `jskit/sql-literal`, `jskit/knex-reason`, `infrastructure:`
|
|
46
46
|
- [data-access.md](./data-access.md)
|
|
47
|
-
- row policy, permission filtering, visibility before pagination, recursive CTE, descendants, package cycle, `RowPolicyPlugin`, row policy cost, slow writes through a policy, access check per history item
|
|
47
|
+
- row policy, permission filtering, visibility before pagination, recursive CTE, descendants, package cycle, capability cycle a row policy closes, `late`, `RowPolicyPlugin`, row policy cost, slow writes through a policy, access check per history item
|
|
48
48
|
- [row-policies.md](./row-policies.md)
|
|
49
|
-
- typed features, server feature, provider, service, repository, collaborator, `typeof`, `= null`, `setProvider`, `register`, `input || {}`, `payload = {}`, `async execute`, `Object.freeze`, `requires`, `optional`, `types.js`, `RuntimeKnex`, `silentLogger`, `create<Name>Actions`, `ActionSpecifications`, request context, `handle.query`, `queryAll`, every row, list stops at one page, `jskit/*` lint findings, `readable-check: allow`, `optional operation:`, `process.env`, `AppError` code, `Object.assign(new Error`, `idempotency`, `…ForTests` export, file or function size, read per row, N+1 queries, slow endpoint, query budget, realistic row counts, slow tests, raised timeout, `migrate.latest()` in tests, test database snapshot, `--test-concurrency=1`, `node --test`, `jskit test`, `testConcurrency()`, `V64_TEST_CONCURRENCY`, Playwright `workers`, Vitest `maxWorkers`, tests one file at a time, test files colliding in parallel, `jskit-test: alone`, `test/*` findings of `jskit check`
|
|
49
|
+
- typed features, server feature, provider, service, repository, collaborator, `typeof`, `= null`, `setProvider`, `register`, `input || {}`, `payload = {}`, `async execute`, `Object.freeze`, `requires`, `optional`, `late`, `Provider capability cycle detected`, `types.js`, `RuntimeKnex`, `silentLogger`, `create<Name>Actions`, `ActionSpecifications`, request context, `handle.query`, `queryAll`, every row, list stops at one page, `jskit/*` lint findings, `readable-check: allow`, `optional operation:`, `process.env`, `AppError` code, `Object.assign(new Error`, `idempotency`, `…ForTests` export, file or function size, read per row, N+1 queries, slow endpoint, query budget, realistic row counts, slow tests, raised timeout, `migrate.latest()` in tests, test database snapshot, `--test-concurrency=1`, `node --test`, `jskit test`, `testConcurrency()`, `V64_TEST_CONCURRENCY`, Playwright `workers`, Vitest `maxWorkers`, tests one file at a time, test files colliding in parallel, `jskit-test: alone`, `test/*` findings of `jskit check`
|
|
50
50
|
- [typed-features.md](./typed-features.md)
|
|
51
51
|
- client features, composable, `use<Name>`, Vue component, client provider, props, emits, `inject`, `provide`, `ref`, `reactive`, `watch`, `addEventListener`, `setInterval`, module state, `Object.freeze` on a composable, `?.()` in a template, `jskit/typed-inject`, `jskit/collaborator-props`, `jskit/fixed-result-shape`, `jskit/released-listeners`, `jskit/no-module-state`, `jskit/no-frozen-vue-state`, `clientFeaturesConfig`, `shared resource:`
|
|
52
52
|
- [client-features.md](./client-features.md)
|
|
@@ -15,6 +15,11 @@ Rules:
|
|
|
15
15
|
- A `useCommand()` with `writeMethod: "DELETE"` sends its parsed input as the
|
|
16
16
|
request body when it declares `input` or `buildRawPayload`, and no body when
|
|
17
17
|
it declares neither; a route that validates a DELETE body needs one of them.
|
|
18
|
+
- A `useCommand()` whose `runPermissions` the person lacks has `canRun` false,
|
|
19
|
+
and its `run()` sends nothing: it shows the notice a server 403 shows
|
|
20
|
+
(`ACTION_PERMISSION_DENIED`, "Forbidden.") through the command's feedback and
|
|
21
|
+
resolves `null`. Hide or disable the control from `canRun` so that notice
|
|
22
|
+
stays the exception.
|
|
18
23
|
- Prefer form runtimes such as `useCrudAddEdit()` or `useAddEdit()` for real forms.
|
|
19
24
|
- Prefer `useCrudList()` and `useCrudView()` for routed CRUD loading and URL resolution.
|
|
20
25
|
- For ordinary routed CRUD record deletion, start from the package-owned CRUD
|
|
@@ -38,6 +38,8 @@ Package composition:
|
|
|
38
38
|
- a package that narrows visibility further depends on the resource owner and calls `resources.contributeRowPolicy(name, policy)` on the handles its own `owns` gave it; a contribution is ANDed with the owner's policy inside its own group, so it can only narrow
|
|
39
39
|
- a contribution never grants visibility: wider visibility (shared rows, grants another package records) is a rule in the owner's own policy over its own tables, and a contribution narrows every read of the table, every feature's included, so a rule for one surface is an owner API method instead
|
|
40
40
|
- the resource owner does not import contributing packages
|
|
41
|
+
- a policy that narrows through another owner's join source, when that owner requires the policy's own feature, declares the owner's capability `late` and reads `requires.<name>` at call time: the kernel resolves it once every feature has booted ([Late requirements](../data-access.md#late-requirements))
|
|
42
|
+
- a policy whose rule reads another owner's rows as stored, whether or not the reader may see them, reads them through that owner's API, which answers a join source under its own `systemScope` narrowed to the call's workspace; never through a context the policy builds
|
|
41
43
|
- do not use module-global mutable registries
|
|
42
44
|
|
|
43
45
|
Example, "your rooms or shared rooms":
|
|
@@ -68,6 +70,7 @@ Cost:
|
|
|
68
70
|
- never load the subject's whole history (every source, notice or grant they were ever linked to) to build an `IN` list, and never call another owner's access check per item of it; another package's restriction is a predicate contribution, and another package's grant is a predicate in the owner's policy over facts the owner keeps
|
|
69
71
|
- the policy runs on every single-record read, including the read-back after a handle's `create()` and `patch()` (`returning: "record"`, their default) and the lookup before `patch` and `delete`, so a write pays it once per row it writes; the many-row writes check access once per statement
|
|
70
72
|
- a write decides access once, inside its transaction; a batch write that would pay an expensive read-back per row follows the data access guide's [Layer 3](../data-access.md#layer-3-many-rows-at-once)
|
|
73
|
+
- a hierarchy (descendants, ancestors) is read through a closure table the tree's owner keeps, with one `whereExists` correlated with the row: no builder a policy holds takes a recursive CTE, and MariaDB compiles none that starts at the row being read
|
|
71
74
|
|
|
72
75
|
Child-resource rules:
|
|
73
76
|
|
|
@@ -243,7 +243,7 @@ owns: [{ resource: contactResource, rowPolicy: ownContactsOrShared }]
|
|
|
243
243
|
- Put visibility in the owner's row policy, never in a search key or route query validation.
|
|
244
244
|
- Do not expose a query key publicly just because the service maps to it internally.
|
|
245
245
|
- Do not rely on route validators alone; a public key still needs a matching backend search definition.
|
|
246
|
-
- A CRUD list refuses a query key its route does not declare with a 400 (`crud.query.undeclaredKeys`), so an undeclared filter fails loudly instead of answering every row.
|
|
246
|
+
- A CRUD list refuses a query key its route does not declare with a 400 (`crud.query.undeclaredKeys`), so an undeclared filter fails loudly instead of answering every row. The screen shows a plain sentence and no Retry; read the server log's warning (or the error's `details`) for the keys refused and the keys the list takes.
|
|
247
247
|
- Never narrow the rows a read answered in code, and never search a list's loaded page in the browser: the filter goes in the read, and a picker or Search box sends `q` ([Narrow in the query](../data-access.md#narrow-in-the-query); `jskit/narrow-in-query`, `jskit/search-on-server`, and `jskit check`'s `data/search-q` for a lookup or list screen whose resource has no `searchSchema.q`).
|
|
248
248
|
|
|
249
249
|
## Quick Rule Of Thumb
|
|
@@ -29,6 +29,8 @@ ends with the same link.
|
|
|
29
29
|
- [Environment from the caller](../typed-features.md#environment-from-the-caller)
|
|
30
30
|
- `setProvider`, `attach*`, any `set<Name>()` that fills a slot, `X | null` below the hook, `deferred until boot: <reason>` (`jskit/no-slot-setter`)
|
|
31
31
|
- [Optional tokens](../typed-features.md#optional-tokens)
|
|
32
|
+
- `Provider capability cycle detected` that only a row policy or another call-time read closes, `late:`, `read its late requirement ... before every provider booted`, `late-requires missing capability`
|
|
33
|
+
- [Late requirements](../typed-features.md#late-requirements)
|
|
32
34
|
- a module-level `register<Name>()`, `let x` or a `WeakMap` filled in `boot()` (`jskit/no-module-registry`)
|
|
33
35
|
- [Owned state](../typed-features.md#owned-state)
|
|
34
36
|
- `shutdown()` with `?.()` or `?? []`
|
|
@@ -229,16 +229,22 @@ capability from one of the application's providers. Without one, invitations
|
|
|
229
229
|
are still created and delivery reports `mailer_unconfigured`. After **Send
|
|
230
230
|
invite**, the Members panel's notice follows the delivery status: `sent` says
|
|
231
231
|
the invite was sent; `simulated` (a test copy, whose `SIDE_EFFECTS` is not
|
|
232
|
-
`live`) and `mailer_unconfigured` say no email was sent; `
|
|
233
|
-
|
|
234
|
-
the
|
|
235
|
-
|
|
232
|
+
`live`) and `mailer_unconfigured` say no email was sent; `held` says email
|
|
233
|
+
isn't set up yet, so the invite will be sent once it is; `failed` is a warning
|
|
234
|
+
that the email failed. Each of those four points to the invite link, which
|
|
235
|
+
the panel shows under the form with its **Copy** button. For a status the
|
|
236
|
+
panel does not know, it shows the delivery result's own `message` (in the
|
|
237
|
+
person's language when its `messageCode` has a translation), and without one
|
|
238
|
+
says only that the invite was created. The mailer, typed
|
|
236
239
|
`WorkspaceInviteMailer` in `@jskit-ai/workspaces-core/server/types`, is an
|
|
237
240
|
object whose `sendWorkspaceInvite(message, options)` receives `{ inviteId,
|
|
238
241
|
email, inviteUrl, workspace, inviter, roleSid, expiresAt, locale, message }`,
|
|
239
|
-
where the inner `message` is the rendered `{ subject, text, html }
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
where the inner `message` is the rendered `{ subject, text, html }`, and
|
|
243
|
+
answers `{ status, message, messageCode, messageParams, providerMessageId }`
|
|
244
|
+
(every field optional; the status defaults to `sent`). A mailer that holds
|
|
245
|
+
email until the application's email is set up, and sends it then, answers
|
|
246
|
+
`status: "held"`. `inviteId` is the saved invitation's id and `workspace.id`
|
|
247
|
+
its workspace's, so such a mailer can record which invitation each email
|
|
242
248
|
belongs to without reading `workspace_invites`:
|
|
243
249
|
|
|
244
250
|
```js
|
|
@@ -340,6 +346,13 @@ before removing or renaming a reported grant, search the code for it
|
|
|
340
346
|
such as `crud.${resource}.list`). If the application checks it, list it in
|
|
341
347
|
`customPermissions`; remove the grant only when nothing uses it.
|
|
342
348
|
|
|
349
|
+
In the browser, a command names the permission it needs as
|
|
350
|
+
`useCommand({ runPermissions })`. While the person lacks it, the command's
|
|
351
|
+
`canRun` is false and `run()` sends nothing: it shows the notice the server's
|
|
352
|
+
refusal shows (a 403 `ACTION_PERMISSION_DENIED`, "Forbidden.") through the
|
|
353
|
+
command's feedback, and resolves `null`. Hide or disable the control from
|
|
354
|
+
`canRun`, so the notice is the exception.
|
|
355
|
+
|
|
343
356
|
## Role display labels
|
|
344
357
|
|
|
345
358
|
Set optional `label` strings in the existing `roleCatalog.roles` definitions,
|
|
@@ -591,6 +604,10 @@ The route slug, selected workspace, query keys, and server scope stay aligned.
|
|
|
591
604
|
Invalid workspace URLs show a deliberate not-found/forbidden state instead of
|
|
592
605
|
silently selecting another workspace. The browser waits for the server's answer
|
|
593
606
|
about an unknown slug before deciding, so the surface can show that state.
|
|
607
|
+
The bootstrap answer, which carries the workspace and the person's permissions
|
|
608
|
+
in it, belongs to the workspace, not to a page: it still applies when the
|
|
609
|
+
person has moved to another page of the same workspace before it arrives, and a
|
|
610
|
+
move to another workspace asks again.
|
|
594
611
|
|
|
595
612
|
### Surfaces and where `/` lands
|
|
596
613
|
|