@jskit-ai/agent-docs 0.1.319 → 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/framework/data-access.md +165 -13
- 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/kernel.md +7 -4
- package/reference/autogen/packages/resource-runtime.md +6 -1
- package/skills/jskit/references/data-access.md +165 -13
- package/skills/jskit/references/heuristics/INDEX.md +2 -2
- package/skills/jskit/references/heuristics/row-policies.md +3 -0
- package/skills/jskit/references/heuristics/typed-features.md +2 -0
- 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
|
@@ -247,14 +247,19 @@ execute(input, context) {
|
|
|
247
247
|
under `@jskit-ai/auth-web/client/views/` so that only a page that shows one
|
|
248
248
|
loads it (the settings' QR code library included). `SecondFactorSettings`
|
|
249
249
|
sets an authenticator up (a QR code and the key as text, shown once, then the
|
|
250
|
-
app's first code), shows the recovery codes once
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
app's first code), shows the recovery codes once (to copy, or to download as
|
|
251
|
+
`recovery-codes.txt`), replaces them, and removes the authenticator, each with
|
|
252
|
+
a code or a recovery code; an app places it as an account settings section,
|
|
253
|
+
whose title names it ("Authenticator app"). It emits `codes-saved` when the
|
|
254
|
+
person says they saved a new set of codes, so a page that needs an
|
|
255
|
+
authenticator before it goes on, such as a console's way in, goes on then.
|
|
253
256
|
`SecondFactorPrompt` proves the session's second factor on a page of the app's.
|
|
254
257
|
For a route that asks for a recent code, `useSecondFactorStepUp()` runs the
|
|
255
258
|
request, and when it is refused with `auth.secondFactor.required` opens
|
|
256
259
|
`SecondFactorDialog` and runs it again after the code; cancelling throws the
|
|
257
|
-
refusal to the caller
|
|
260
|
+
refusal to the caller. The dialog gives focus back to the element that had it
|
|
261
|
+
when it opened (the control that sent the request), after the code as after a
|
|
262
|
+
cancel:
|
|
258
263
|
|
|
259
264
|
```vue
|
|
260
265
|
<script setup>
|
|
@@ -435,10 +435,13 @@ request, `{ kind: "anonymous" }` for one by no one, and `{ kind: "system" }` or
|
|
|
435
435
|
`reason`, for background work. A job names a user only as `actorId`, the
|
|
436
436
|
person it works for ([below](#background-work)), so never read a missing actor
|
|
437
437
|
as an anonymous request. The owner's policy also receives the capabilities its
|
|
438
|
-
feature requires (and its optional ones), by local name, as
|
|
439
|
-
same ones its setup receives: a policy that needs another
|
|
440
|
-
declares that feature's capability in `requires` and reads
|
|
441
|
-
|
|
438
|
+
feature requires (and its optional and late ones), by local name, as
|
|
439
|
+
`requires`, the same ones its setup receives: a policy that needs another
|
|
440
|
+
feature's answer declares that feature's capability in `requires` and reads
|
|
441
|
+
`requires.<name>`. When that feature requires the policy's own feature, the
|
|
442
|
+
two form a ring; the policy's feature declares the capability `late` instead
|
|
443
|
+
([Capability cycles](#capability-cycles)). A policy runs on every read, so
|
|
444
|
+
what it asks there must be cheap.
|
|
442
445
|
|
|
443
446
|
```js
|
|
444
447
|
// good: one predicate on the row being read
|
|
@@ -473,7 +476,12 @@ subquery to the row with `whereExists`: over `ownTable(name)`, which may join
|
|
|
473
476
|
the owner's other tables, or over another owner's join source. A policy is told
|
|
474
477
|
the call's `options`, `{ context, trx }` as the caller passed them, and passes
|
|
475
478
|
them on unchanged to `joinSource({ alias }, options)`, so the join source reads
|
|
476
|
-
in the caller's scope and transaction; never build them by hand.
|
|
479
|
+
in the caller's scope and transaction; never build them by hand. `options.trx`
|
|
480
|
+
names the transaction the read runs in: the caller's, or, for a write whose
|
|
481
|
+
caller named none, the one json-rest-api opens for it, which the lookup before
|
|
482
|
+
a patch and the read-back after a create run in. So an owner API the policy
|
|
483
|
+
calls with its `options` (a join source, or a handle read such as a role check)
|
|
484
|
+
joins that transaction and never waits for a second connection.
|
|
477
485
|
|
|
478
486
|
```js
|
|
479
487
|
// good: a member of the document's team sees it, through the teams owner's join source
|
|
@@ -495,6 +503,45 @@ function teamDocumentsPolicy({ query, caller, column }) {
|
|
|
495
503
|
}
|
|
496
504
|
```
|
|
497
505
|
|
|
506
|
+
A policy whose rule reads another owner's rows as stored (a document is
|
|
507
|
+
visible while its folder is open, whether or not the reader may see the folder
|
|
508
|
+
itself) reads them through that owner's API, never through a context it builds.
|
|
509
|
+
The owner answers a join source of its rows under its own `systemScope`,
|
|
510
|
+
narrowed to the call's workspace, so the rows stay that workspace's and `jskit
|
|
511
|
+
check` lists the reason. The policy passes its `options` on unchanged, as
|
|
512
|
+
always, and returns early for background work, whose own context already
|
|
513
|
+
decides. It still only narrows: the stored rows feed its predicate and are
|
|
514
|
+
never answered, so the reader sees no folder it could not see before.
|
|
515
|
+
|
|
516
|
+
```js
|
|
517
|
+
// good: the folders' owner API, in the folders feature, whose setup receives systemContext
|
|
518
|
+
function storedSource({ alias }, options) {
|
|
519
|
+
const context = systemContext("the documents' row policy reads each folder's status as stored")
|
|
520
|
+
.forWorkspace(resolveWorkspaceScopeValue(options.context));
|
|
521
|
+
return folders.joinSource({ alias }, { ...passedOn(options), context });
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// good: the documents' policy, which requires the folders' owner API
|
|
525
|
+
async function openFolderDocuments({ query, caller, column, options, requires }) {
|
|
526
|
+
if (caller.kind !== "user") {
|
|
527
|
+
return caller.kind !== "anonymous";
|
|
528
|
+
}
|
|
529
|
+
const folder = await requires.folders.storedSource({ alias: "f" }, options);
|
|
530
|
+
query.whereExists(folder.query.select(1).whereColumn(folder.column("id"), column("folderId")).where(folder.column("status"), "open"));
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
A policy never walks a tree with a recursive query (`withRecursive`). No builder
|
|
536
|
+
it holds takes a common table expression, and a walk that starts at the row
|
|
537
|
+
being read does not compile on MariaDB, which lets no outer column into a
|
|
538
|
+
recursive query's first member; a walk that starts elsewhere (the reader's
|
|
539
|
+
grants, walking down) reads the reader's whole subtree on every read. Keep the
|
|
540
|
+
tree's ancestry stored instead: its owner writes a closure table (each node's
|
|
541
|
+
ancestors, one row each, with their depth) in the same transaction that adds
|
|
542
|
+
or moves a node, and the policy ties one `whereExists` over that table's join
|
|
543
|
+
source to the row, on indexed columns, on every database.
|
|
544
|
+
|
|
498
545
|
A rule that depends on the caller's role reads `context.permissions` with
|
|
499
546
|
`hasPermission(context.permissions, "bookings.view-all")` from
|
|
500
547
|
`@jskit-ai/kernel/shared/support`, never with `includes()`. A role may hold
|
|
@@ -727,6 +774,21 @@ or a counter row taken with `lock(id)`. Every lock needs a transaction; SQLite
|
|
|
727
774
|
runs one transaction at a time, so there is no row lock to take. Take locks in
|
|
728
775
|
one order on every path, a parent before its children.
|
|
729
776
|
|
|
777
|
+
`lockWhere` takes that order from `sort` too: `lockWhere({ batchId }, {
|
|
778
|
+
...txOptions, sort: ["moduleKey"] })` locks the rows in `sort` order
|
|
779
|
+
(fields, `"-moduleKey"` for descending), then by id, and answers them in it,
|
|
780
|
+
so two paths that lock overlapping rows wait for each other instead of
|
|
781
|
+
deadlocking. `limit` locks only the first rows of that order, by id without a
|
|
782
|
+
`sort`: a check whether any row matches, or the lock of one row by a unique key
|
|
783
|
+
other than its id, takes `limit: 1`, one statement as `lock(id)` is
|
|
784
|
+
(`workspaces.memberships.lockByWorkspaceIdAndUserId` locks its membership so).
|
|
785
|
+
Without either, `lockWhere` locks every match in id order (on MySQL and MariaDB
|
|
786
|
+
in the order of the index it reads, below), at most 1,000 (more throw), and
|
|
787
|
+
PostgreSQL reads them once more under its locks, for a row that started to
|
|
788
|
+
match while it waited; with a `limit` it stops once it holds that many. A
|
|
789
|
+
`limit` outside 1 to 1,000, or a `sort` on no stored field, is refused before
|
|
790
|
+
any statement.
|
|
791
|
+
|
|
730
792
|
A lock answers the rows it locks, with the fields `fields` names. Its
|
|
731
793
|
`include` names belongs-to relationships (`include: ["customer"]`, or
|
|
732
794
|
`"batch.yard"` a level further): after its own rows, the lock locks the
|
|
@@ -772,7 +834,12 @@ from a request: every id listed is locked, a hidden one too, before it is left
|
|
|
772
834
|
out. And `lockWhere` needs an index that starts with the ownership columns (on
|
|
773
835
|
a table with no owners, with a column the filters compare); without one it
|
|
774
836
|
refuses with `RestApiBulkWriteUnsupportedError` naming the index to add in a
|
|
775
|
-
migration.
|
|
837
|
+
migration. With `sort` or `limit` the index must also read the rows in the
|
|
838
|
+
lock's order, since the database locks them in the order it reads them: after
|
|
839
|
+
the ownership columns and the columns the filters fix to one value, it holds
|
|
840
|
+
the sort's columns, ascending, and then nothing but the id, and the sort's
|
|
841
|
+
fields go one way (all ascending or all descending). A unique key the filters
|
|
842
|
+
fix whole, as a membership's workspace and user are, needs nothing more.
|
|
776
843
|
|
|
777
844
|
A worker taking the next job uses `claim({ filters, sort, take }, txOptions)`,
|
|
778
845
|
which skips rows another worker holds. A record that serializes work on a key
|
|
@@ -827,8 +894,15 @@ await memberships.patch(input.membershipId, { lastFiledAt: new Date() }, txOptio
|
|
|
827
894
|
```
|
|
828
895
|
|
|
829
896
|
Locks stay on the owner's handle and its owner API. A `scopedQuery()` or
|
|
830
|
-
`joinSource()` builder takes no lock,
|
|
831
|
-
|
|
897
|
+
`joinSource()` builder takes no lock, not even a shared one: PostgreSQL's `FOR
|
|
898
|
+
SHARE OF` an alias would lock only that source's rows, but MariaDB has no `FOR
|
|
899
|
+
SHARE OF` at all, and its `LOCK IN SHARE MODE` covers every row the statement
|
|
900
|
+
examines, in every table. A report that needs another
|
|
901
|
+
owner's rows unchanged until it commits first locks them through that owner's
|
|
902
|
+
handle or owner API with `lockMode: "share"` (by a unique key with `limit:
|
|
903
|
+
1`), then reads its join. A row policy is not told a read's lock mode, and
|
|
904
|
+
never takes a lock: it says which rows a caller may see, the same for every
|
|
905
|
+
read, and the lock call it narrows takes its own mode. Rows
|
|
832
906
|
of several owners are never locked in one statement over a join, which on
|
|
833
907
|
MySQL and MariaDB locks every joined row the read examines: lock each owner's
|
|
834
908
|
rows with its own `lock`, `lockMany` or `lockWhere`, the owners in one fixed
|
|
@@ -1248,8 +1322,11 @@ const SettlementFeature = defineFeature({
|
|
|
1248
1322
|
another feature's CRUD repository too (see [Layer
|
|
1249
1323
|
1](#layer-1-the-table-resource)). Never unhide it for the job.
|
|
1250
1324
|
- A request uses its own context. The exceptions are a console report
|
|
1251
|
-
behind a console permission, with bounded output,
|
|
1252
|
-
row it has proved it reaches ([Layer 1](#layer-1-the-table-resource))
|
|
1325
|
+
behind a console permission, with bounded output, the write of a shared
|
|
1326
|
+
row it has proved it reaches ([Layer 1](#layer-1-the-table-resource)), and
|
|
1327
|
+
an owner API that answers its own rows as stored to another owner's row
|
|
1328
|
+
policy, narrowed to the call's workspace ([Layer
|
|
1329
|
+
1](#layer-1-the-table-resource)).
|
|
1253
1330
|
- `jskit check` lists every system scope and every `systemContext` call with
|
|
1254
1331
|
its reason, read from the string literal at the call: a reason kept in a
|
|
1255
1332
|
constant reads as none.
|
|
@@ -1425,7 +1502,8 @@ without it.
|
|
|
1425
1502
|
|
|
1426
1503
|
A capability cycle is a ring of requires: feature A requires a capability that
|
|
1427
1504
|
feature B provides while B, directly or through others, requires one that A
|
|
1428
|
-
provides. An `optional` require closes a ring as a required one does
|
|
1505
|
+
provides. An `optional` require closes a ring as a required one does; a
|
|
1506
|
+
`late` one does not ([below](#late-requirements)). The
|
|
1429
1507
|
kernel sets features up in the order their requires give, so it cannot start a
|
|
1430
1508
|
ring: boot fails before any setup, naming it,
|
|
1431
1509
|
`Provider capability cycle detected: children -> parents -> children.`
|
|
@@ -1449,10 +1527,74 @@ Keep every require pointing one way:
|
|
|
1449
1527
|
definitions, move those table resources into a package of their own that
|
|
1450
1528
|
holds only shared definitions and depends on neither.
|
|
1451
1529
|
- Never break a ring with a value handed over later (a setter, a capability
|
|
1452
|
-
looked up at call time): a call's destination then depends on what
|
|
1453
|
-
before. A setter kept until the split carries typed features' `cycle:`
|
|
1530
|
+
looked up by name at call time): a call's destination then depends on what
|
|
1531
|
+
ran before. A setter kept until the split carries typed features' `cycle:`
|
|
1454
1532
|
exception ([Optional tokens](/guide/framework/typed-features#optional-tokens)).
|
|
1455
1533
|
|
|
1534
|
+
### Late requirements
|
|
1535
|
+
|
|
1536
|
+
A ring that only a read at call time closes, most often a row policy's, and
|
|
1537
|
+
that you cannot or do not want to split, is broken with a late requirement:
|
|
1538
|
+
the kernel's declared alternative to a setter. An audit history whose row
|
|
1539
|
+
policy narrows through the evidence files' owner, while the evidence owner
|
|
1540
|
+
records each change in the audit history, is one: the evidence feature
|
|
1541
|
+
requires `audit.history` as usual, and the audit feature declares
|
|
1542
|
+
`late: { evidence: "evidence.files" }`.
|
|
1543
|
+
|
|
1544
|
+
- A late requirement takes no part in the order features start in, nor in the
|
|
1545
|
+
cycle check, so the ring starts. The kernel resolves it once, after every
|
|
1546
|
+
feature's `boot()`: its destination is declared, so it never depends on what
|
|
1547
|
+
ran before.
|
|
1548
|
+
- It is read at call time only: in a row policy (`requires.evidence`), a
|
|
1549
|
+
request handler, or a method setup builds that runs later, which keeps the
|
|
1550
|
+
capabilities object and reads the name when it runs. A read before every
|
|
1551
|
+
feature has booted (in setup or boot, or a late name destructured in setup's
|
|
1552
|
+
parameters) throws `Provider "audit" read its late requirement "evidence"
|
|
1553
|
+
(capability "evidence.files") before every provider booted: ...`, which
|
|
1554
|
+
says where it may be read. A shutdown reads it only after a start that
|
|
1555
|
+
finished.
|
|
1556
|
+
- It is required: when no feature or runtime input provides it, start fails at
|
|
1557
|
+
the end of boot, `Provider "audit" late-requires missing capability
|
|
1558
|
+
"evidence.files": no provider or runtime input provides it.`, and stops what
|
|
1559
|
+
started, as any startup failure does. The package manifest lists it under
|
|
1560
|
+
`requires`.
|
|
1561
|
+
- A feature never late-requires a capability it provides, nor one it already
|
|
1562
|
+
requires or takes as optional.
|
|
1563
|
+
- The one-way rules above still come first: split the ring when you can. A
|
|
1564
|
+
ring that both features' setup or boot needs cannot be broken this way,
|
|
1565
|
+
since a late requirement is never read there.
|
|
1566
|
+
|
|
1567
|
+
```js
|
|
1568
|
+
// good: the audit history's row policy reads the evidence owner's join source at call time
|
|
1569
|
+
const AuditFeature = defineFeature({
|
|
1570
|
+
id: "audit",
|
|
1571
|
+
owns: [{ resource: auditEntryResource, rowPolicy: auditEntriesPolicy }],
|
|
1572
|
+
late: {
|
|
1573
|
+
evidence: "evidence.files"
|
|
1574
|
+
},
|
|
1575
|
+
provides: {
|
|
1576
|
+
history: "audit.history"
|
|
1577
|
+
},
|
|
1578
|
+
setup({ resources }) {
|
|
1579
|
+
return { history: createAuditHistory({ entries: resources.auditEntries }) };
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
async function auditEntriesPolicy({ query, caller, column, options, requires }) {
|
|
1584
|
+
if (caller.kind !== "user") {
|
|
1585
|
+
return caller.kind !== "anonymous";
|
|
1586
|
+
}
|
|
1587
|
+
const file = await requires.evidence.joinSource({ alias: "ef" }, options);
|
|
1588
|
+
query.whereExists(file.query.select(1).whereColumn(file.column("id"), column("evidenceFileId")));
|
|
1589
|
+
return true;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// bad: the late name destructured in setup, before every feature has booted; boot fails
|
|
1593
|
+
setup({ resources, evidence }) {
|
|
1594
|
+
return { history: createAuditHistory({ entries: resources.auditEntries, evidence }) };
|
|
1595
|
+
}
|
|
1596
|
+
```
|
|
1597
|
+
|
|
1456
1598
|
## Check and judge
|
|
1457
1599
|
|
|
1458
1600
|
Before calling data work done, apply the
|
|
@@ -1609,6 +1751,16 @@ server code is server code. Neither `eslint-disable`, an inline
|
|
|
1609
1751
|
|
|
1610
1752
|
### Exceptions
|
|
1611
1753
|
|
|
1754
|
+
A data-access rule that refuses a statement points at a missing API, never at a
|
|
1755
|
+
statement to excuse: no rule takes a per-statement exception. When no owner
|
|
1756
|
+
API does what the work needs (locks in a given order, one row by a unique key,
|
|
1757
|
+
a check the row policy cannot write), ask for one: from the feature that owns
|
|
1758
|
+
the table, or from JSKIT for its own packages and for the handle itself. Only
|
|
1759
|
+
statements that are data access themselves go under an exception, in a file
|
|
1760
|
+
of their own declared as infrastructure (below), kept small and holding only
|
|
1761
|
+
those statements, so the exception hides nothing else: a repository, a row
|
|
1762
|
+
policy or a report never moves into such a file to pass lint.
|
|
1763
|
+
|
|
1612
1764
|
A module whose job is data access itself (a database runtime, a migration
|
|
1613
1765
|
runner, test-database setup, an operator's data import or cutover tool, a
|
|
1614
1766
|
database console that runs the person's own SQL) may opt out of
|
|
@@ -29,8 +29,9 @@ rule in [client features](/guide/framework/client-features).
|
|
|
29
29
|
> so each call has exactly one visible destination for a reader and for the
|
|
30
30
|
> code map.
|
|
31
31
|
|
|
32
|
-
- A **capability** is a value a feature `provides`, `requires
|
|
33
|
-
(`optional`)
|
|
32
|
+
- A **capability** is a value a feature `provides`, `requires`, may use
|
|
33
|
+
(`optional`) or requires once every feature has booted (`late`), named by a
|
|
34
|
+
**token** such as `"feature.invoices"`.
|
|
34
35
|
- A **collaborator** is an object or function with behaviour that code calls:
|
|
35
36
|
a service, store, repository, runtime, router, publisher, catalogue, logger
|
|
36
37
|
or clock. Plain data (an input, a record, a list, an options bag) is not one.
|
|
@@ -47,8 +48,8 @@ it reports the call as exact instead of guessing from the method name.
|
|
|
47
48
|
### Feature files
|
|
48
49
|
|
|
49
50
|
**A `defineFeature` lives in `<Name>Feature.js`, its keys in one order, one
|
|
50
|
-
per line: `id, domain, owns, systemScope, requires, optional,
|
|
51
|
-
setup, actions, boot, shutdown`.** A `defineProvider` lives in `<Name>Provider.js`.
|
|
51
|
+
per line: `id, domain, owns, systemScope, requires, optional, late,
|
|
52
|
+
provides, setup, actions, boot, shutdown`.** A `defineProvider` lives in `<Name>Provider.js`.
|
|
52
53
|
|
|
53
54
|
- `setup` builds each provided value with a named `create<Name>` factory from
|
|
54
55
|
a module of its own, never inline. It returns exactly the keys `provides`
|
|
@@ -86,8 +87,8 @@ actions: ({ invoices }) => [{ id: "invoices.list", execute: () => invoices.list(
|
|
|
86
87
|
**A package's manifest, `jskit.capabilities` in its `package.json`, lists
|
|
87
88
|
exactly what its features provide, and every capability they require beyond
|
|
88
89
|
the kernel's own (`runtime.actions`, `runtime.events`, `runtime.http`,
|
|
89
|
-
`runtime.bootstrap`) and those the package provides itself.**
|
|
90
|
-
capabilities are not
|
|
90
|
+
`runtime.bootstrap`) and those the package provides itself.** Late
|
|
91
|
+
capabilities are required; optional ones are not. A requirement no feature has stays only when
|
|
91
92
|
the package needs it at install time, such as the database its migrations
|
|
92
93
|
need.
|
|
93
94
|
|
|
@@ -261,7 +262,8 @@ function createMailer({ env = process.env } = {}) {
|
|
|
261
262
|
- When the slot's supplier requires the slot's owner, the two form a cycle.
|
|
262
263
|
Split the part of the owner the supplier needs into its own feature. Until
|
|
263
264
|
then the setter stays, with a `cycle:` [exception comment](#exceptions), and
|
|
264
|
-
is cleared at shutdown.
|
|
265
|
+
is cleared at shutdown. A value with no default that the owner reads only
|
|
266
|
+
when called is no slot: it is a [late requirement](#late-requirements).
|
|
265
267
|
|
|
266
268
|
Why: a slot filled later makes a call's destination depend on what ran
|
|
267
269
|
before.
|
|
@@ -291,6 +293,46 @@ function setNumbering(next) {
|
|
|
291
293
|
}
|
|
292
294
|
```
|
|
293
295
|
|
|
296
|
+
### Late requirements
|
|
297
|
+
|
|
298
|
+
**A capability that closes a ring and is read only when called, such as by a
|
|
299
|
+
row policy, is `late`: the kernel resolves it once every feature has booted,
|
|
300
|
+
and code reads it from the capabilities object at call time, never in
|
|
301
|
+
`setup()` or `boot()`.**
|
|
302
|
+
|
|
303
|
+
- Split the ring first ([capability cycles](/guide/framework/data-access#capability-cycles)).
|
|
304
|
+
A late requirement is for a ring a call-time read closes, after splitting
|
|
305
|
+
is not possible or not wanted.
|
|
306
|
+
- `late` maps local names to tokens, as `requires` does, with names no other
|
|
307
|
+
map of the feature uses. It never names a token the feature provides,
|
|
308
|
+
requires or takes as optional.
|
|
309
|
+
- It is required: when nothing provides it, start-up fails at the end of
|
|
310
|
+
boot, naming the feature and the token, and the package manifest lists it.
|
|
311
|
+
- A row policy reads it from `requires`
|
|
312
|
+
([data access](/guide/framework/data-access#late-requirements)). A value
|
|
313
|
+
`setup()` builds receives the capabilities object, typed, and reads the
|
|
314
|
+
late name in its methods; `setup()` never destructures it. A read before
|
|
315
|
+
every feature has booted throws, naming the feature, the name and the token.
|
|
316
|
+
|
|
317
|
+
Why: the token is declared and the kernel resolves it once, so a call's
|
|
318
|
+
destination never depends on what ran before, as it does with a setter.
|
|
319
|
+
|
|
320
|
+
```js
|
|
321
|
+
// good: the token declared late; the factory reads it when a report runs
|
|
322
|
+
late: {
|
|
323
|
+
evidence: "evidence.files"
|
|
324
|
+
},
|
|
325
|
+
/** @param {{ resources: { auditEntries: import("@jskit-ai/resource-runtime/server/types").ResourceHandle }, evidence: import("@local/evidence/server/types").EvidenceFiles }} capabilities */
|
|
326
|
+
setup(capabilities) {
|
|
327
|
+
return { reports: createAuditReports({ capabilities }) };
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
// bad: destructured in setup, before every feature has booted; start-up fails
|
|
331
|
+
setup({ resources, evidence }) {
|
|
332
|
+
return { reports: createAuditReports({ entries: resources.auditEntries, evidence }) };
|
|
333
|
+
},
|
|
334
|
+
```
|
|
335
|
+
|
|
294
336
|
### Owned state
|
|
295
337
|
|
|
296
338
|
**A capability owns its state: built in `setup()`, started in `boot()`,
|
|
@@ -1161,7 +1203,7 @@ Why: the limits measure code a person reads; a table is scanned, not read.
|
|
|
1161
1203
|
an object that spans lines, braces once an `if` spans lines.** `eslint --fix`
|
|
1162
1204
|
applies it.
|
|
1163
1205
|
|
|
1164
|
-
- A returned frozen result and a `requires`, `optional` or `provides` map put
|
|
1206
|
+
- A returned frozen result and a `requires`, `optional`, `late` or `provides` map put
|
|
1165
1207
|
each property on its own line. A short leaf literal of at most three scalar
|
|
1166
1208
|
properties (`{ type: "string", required: true }`) may stay on one line.
|
|
1167
1209
|
- Long prose stays inline in its string or template; never split a sentence
|
|
@@ -1304,7 +1346,7 @@ Every finding ends with a link to the section of this page that explains it.
|
|
|
1304
1346
|
| `jskit/no-patched-error` | `Object.assign(new Error(…), { statusCode })`, or an error builder's result given its status afterwards | [One construction per error](#one-construction-per-error) |
|
|
1305
1347
|
| `jskit/no-test-only-export` | an export whose name says only tests use it (`…ForTests`, `__reset…`; `__testables` aside) | [No test-only exports](#no-test-only-exports) |
|
|
1306
1348
|
| `jskit/narrow-in-query` | `.filter()`, `.find()`, `.some()`, `.every()`, `.slice()`, a lone `.length` or a loop that skips with `continue`, over the rows a read in the same function answered and uses no other way | [Narrow in the query](#narrow-in-the-query) |
|
|
1307
|
-
| `jskit/one-property-per-line` | two properties on one line in a returned `Object.freeze({ … })` or a `requires` / `optional` / `provides` map (`eslint --fix` splits them) | [Formatter](#formatter) |
|
|
1349
|
+
| `jskit/one-property-per-line` | two properties on one line in a returned `Object.freeze({ … })` or a `requires` / `optional` / `late` / `provides` map (`eslint --fix` splits them) | [Formatter](#formatter) |
|
|
1308
1350
|
| `jskit/jsdoc-description-inside` | a `//` description directly above a `/** */` block | [Comments](#comments) |
|
|
1309
1351
|
| `jskit/allow-comment-form` | a `readable-check: allow` reason without a prefix from the table below, or one that cites tests or the state of a project | [Exceptions](#exceptions) |
|
|
1310
1352
|
| `max-lines`, `max-lines-per-function` | files over 750 lines, functions over 600 | [Size limits](#size-limits) |
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@local/main": "0.1.0",
|
|
36
36
|
"@fastify/static": "^10.1.3",
|
|
37
|
-
"@jskit-ai/kernel": "0.2.
|
|
37
|
+
"@jskit-ai/kernel": "0.2.23",
|
|
38
38
|
"@jskit-ai/material-web": "0.1.6",
|
|
39
39
|
"@tanstack/vue-query": "^5.101.0",
|
|
40
40
|
"fastify": "^5.12.7",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"vue": "^3.5.44",
|
|
45
45
|
"vue-router": "^5.3.1",
|
|
46
46
|
"vuetify": "^4.3.0",
|
|
47
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
47
|
+
"@jskit-ai/http-runtime": "0.2.23",
|
|
48
48
|
"@fastify/fast-json-stringify-compiler": "^5.1.0",
|
|
49
49
|
"@vue/devtools-api": "^8.2.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@jskit-ai/config-eslint": "0.1.
|
|
53
|
-
"@jskit-ai/jskit-catalog": "0.2.
|
|
52
|
+
"@jskit-ai/config-eslint": "0.1.252",
|
|
53
|
+
"@jskit-ai/jskit-catalog": "0.2.72",
|
|
54
54
|
"@playwright/test": "1.61.1",
|
|
55
55
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
56
56
|
"eslint": "^10.8.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@local/main": "0.1.0",
|
|
36
36
|
"@fastify/static": "^10.1.3",
|
|
37
|
-
"@jskit-ai/kernel": "0.2.
|
|
37
|
+
"@jskit-ai/kernel": "0.2.23",
|
|
38
38
|
"@jskit-ai/material-web": "0.1.6",
|
|
39
39
|
"@tanstack/vue-query": "^5.101.0",
|
|
40
40
|
"fastify": "^5.12.7",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"vue": "^3.5.44",
|
|
45
45
|
"vue-router": "^5.3.1",
|
|
46
46
|
"vuetify": "^4.3.0",
|
|
47
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
48
|
-
"@jskit-ai/shell-web": "0.2.
|
|
47
|
+
"@jskit-ai/http-runtime": "0.2.23",
|
|
48
|
+
"@jskit-ai/shell-web": "0.2.32",
|
|
49
49
|
"@fastify/fast-json-stringify-compiler": "^5.1.0",
|
|
50
50
|
"@vue/devtools-api": "^8.2.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@jskit-ai/config-eslint": "0.1.
|
|
54
|
-
"@jskit-ai/jskit-catalog": "0.2.
|
|
53
|
+
"@jskit-ai/config-eslint": "0.1.252",
|
|
54
|
+
"@jskit-ai/jskit-catalog": "0.2.72",
|
|
55
55
|
"@playwright/test": "1.61.1",
|
|
56
56
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
57
57
|
"eslint": "^10.8.0",
|
|
@@ -385,13 +385,14 @@ Exports
|
|
|
385
385
|
Exports
|
|
386
386
|
- `ARCHITECTURE_ID_PATTERN`
|
|
387
387
|
- `capabilityKey(value)`
|
|
388
|
-
- `defineProvider({ id, requires = {}, optional = {}, provides = {}, hints = {}, setup, boot = null, shutdown = null } = {})`
|
|
388
|
+
- `defineProvider({ id, requires = {}, optional = {}, late = {}, provides = {}, hints = {}, setup, boot = null, shutdown = null } = {})`
|
|
389
389
|
- `normalizeArchitectureId(value, label)`
|
|
390
390
|
- `type ProviderDefinition`
|
|
391
391
|
Local functions
|
|
392
392
|
- `normalizeCapabilityMap(value, label)`
|
|
393
393
|
- `normalizeHints(value, requires, providerId)`
|
|
394
394
|
- `assertDistinctLocalNames(maps)`
|
|
395
|
+
- `assertLateCapabilitiesUnique(providerId, late, others)`
|
|
395
396
|
- `normalizeLifecycleMethod(value, label)`
|
|
396
397
|
|
|
397
398
|
### `capabilities/index.js`
|
|
@@ -409,7 +410,8 @@ Local functions
|
|
|
409
410
|
- `normalizeInputCapabilities(value)`
|
|
410
411
|
- `providerCapabilityIds(provider, field)`
|
|
411
412
|
- `buildProviderOrder(providers, inputCapabilities)`
|
|
412
|
-
- `resolveProviderDependencies(provider, capabilities)`
|
|
413
|
+
- `resolveProviderDependencies(provider, capabilities, late)`
|
|
414
|
+
- `resolveLateDependencies(provider, capabilities)`
|
|
413
415
|
|
|
414
416
|
### i18n
|
|
415
417
|
|