@starci/hfs 4.7.37 → 4.7.39
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/runtime/knowledge/grammars/index.yaml +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +13 -8
- package/runtime/knowledge/hfs/fe-stack.yaml +1 -1
- package/runtime/knowledge/hfs/rules.yaml +2 -1
- package/runtime/knowledge/hfs/slots.yaml +19 -1
- package/runtime/knowledge/patterns/be/queues.yaml +1 -1
- package/runtime/scripts/hfs/declaration-shape.mjs +14 -2
- package/runtime/scripts/hfs/rules/database-queue-outbox.mjs +102 -0
- package/runtime/scripts/hfs/rules/database-queues.mjs +35 -17
- package/scaffold/add-queue-lite.mjs +3 -1
- package/scaffold/app.mjs +6 -5
- package/scaffold/lite-exports.mjs +9 -3
- package/templates/app/skeleton/.starcistacks/production/README.md +2 -2
- package/templates/app/skeleton-lite/.starcistacks/dev/README.md +1 -1
- package/templates/be/skeleton/apps/__app__/src/main.ts +7 -2
- package/templates/be/skeleton/apps/cli/src/compose/platform.ts +1 -1
- package/templates/be/skeleton/src/modules/platform/database/index.ts +1 -1
- package/templates/be/skeleton/src/modules/platform/http/index.ts +1 -5
- package/templates/be/skeleton/src/modules/platform/logging/correlation.service.spec.ts +3 -1
- package/templates/be/skeleton/src/modules/platform/logging/index.ts +2 -13
- package/templates/be/skeleton/src/modules/platform/primitives/record.policy.spec.ts +18 -6
- package/templates/be/skeleton-lite/src/modules/platform/database/index.ts +0 -1
- package/templates/be/skeleton-lite/src/modules/platform/logging/index.ts +2 -13
- package/templates/be/skeleton-lite/src/modules/platform/primitives/index.ts +0 -1
- package/templates/fe/skeleton/apps/__app__/src/components/blocks/SignInForm/component.tsx +1 -1
- package/templates/fe/skeleton/apps/__app__/src/components/blocks/SignOutButton/component.tsx +1 -1
- package/templates/fe/skeleton/apps/__app__/src/features/overlays/AppGuideOverlay/component.tsx +1 -1
- package/templates/fe/skeleton/apps/__app__/src/modules/toast/toast.tsx +5 -5
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingPage/component.tsx +1 -1
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/SiteShell/classNames.ts +2 -2
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/SiteShell/index.tsx +1 -1
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/SiteShell/classNames.ts +2 -2
- package/templates/be/skeleton/src/modules/platform/http/graphql-call.mapper.spec.ts +0 -92
- package/templates/be/skeleton/src/modules/platform/http/graphql-call.mapper.ts +0 -52
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.7.39 - 2026-10-26
|
|
4
|
+
- Added: R258 follows the active cron schedule and accepts a declared outbox (`sides.be.queueOutbox`), and the optional slot `app.scripts.integration` carries integration scripts.
|
|
5
|
+
- Fixed: the lite scaffold templates, barrels and dev README follow the lite scaffold end-to-end fixes.
|
|
6
|
+
|
|
7
|
+
## 4.7.38 - 2026-10-26
|
|
8
|
+
- Changed: the bundled canon pins select @starci/stylelint-canon 2.0.13, @starci/eslint-canon-be 3.4.46, @starci/eslint-canon-fe 9.1.1, the Grammar lint families 0.12.5 and @starci/grammar 0.12.5.
|
|
9
|
+
- Fixed: the full and lite scaffold templates, skeletons and specs follow the scaffold end-to-end and repaint fixes made after 4.7.37.
|
|
10
|
+
|
|
3
11
|
## 4.7.37 - 2026-10-26
|
|
4
12
|
- Fixed: the scaffold SiteShell declares viewport=flow so Grammar lint reads it as site chrome, the hygiene sync follows the scaffold end-to-end fixes, and the scaffold json-logger spec expects the logger field order.
|
|
5
13
|
|
package/package.json
CHANGED
|
@@ -77,7 +77,7 @@ families:
|
|
|
77
77
|
package: '@starci/grammar'
|
|
78
78
|
entry: '@starci/grammar/common'
|
|
79
79
|
styleEntry: '@starci/grammar/common.css'
|
|
80
|
-
peers: [react, '@heroui/react', '@xyflow/react']
|
|
80
|
+
peers: [react, '@heroui/react', '@xyflow/react', react-aria-components]
|
|
81
81
|
packageSnapshot: common/DNA.yaml
|
|
82
82
|
scope: |
|
|
83
83
|
DNA snapshot only. This catalog carries no Common-side family boundary, idiom set or composition
|
|
@@ -23,42 +23,42 @@ pins:
|
|
|
23
23
|
source: packages/heroicons/package.json
|
|
24
24
|
why: 'StarCi custom Heroicons-compatible cuts; eslint-grammar-starci (icon.mjs) admits @starci/heroicons/24/outline and /16/solid as icon sources, so an app that uses them gets this exact version.'
|
|
25
25
|
'@starci/grammar':
|
|
26
|
-
version: 0.12.
|
|
26
|
+
version: 0.12.6
|
|
27
27
|
group: starci
|
|
28
28
|
install: registry
|
|
29
29
|
side: fe
|
|
30
30
|
source: packages/grammar/package.json
|
|
31
31
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
32
32
|
'@starci/eslint-canon-be':
|
|
33
|
-
version: 3.4.
|
|
33
|
+
version: 3.4.47
|
|
34
34
|
group: starci
|
|
35
35
|
install: registry
|
|
36
36
|
side: be
|
|
37
37
|
source: packages/eslint/be/package.json
|
|
38
38
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
39
39
|
'@starci/eslint-canon-fe':
|
|
40
|
-
version: 9.1.
|
|
40
|
+
version: 9.1.2
|
|
41
41
|
group: starci
|
|
42
42
|
install: registry
|
|
43
43
|
side: fe
|
|
44
44
|
source: packages/eslint/fe/package.json
|
|
45
45
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
46
46
|
'@starci/eslint-grammar-starci':
|
|
47
|
-
version: 0.12.
|
|
47
|
+
version: 0.12.6
|
|
48
48
|
group: starci
|
|
49
49
|
install: registry
|
|
50
50
|
side: fe
|
|
51
51
|
source: packages/eslint/grammar-starci/package.json
|
|
52
52
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
53
53
|
'@starci/eslint-grammar-offset-pop':
|
|
54
|
-
version: 0.12.
|
|
54
|
+
version: 0.12.6
|
|
55
55
|
group: starci
|
|
56
56
|
install: registry
|
|
57
57
|
side: fe
|
|
58
58
|
source: packages/eslint/grammar-offset-pop/package.json
|
|
59
59
|
why: 'the Offset Pop Grammar component API lint, versioned with @starci/grammar; its shared component contract comes from the StarCi family lint without copying rules.'
|
|
60
60
|
'@starci/stylelint-canon':
|
|
61
|
-
version: 2.0.
|
|
61
|
+
version: 2.0.13
|
|
62
62
|
group: starci
|
|
63
63
|
install: registry
|
|
64
64
|
side: fe
|
|
@@ -91,14 +91,14 @@ pins:
|
|
|
91
91
|
source: packages/test-world/package.json
|
|
92
92
|
why: 'the shared e2e library of every back end (R47, R48), a devDependency of every back end: the warm stack behind toxiproxy, the network-edge fakes, the Nest boot, the typed useTestWorld handle, useSandbox for contract specs and the outage lock. Kafka is real own infra (the one digest-pinned apache/kafka KRaft image, a broker listener and proxy per slot, slot-prefixed topics, consumer groups and client ids) and Postgres is schema-per-context (a schema and a login role per context in a shared database). Each worker has its own data slot (<ns>_w<k>) with its own databases, Keycloak realm, leased Redis DB, bucket/collection/topic prefixes, fakes host, toxiproxy proxies and outage lock; a run provisions min(jest workers, workers cap, default 2) slots, and state file protocol 2 pairs exactly with @starci/jest-preset (TEST_WORLD_PAIR_MISMATCH otherwise). A modules world boots real peer apps beside its modules, world.apps.<name>.during(fn) is the outage of a peer app, w.keycloak.clientSecret(client) answers the run-generated secret of a confidential realm client, world.keycloak.events/sessions read the realm user events and live sessions, world.infra.postgresql.connection(name) takes one database connection down while the others serve, and world.resolve and scope.resolve take any Nest token. Every path a declaration names (`stack`, seeds, the realm, Dockerfiles) resolves from the app root (the directory of hfs.json); the globalSetup registers the path aliases as TypeScript resolves them. Its CLI main is exported at ./cli for starci app stack.'
|
|
93
93
|
'@starci/cli':
|
|
94
|
-
version: 1.7.
|
|
94
|
+
version: 1.7.39
|
|
95
95
|
group: starci
|
|
96
96
|
install: registry
|
|
97
97
|
side: both
|
|
98
98
|
source: packages/cli/package.json
|
|
99
99
|
why: 'the only StarCi command package; product repositories install it for starci app, while @starci/hfs remains its pinned transitive implementation.'
|
|
100
100
|
'@starci/hfs':
|
|
101
|
-
version: 4.7.
|
|
101
|
+
version: 4.7.39
|
|
102
102
|
group: starci
|
|
103
103
|
install: registry
|
|
104
104
|
side: both
|
|
@@ -299,6 +299,11 @@ pins:
|
|
|
299
299
|
group: ui
|
|
300
300
|
side: fe
|
|
301
301
|
why: 'Grammar FlowGraph imports React Flow from @xyflow/react; every Grammar consumer declares this required peer at the version used by the Grammar package.'
|
|
302
|
+
react-aria-components:
|
|
303
|
+
version: 1.21.1
|
|
304
|
+
group: ui
|
|
305
|
+
side: fe
|
|
306
|
+
why: 'Grammar imports React Aria Components directly (Sidebar, Field); every Grammar consumer declares this required peer at the version HeroUI resolves.'
|
|
302
307
|
'@heroui/react':
|
|
303
308
|
version: 3.2.6
|
|
304
309
|
group: ui
|
|
@@ -99,7 +99,7 @@ concerns:
|
|
|
99
99
|
why: useTranslations for copy and the next-intl formatter for numbers, fixed dates and currency; FE-DATE owns live time display.
|
|
100
100
|
- id: ui
|
|
101
101
|
tier: core
|
|
102
|
-
packages: ['@heroui/react', '@heroui/styles', tailwindcss, '@starci/grammar']
|
|
102
|
+
packages: ['@heroui/react', '@heroui/styles', tailwindcss, '@starci/grammar', react-aria-components]
|
|
103
103
|
home: [fe.components, fe.feature]
|
|
104
104
|
pattern: FE-UI
|
|
105
105
|
forbids: ['@mantine/core', '@mui/material', '@chakra-ui/react', antd, styled-components, '@emotion/react', '@emotion/styled']
|
|
@@ -4405,7 +4405,7 @@ rules:
|
|
|
4405
4405
|
editionWhy: "owner:lite-backing-services makes Supabase lite's database backing and ruling:R212/case-10 moves the lite queue to Redis; the pgmq retirement and pg_cron ownership requirements apply to that backing."
|
|
4406
4406
|
docs: [docs/microservices.md#r258]
|
|
4407
4407
|
templateNa: "Queue declarations and enqueue-only cron commands depend on product-owned work and are authored in its Supabase migrations."
|
|
4408
|
-
law: "DB_QUEUE_CRON: the queue is BullMQ on Redis (ruling:R212/case-10), so the active migrations leave no pgmq queue named by a queue constant under modules/queues; a pgmq queue a migration created for one is dropped by a later migration. Every pgmq queue the active migrations leave is an event-bus topic queue named by a literal *_TOPIC_QUEUE constant under platform/event-bus, every such constant has its pgmq queue, and pgmq objects are granted only to the application role while they exist. A
|
|
4408
|
+
law: "DB_QUEUE_CRON: the queue is BullMQ on Redis (ruling:R212/case-10), so the active migrations leave no pgmq queue named by a queue constant under modules/queues; a pgmq queue a migration created for one is dropped by a later migration. Every pgmq queue the active migrations leave is an event-bus topic queue named by a literal *_TOPIC_QUEUE constant under platform/event-bus, every such constant has its pgmq queue, and pgmq objects are granted only to the application role while they exist. A pg_cron job belongs to a migration and only enqueues; its name is scheduled once while it is active, so a later migration schedules it again only after its own cron.unschedule of that name, and one tick function has one live job at a time. Its command, directly or through one enqueue-only *_tick function, inserts one row of a literal queue constant into the queue outbox table of ruleParams.db.queueOutbox, writing only its declared columns (the relay hands it to BullMQ). An app whose hfs.json sides.be.backing declares redis may declare its own outbox in sides.be.queueOutbox ({table, enqueue, queueParameter}); the command, or the tick, then calls the declared enqueue function with a literal queue constant for the declared parameter and pure other arguments, while the active definition of that function only inserts one row into the declared table with its queue column bound to that parameter (an ON CONFLICT DO NOTHING, a read of the declared table and pure expressions are the only other work). A direct insert into the app's outbox table, or any other function, stays refused. The job executes no business DML or HTTP request and shares no tick with an app scheduler. A pgmq.send validates only in the original body of a job an older migration scheduled while that queue existed; the live job and its current tick never enqueue that way. Removing a tick unschedules its job."
|
|
4409
4409
|
kinds: [check]
|
|
4410
4410
|
gates: [settle, land, ci]
|
|
4411
4411
|
failureCodes: ["DB_PGMQ_DECLARED", "DB_CRON_OWNED"]
|
|
@@ -4413,6 +4413,7 @@ rules:
|
|
|
4413
4413
|
- {kind: hfs, id: db-queue-cron, at: scripts/hfs/rules/database-queues.mjs}
|
|
4414
4414
|
proves:
|
|
4415
4415
|
- {path: packages/hfs/src/hfs-database-queues.spec.mjs, edition: lite, codes: [DB_PGMQ_DECLARED, DB_CRON_OWNED]}
|
|
4416
|
+
- {path: packages/hfs/src/hfs-queue-outbox-declaration.spec.mjs, edition: lite, codes: [DB_CRON_OWNED]}
|
|
4416
4417
|
exemplifiedBy:
|
|
4417
4418
|
- {path: packages/hfs/src/hfs-database-queues.spec.mjs, edition: lite, codes: [DB_PGMQ_DECLARED, DB_CRON_OWNED]}
|
|
4418
4419
|
witness:
|
|
@@ -43,7 +43,7 @@ versioning:
|
|
|
43
43
|
# journey (enabled with app.browser by `browser: true`).
|
|
44
44
|
# 3.6.0 is a minor (alpha.30): it ADDS the opt-in be.feature.realtime.sse slot, the server-sent-events door of the realtime kind (owner decision
|
|
45
45
|
# 2026-10-24: lite may serve SSE, and SSE is the default door for one-way push), and lets fe.modules.api hold the SSE stream operations (sse/).
|
|
46
|
-
# 3.7.0 is a minor (alpha.31): it ADDS the optional fe.transport.stream slot, the fetch reader of server-sent-events streams (the stream half of the
|
|
46
|
+
# 3.7.0 is a minor (alpha.31): it ADDS the optional app.scripts.integration slot (scripts/integration/*.mjs, the product test-support scripts that only the integration harness runs) and the optional fe.transport.stream slot, the fetch reader of server-sent-events streams (the stream half of the
|
|
47
47
|
# transport client layer), and lets fe.hooks.swr hold the SWR subscription hooks (api/sse/subscriptions/useSubscribe<X>Swr.ts, one useSWRSubscription per stream operation).
|
|
48
48
|
|
|
49
49
|
# Field meaning, per slot.
|
|
@@ -727,6 +727,24 @@ slots:
|
|
|
727
727
|
rules: [HFS_PLAINTEXT_SECRET, HFS_SCRIPT_ONE_OFF, BE_SPEC_PLACEMENT, HFS_REPO_LOCAL_CHECK]
|
|
728
728
|
exemplifiedBy:
|
|
729
729
|
- {path: packages/hfs/src/hfs-slot-ownership.spec.mjs, edition: lite}
|
|
730
|
+
- id: app.scripts.integration
|
|
731
|
+
since: 3.7.0
|
|
732
|
+
profiles: [app]
|
|
733
|
+
editionWhy: "Lite and full share the slot: a product's integration proof that needs a throwaway, unmigrated database has the same need in both editions, and lite's generic scripts path is closed to anything but codegen and delivery tooling."
|
|
734
|
+
# Product test-support scripts, run only by the integration harness (the integration suites call them; no package script, workflow, hook
|
|
735
|
+
# or deploy step does). A proof that must create a throwaway database that no migration has touched and run DDL on it keeps that work here,
|
|
736
|
+
# because the back-end lint refuses runtime DDL and raw query text in test sources. The folder is `integration`, not `test`:
|
|
737
|
+
# R252's script scan skips test folders, and a support script that creates databases must stay inside it. A spec or test is not a script
|
|
738
|
+
# (BE_SPEC_PLACEMENT), a check or lint source has no place (HFS_REPO_LOCAL_CHECK), and a script that reaches a host other than the private
|
|
739
|
+
# test stack is refused by its own connection guard, which the integration spec of the product proves.
|
|
740
|
+
path: "scripts/integration/*.mjs"
|
|
741
|
+
presence: optional
|
|
742
|
+
tracked: tracked
|
|
743
|
+
tier: none
|
|
744
|
+
tests: none
|
|
745
|
+
rules: [HFS_PLAINTEXT_SECRET, HFS_SCRIPT_ONE_OFF, BE_SPEC_PLACEMENT, HFS_REPO_LOCAL_CHECK]
|
|
746
|
+
exemplifiedBy:
|
|
747
|
+
- {path: packages/hfs/src/hfs-slot-ownership.spec.mjs, editions: [lite, full]}
|
|
730
748
|
- id: app.sides
|
|
731
749
|
since: 3.1.0
|
|
732
750
|
profiles: [app]
|
|
@@ -85,7 +85,7 @@ rules:
|
|
|
85
85
|
A recurring task is a job scheduler (`upsertJobScheduler`) that the queue module declares in its `schedulers` list and
|
|
86
86
|
`platform/queue` registers at boot, or, in an app on Supabase, a uniquely named pg_cron job of a migration whose command
|
|
87
87
|
(directly or through one `*_tick` function) only inserts one row of a queue constant into the queue outbox table of
|
|
88
|
-
`ruleParams.db.queueOutbox` (`public.queue`), which the relay hands to BullMQ; a tick has exactly one of the two owners. Its job is processed by the same
|
|
88
|
+
`ruleParams.db.queueOutbox` (`public.queue`), which the relay hands to BullMQ, or by calling the enqueue function that the app declares with its own outbox table in `hfs.json` `sides.be.queueOutbox` (redis declared in `sides.be.backing`; the function's active definition only inserts into that table); a tick has exactly one of the two owners. A job name is scheduled once while it is active: a later migration that replaces a tick's command calls `cron.unschedule` of the name first. Its job is processed by the same
|
|
89
89
|
`features/jobs/<job>/<job>.processor.ts` as any enqueued job. `@nestjs/schedule`, `@Cron`, `@Interval`, `@Timeout` and
|
|
90
90
|
`setInterval` for work are not used anywhere.
|
|
91
91
|
rationale: |-
|
|
@@ -73,6 +73,18 @@ function extraPackageProblems(side, entries) {
|
|
|
73
73
|
return [];
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** `sides.be.queueOutbox`: the app's own queue outbox ({table, enqueue, queueParameter}), which a pg_cron tick may enqueue through (R258); it needs the redis backing the relay hands rows to. */
|
|
77
|
+
function queueOutboxProblems(side, value) {
|
|
78
|
+
const declared = value.queueOutbox;
|
|
79
|
+
if (declared === undefined) return [];
|
|
80
|
+
if (side !== 'be') return ['queueOutbox belongs to the be side'];
|
|
81
|
+
const name = (item) => typeof item === 'string' && /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/.test(item);
|
|
82
|
+
const bad = [];
|
|
83
|
+
if (!isPlainObject(declared) || Object.keys(declared).sort().join() !== 'enqueue,queueParameter,table' || !name(declared.table) || !name(declared.enqueue) || !/^[a-z_][a-z0-9_]*$/.test(String(declared.queueParameter))) bad.push('sides.be.queueOutbox must be {table: <schema>.<table>, enqueue: <schema>.<function>, queueParameter: <parameter name>}');
|
|
84
|
+
if (!(value.backing ?? []).includes('redis')) bad.push('sides.be.queueOutbox needs sides.be.backing to declare redis, which the relay hands its rows to');
|
|
85
|
+
return bad;
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
function grammarProblems(side, grammar) {
|
|
77
89
|
if (grammar === undefined) return [];
|
|
78
90
|
if (side !== 'fe') return ['grammar belongs to the fe side'];
|
|
@@ -83,7 +95,7 @@ function declarationSideProblems(side, value, names) {
|
|
|
83
95
|
const bad = [];
|
|
84
96
|
const at = `sides.${side}`;
|
|
85
97
|
if (!isPlainObject(value)) return [`${at} must be an object`];
|
|
86
|
-
for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing'].includes(key)) bad.push(`${at} has unknown key ${key}`);
|
|
98
|
+
for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing', 'queueOutbox'].includes(key)) bad.push(`${at} has unknown key ${key}`);
|
|
87
99
|
bad.push(...appShapeProblems(value.apps, at, side, names));
|
|
88
100
|
if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot)))) bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
|
|
89
101
|
if (value.backing !== undefined && side !== 'be') bad.push('backing belongs to the be side');
|
|
@@ -91,7 +103,7 @@ function declarationSideProblems(side, value, names) {
|
|
|
91
103
|
bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
|
|
92
104
|
if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0)) bad.push(`${at}.reads must be a unique list of paths`);
|
|
93
105
|
if (value.connections !== undefined) bad.push(...connectionProblems(side, value));
|
|
94
|
-
bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
|
|
106
|
+
bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar), ...queueOutboxProblems(side, value));
|
|
95
107
|
return bad;
|
|
96
108
|
}
|
|
97
109
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// R258: an app whose queue is BullMQ on a declared Redis may keep its own outbox beside the canon `ruleParams.db.queueOutbox` table. The
|
|
2
|
+
// app declares it in hfs.json `sides.be.queueOutbox` ({table, enqueue, queueParameter}), and a pg_cron tick enqueues through the declared
|
|
3
|
+
// `enqueue` function only while that function's active definition does nothing but write the declared table with its queue column bound
|
|
4
|
+
// to the declared parameter. The checker reads the declaration and the function body; it names no app table or function.
|
|
5
|
+
import pg from 'libpg-query';
|
|
6
|
+
import { sqlStringParts as strings, walkSqlAst as walk, sqlParser } from '../../lib/sql-ast.mjs';
|
|
7
|
+
|
|
8
|
+
await pg.loadModule();
|
|
9
|
+
|
|
10
|
+
const sqlTree = sqlParser(pg);
|
|
11
|
+
const STATEMENTS = new Set(['PLpgSQL_stmt_block', 'PLpgSQL_stmt_execsql', 'PLpgSQL_stmt_if', 'PLpgSQL_stmt_assign', 'PLpgSQL_stmt_return']);
|
|
12
|
+
const OTHER_DML = ['UpdateStmt', 'DeleteStmt', 'MergeStmt'];
|
|
13
|
+
const qualified = (name) => name.includes('.') ? name : `public.${name}`;
|
|
14
|
+
|
|
15
|
+
/** The outbox an app declares, or null: it counts only while the back end declares the redis backing the relay hands rows to. */
|
|
16
|
+
export function queueOutboxDeclaration(declaration) {
|
|
17
|
+
const be = declaration?.sides?.be;
|
|
18
|
+
const declared = be?.queueOutbox;
|
|
19
|
+
if (!declared || !(be.backing ?? []).includes('redis')) return null;
|
|
20
|
+
return { table: qualified(declared.table), enqueue: qualified(declared.enqueue), parameter: declared.queueParameter };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function plpgsqlStatements(fn, body) {
|
|
24
|
+
const parameters = (fn.parameters ?? []).map((item) => item.FunctionParameter?.name).filter(Boolean).map((name) => `"${name.replaceAll('"', '""')}" text`).join(',');
|
|
25
|
+
let tag = '$hfs_outbox$';
|
|
26
|
+
while (body.includes(tag)) tag = `${tag.slice(0, -1)}_$`;
|
|
27
|
+
let tree;
|
|
28
|
+
try { tree = pg.parsePlPgSQLSync(`create function hfs_probe(${parameters}) returns text language plpgsql as ${tag}${body}${tag};`); } catch { return null; }
|
|
29
|
+
const trees = [];
|
|
30
|
+
let safe = true;
|
|
31
|
+
walk(tree, (node) => {
|
|
32
|
+
for (const key of Object.keys(node)) if (key.startsWith('PLpgSQL_stmt_') && !STATEMENTS.has(key)) safe = false;
|
|
33
|
+
const expr = node.PLpgSQL_expr;
|
|
34
|
+
if (expr) trees.push(sqlTree(expr.parseMode === 0 ? expr.query : `select ${expr.query}`));
|
|
35
|
+
});
|
|
36
|
+
return safe ? trees : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function bodyStatements(fn) {
|
|
40
|
+
const option = (name) => (fn.options ?? []).find((item) => item.DefElem?.defname === name)?.DefElem?.arg;
|
|
41
|
+
const language = option('language')?.String?.sval ?? 'sql';
|
|
42
|
+
const body = strings(option('as')?.List?.items).join('');
|
|
43
|
+
if (language === 'plpgsql') return plpgsqlStatements(fn, body);
|
|
44
|
+
if (language !== 'sql') return null;
|
|
45
|
+
if (fn.sql_body) return (fn.sql_body.List ? fn.sql_body.List.items : [fn.sql_body]).map((stmt) => ({ stmts: [{ stmt }] }));
|
|
46
|
+
return sqlTree(body)?.stmts?.map((entry) => ({ stmts: [entry] })) ?? null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** True when the nodes hold no sub-select or other statement and call only functions `pureCall` admits. */
|
|
50
|
+
function pureNodes(nodes, pureCall) {
|
|
51
|
+
let ok = true;
|
|
52
|
+
walk(nodes, (node) => {
|
|
53
|
+
if (node.SubLink || node.SelectStmt || node.InsertStmt || OTHER_DML.some((key) => node[key])) ok = false;
|
|
54
|
+
if (node.FuncCall && !pureCall(node.FuncCall)) ok = false;
|
|
55
|
+
});
|
|
56
|
+
return ok;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `insert into <table> (..., queue, ...) values (..., <parameter>, ...) [on conflict .. do nothing] [returning ..]` with pure other values. */
|
|
60
|
+
function insertOk(declared, insert, pureCall) {
|
|
61
|
+
if (insert.withClause || `${insert.relation?.schemaname || 'public'}.${insert.relation?.relname}` !== declared.table) return false;
|
|
62
|
+
if (insert.onConflictClause && insert.onConflictClause.action !== 'ONCONFLICT_NOTHING') return false;
|
|
63
|
+
const columns = (insert.cols ?? []).map((item) => item.ResTarget?.name);
|
|
64
|
+
const rows = insert.selectStmt?.SelectStmt?.valuesLists ?? [];
|
|
65
|
+
const values = rows.length === 1 ? rows[0].List?.items ?? [] : [];
|
|
66
|
+
const at = columns.indexOf('queue');
|
|
67
|
+
if (at < 0 || new Set(columns).size !== columns.length || values.length !== columns.length) return false;
|
|
68
|
+
const bound = values[at].ColumnRef?.fields;
|
|
69
|
+
if (!bound || strings(bound).join('.') !== declared.parameter || bound.length !== 1) return false;
|
|
70
|
+
return pureNodes(values.filter((_, index) => index !== at), pureCall);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A read of the declared table with pure expressions, or an expression over variables alone. */
|
|
74
|
+
function readOk(declared, tree, pureCall) {
|
|
75
|
+
let ok = true;
|
|
76
|
+
walk(tree, (node) => {
|
|
77
|
+
if (OTHER_DML.some((key) => node[key]) || node.InsertStmt || node.SelectStmt?.intoClause) ok = false;
|
|
78
|
+
if (node.FuncCall && !pureCall(node.FuncCall)) ok = false;
|
|
79
|
+
if (node.RangeVar && `${node.RangeVar.schemaname || 'public'}.${node.RangeVar.relname}` !== declared.table) ok = false;
|
|
80
|
+
});
|
|
81
|
+
return ok;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function statementOk(declared, tree, pureCall) {
|
|
85
|
+
const stmt = tree?.stmts?.length === 1 ? tree.stmts[0].stmt : null;
|
|
86
|
+
if (stmt?.InsertStmt) return insertOk(declared, stmt.InsertStmt, pureCall);
|
|
87
|
+
return Boolean(stmt?.SelectStmt) && readOk(declared, tree, pureCall);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The position of the queue parameter when the active definition of the declared enqueue function only writes the declared outbox
|
|
92
|
+
* (inserts, reads of that table and pure expressions), or -1. `pureCall` admits a function call that does no work.
|
|
93
|
+
*/
|
|
94
|
+
export function outboxEnqueueQueueIndex(declared, entry, pureCall) {
|
|
95
|
+
const fn = entry?.node;
|
|
96
|
+
if (!fn) return -1;
|
|
97
|
+
const index = (fn.parameters ?? []).findIndex((item) => item.FunctionParameter?.name === declared.parameter);
|
|
98
|
+
const trees = bodyStatements(fn);
|
|
99
|
+
if (index < 0 || !trees?.length || !trees.every((tree) => statementOk(declared, tree, pureCall))) return -1;
|
|
100
|
+
const inserts = trees.filter((tree) => tree?.stmts?.[0]?.stmt?.InsertStmt).length;
|
|
101
|
+
return inserts === 1 ? index : -1;
|
|
102
|
+
}
|
|
@@ -11,10 +11,11 @@ import { queueSourceFacts, queueSchedulers, queueProblem as problem } from './da
|
|
|
11
11
|
import { readJson, readText } from './read.mjs';
|
|
12
12
|
import { DB_CRON_OWNED, DB_PGMQ_DECLARED, isActiveMigration } from './database-constants.mjs';
|
|
13
13
|
import { loadSlotManifest } from '../slots.mjs';
|
|
14
|
+
import { queueOutboxDeclaration, outboxEnqueueQueueIndex } from './database-queue-outbox.mjs';
|
|
14
15
|
|
|
15
16
|
await pg.loadModule();
|
|
16
17
|
|
|
17
|
-
const PURE_CALLS = new Set(['jsonb_build_object', 'json_build_object', 'jsonb_build_array', 'json_build_array', 'to_jsonb', 'now', 'clock_timestamp']);
|
|
18
|
+
const PURE_CALLS = new Set(['jsonb_build_object', 'json_build_object', 'jsonb_build_array', 'json_build_array', 'to_jsonb', 'now', 'clock_timestamp', 'date_trunc']);
|
|
18
19
|
const TABLE_PRIVILEGES = ['select', 'insert', 'update', 'delete', 'truncate', 'references', 'trigger', 'maintain'];
|
|
19
20
|
const sqlName = (nodes) => strings(nodes).join('.');
|
|
20
21
|
const callName = (call) => sqlName(call.funcname);
|
|
@@ -54,9 +55,11 @@ function inspectQueueCall(state, call, file, migration) {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
function recordSchedule(state, call, file) {
|
|
57
|
-
const entry = { call, file, created: new Map(state.created), functions: new Map(state.functions) };
|
|
58
|
-
state.schedules.push(entry);
|
|
59
58
|
const job = sqlLiteral(argument(call, 0, ['job_name']));
|
|
59
|
+
// The names scheduled and not unscheduled since, in migration order: a name is a duplicate only while it is still scheduled.
|
|
60
|
+
const entry = { call, file, created: new Map(state.created), functions: new Map(state.functions), active: new Set(state.scheduledNames) };
|
|
61
|
+
state.schedules.push(entry);
|
|
62
|
+
if (job !== null) state.scheduledNames.add(job);
|
|
60
63
|
const schedule = sqlLiteral(argument(call, 1, ['schedule']));
|
|
61
64
|
const command = sqlLiteral(argument(call, 2, ['command']));
|
|
62
65
|
if (job !== null && schedule !== null && command !== null) {
|
|
@@ -77,6 +80,7 @@ function inspectCronCall(state, call, file, migration) {
|
|
|
77
80
|
if (job !== null) {
|
|
78
81
|
state.unschedules.push({ name: job, file });
|
|
79
82
|
state.activeCron.delete(job);
|
|
83
|
+
state.scheduledNames.delete(job);
|
|
80
84
|
state.liveSchedules.delete(job);
|
|
81
85
|
}
|
|
82
86
|
else problem(state, DB_CRON_OWNED, file, 'cron.unschedule must identify the migration-owned job by literal name');
|
|
@@ -205,12 +209,16 @@ function enqueue(state, call) {
|
|
|
205
209
|
return queue !== null && state.created.has(queue) && safe ? queue : null;
|
|
206
210
|
}
|
|
207
211
|
|
|
212
|
+
function pureCall(call) {
|
|
213
|
+
return uuidConstructor(call) || PURE_CALLS.has(callName(call).replace(/^pg_catalog\./, ''));
|
|
214
|
+
}
|
|
215
|
+
|
|
208
216
|
function pureArguments(call) {
|
|
209
217
|
return pureExpressions(call.args);
|
|
210
218
|
}
|
|
211
219
|
|
|
212
220
|
function pureExpressions(nodes) {
|
|
213
|
-
let safe = callsOf(nodes).every(
|
|
221
|
+
let safe = callsOf(nodes).every(pureCall);
|
|
214
222
|
walk(nodes, (node) => {
|
|
215
223
|
if (['SubLink', 'SelectStmt', 'InsertStmt', 'UpdateStmt', 'DeleteStmt', 'MergeStmt'].some((key) => node[key])) safe = false;
|
|
216
224
|
});
|
|
@@ -223,6 +231,15 @@ function queueOutbox(manifest) {
|
|
|
223
231
|
return declared ? { table: declared.table, columns: new Set(declared.columns) } : null;
|
|
224
232
|
}
|
|
225
233
|
|
|
234
|
+
/** The queue constant a call of the app's declared outbox enqueue function enqueues (hfs.json sides.be.queueOutbox), or null. */
|
|
235
|
+
function declaredEnqueue(state, call) {
|
|
236
|
+
const declared = state.declaredOutbox;
|
|
237
|
+
if (!declared || qualified(callName(call)) !== declared.enqueue) return null;
|
|
238
|
+
const index = outboxEnqueueQueueIndex(declared, state.functions.get(declared.enqueue), pureCall);
|
|
239
|
+
const queue = index < 0 ? null : sqlLiteral(argument(call, index, [declared.parameter]));
|
|
240
|
+
return queue !== null && state.constants.has(queue) && pureArguments(call) ? queue : null;
|
|
241
|
+
}
|
|
242
|
+
|
|
226
243
|
/** The queue constant one outbox row enqueues: `insert into <outbox> (queue, ...) values ('<queue constant>', ...)` with pure values. */
|
|
227
244
|
function outboxEnqueue(state, insert) {
|
|
228
245
|
if (!state.outbox || insert.returningClause || insert.returningList || insert.onConflictClause || insert.withClause) return null;
|
|
@@ -242,7 +259,8 @@ function singleEnqueue(state, tree, legacy) {
|
|
|
242
259
|
const insert = tree?.stmts?.length === 1 ? tree.stmts[0].stmt?.InsertStmt : undefined;
|
|
243
260
|
if (insert) return outboxEnqueue(state, insert);
|
|
244
261
|
const call = singleCall(tree);
|
|
245
|
-
|
|
262
|
+
if (!call) return null;
|
|
263
|
+
return declaredEnqueue(state, call) ?? (legacy ? enqueue(state, call) : null);
|
|
246
264
|
}
|
|
247
265
|
|
|
248
266
|
/** PostgreSQL's catalog-owned scalar UUID constructor adds an envelope identity without doing work in the tick. */
|
|
@@ -311,7 +329,7 @@ function scheduleTarget(state, command, legacy) {
|
|
|
311
329
|
const tree = sqlTree(command);
|
|
312
330
|
const target = singleCall(tree);
|
|
313
331
|
if (!target) return { tick: null, queues: singleEnqueue(state, tree, legacy) };
|
|
314
|
-
if (!callName(target).endsWith('_tick')) return { tick: null, queues: legacy ? enqueue(state, target) : null };
|
|
332
|
+
if (!callName(target).endsWith('_tick')) return { tick: null, queues: declaredEnqueue(state, target) ?? (legacy ? enqueue(state, target) : null) };
|
|
315
333
|
const tick = qualified(callName(target));
|
|
316
334
|
const fn = state.functions.get(tick);
|
|
317
335
|
const queues = fn && pureArguments(target) && tickQueues(state, fn, legacy);
|
|
@@ -325,7 +343,7 @@ function tickRemoval(state, tick, name) {
|
|
|
325
343
|
}
|
|
326
344
|
}
|
|
327
345
|
|
|
328
|
-
function scheduleCheck(state, schedule,
|
|
346
|
+
function scheduleCheck(state, schedule, schedulers, ticks) {
|
|
329
347
|
const { call, file } = schedule;
|
|
330
348
|
const name = sqlLiteral(argument(call, 0, ['job_name']));
|
|
331
349
|
const command = sqlLiteral(argument(call, 2, ['command']));
|
|
@@ -333,22 +351,23 @@ function scheduleCheck(state, schedule, names, schedulers, ticks) {
|
|
|
333
351
|
problem(state, DB_CRON_OWNED, file, 'cron.schedule requires literal job name, cadence and command for migration ownership');
|
|
334
352
|
return;
|
|
335
353
|
}
|
|
336
|
-
if (
|
|
337
|
-
names.add(name);
|
|
354
|
+
if (schedule.active.has(name)) problem(state, DB_CRON_OWNED, file, 'a cron job name is scheduled once while it is active: cron.unschedule it before a later migration schedules it again');
|
|
338
355
|
const historical = { ...state, created: schedule.created, functions: schedule.functions };
|
|
339
356
|
const { tick, queues } = scheduleTarget(historical, command, true);
|
|
340
357
|
if (!queues) problem(state, DB_CRON_OWNED, file, 'a cron command inserts one row of a queue constant into the queue outbox, directly or through one existing *_tick function that only does that; business DML, dynamic SQL and network calls are refused');
|
|
341
358
|
if (state.liveSchedules.get(name) === schedule && !scheduleTarget(state, command, false).queues) problem(state, DB_CRON_OWNED, file, 'the live cron job must insert one outbox row of a queue constant (ruling:R212/case-10): it targets a missing queue or tick, still enqueues with pgmq.send, or its current tick no longer only does that');
|
|
342
|
-
tickOwner(state, tick,
|
|
359
|
+
tickOwner(state, tick, name, schedule, ticks);
|
|
343
360
|
const owners = [name, ...(tick ? [tick, tick.split('.').at(-1)] : []), ...[queues ?? []].flat()];
|
|
344
361
|
if (owners.some((owner) => schedulers.has(owner))) problem(state, DB_CRON_OWNED, file, 'the tick is also declared in an application scheduler list; give it one owner');
|
|
345
362
|
tickRemoval(state, tick, name);
|
|
346
363
|
}
|
|
347
364
|
|
|
348
|
-
function
|
|
365
|
+
/** One tick function has one cron owner at a time: an earlier job of the tick that is still scheduled is a second owner. */
|
|
366
|
+
function tickOwner(state, tick, name, schedule, ticks) {
|
|
349
367
|
if (!tick) return;
|
|
350
|
-
|
|
351
|
-
|
|
368
|
+
const owners = ticks.get(tick) ?? [];
|
|
369
|
+
if (owners.some((owner) => schedule.active.has(owner))) problem(state, DB_CRON_OWNED, schedule.file, 'a tick function has more than one cron owner');
|
|
370
|
+
ticks.set(tick, [...owners, name]);
|
|
352
371
|
}
|
|
353
372
|
|
|
354
373
|
function queueState({ repoRoot, files = [], all = files, repo = {}, manifest }) {
|
|
@@ -356,7 +375,7 @@ function queueState({ repoRoot, files = [], all = files, repo = {}, manifest })
|
|
|
356
375
|
const declaration = readJson(repoRoot, 'hfs.json') ?? repo;
|
|
357
376
|
const connected = ['be', 'fe'].some((side) => (declaration.sides?.[side]?.connections ?? []).some((item) => item.provider === 'supabase'));
|
|
358
377
|
if (repo.edition !== 'lite' && declaration.edition !== 'lite' && !declaration.supabase && !connected && !paths.some((file) => file.startsWith('supabase/'))) return null;
|
|
359
|
-
const state = { repoRoot, appRole: declaration.supabase?.appRole ?? 'app_be', findings: [], outbox: queueOutbox(manifest ?? loadSlotManifest()), constants: new Map(), topics: new Map(), created: new Map(), functions: new Map(), schedules: [], activeCron: new Map(), liveSchedules: new Map(), unschedules: [], drops: [], grants: [], queueAcls: new Map() };
|
|
378
|
+
const state = { repoRoot, appRole: declaration.supabase?.appRole ?? 'app_be', findings: [], outbox: queueOutbox(manifest ?? loadSlotManifest()), declaredOutbox: queueOutboxDeclaration(declaration), scheduledNames: new Set(), constants: new Map(), topics: new Map(), created: new Map(), functions: new Map(), schedules: [], activeCron: new Map(), liveSchedules: new Map(), unschedules: [], drops: [], grants: [], queueAcls: new Map() };
|
|
360
379
|
state.sources = queueSourceFacts(state, paths, inspectCalls);
|
|
361
380
|
migrationFacts(state, paths);
|
|
362
381
|
return state;
|
|
@@ -369,10 +388,9 @@ function validateQueues(state, inScope) {
|
|
|
369
388
|
}
|
|
370
389
|
for (const [topic, file] of state.topics) if (!state.created.has(topic)) problem(state, DB_PGMQ_DECLARED, file, `event-bus topic queue ${topic} has no pgmq.create in an active migration`);
|
|
371
390
|
for (const { node, file, created, executed } of state.grants) grantCheck({ ...state, created: executed ? created : state.created }, node, file);
|
|
372
|
-
const
|
|
373
|
-
const ticks = new Set();
|
|
391
|
+
const ticks = new Map();
|
|
374
392
|
const schedulers = queueSchedulers(state.sources);
|
|
375
|
-
for (const schedule of state.schedules) scheduleCheck(state, schedule,
|
|
393
|
+
for (const schedule of state.schedules) scheduleCheck(state, schedule, schedulers, ticks);
|
|
376
394
|
return state.findings.filter((finding) => inScope(finding.path));
|
|
377
395
|
}
|
|
378
396
|
|
|
@@ -65,9 +65,11 @@ const DATABASE_ERROR = 'be/src/modules/platform/database/errors/database.error.t
|
|
|
65
65
|
/** Skeleton files the lite starter leaves out and the queue capabilities use, each from its skeleton template. */
|
|
66
66
|
const SKELETON_FILES = Object.freeze([
|
|
67
67
|
['be/src/modules/platform/database/database.sql.ts', 'skeleton-lite/src/modules/platform/database/database.sql.ts'],
|
|
68
|
+
['be/src/modules/platform/primitives/sequence.policy.ts', 'skeleton/src/modules/platform/primitives/sequence.policy.ts'],
|
|
69
|
+
['be/src/modules/platform/primitives/sequence.policy.spec.ts', 'skeleton/src/modules/platform/primitives/sequence.policy.spec.ts'],
|
|
68
70
|
]);
|
|
69
71
|
|
|
70
|
-
/** The sql tag of the outbox and claim statements (with its identifier error) and the in-order relay
|
|
72
|
+
/** The sql tag of the outbox and claim statements (with its identifier error) and the in-order relay the queue adapters walk their rows with. */
|
|
71
73
|
function skeletonFiles(repoRoot) {
|
|
72
74
|
const created = SKELETON_FILES.filter(([relative]) => !fs.existsSync(path.join(repoRoot, ...relative.split('/'))))
|
|
73
75
|
.map(([relative, source]) => ({ relative, text: render(template(`be/${source}`), {}) }));
|
package/scaffold/app.mjs
CHANGED
|
@@ -199,7 +199,7 @@ const LITE_STARTER_DEPENDENCIES = Object.freeze({
|
|
|
199
199
|
*/
|
|
200
200
|
const FE_APP_DEPENDENCIES = Object.freeze({
|
|
201
201
|
'@<project>/i18n': '*', '@<project>/ui': '*',
|
|
202
|
-
'@heroui/react': null, '@heroui/styles': null, '@starci/grammar': null, '@xyflow/react': null, next: null, 'next-intl': null, react: null, 'react-dom': null,
|
|
202
|
+
'@heroui/react': null, '@heroui/styles': null, '@starci/grammar': null, '@xyflow/react': null, 'react-aria-components': null, next: null, 'next-intl': null, react: null, 'react-dom': null,
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
/**
|
|
@@ -207,7 +207,7 @@ const FE_APP_DEPENDENCIES = Object.freeze({
|
|
|
207
207
|
* the front end is the Auth client of modules/auth only) and server-only for its own next-intl request config.
|
|
208
208
|
*/
|
|
209
209
|
const LITE_FE_APP_DEPENDENCIES = Object.freeze({
|
|
210
|
-
'@heroicons/react': null, '@heroui/react': null, '@heroui/styles': null, '@starci/grammar': null, '@starci/heroicons': null, '@xyflow/react': null,
|
|
210
|
+
'@heroicons/react': null, '@heroui/react': null, '@heroui/styles': null, '@starci/grammar': null, '@starci/heroicons': null, '@xyflow/react': null, 'react-aria-components': null,
|
|
211
211
|
'@supabase/supabase-js': null, next: null, 'next-intl': null, react: null, 'react-dom': null, 'server-only': null,
|
|
212
212
|
});
|
|
213
213
|
|
|
@@ -218,7 +218,7 @@ const LITE_FE_APP_DEPENDENCIES = Object.freeze({
|
|
|
218
218
|
* ./routing, client-safe: the default locale a client boundary reads).
|
|
219
219
|
*/
|
|
220
220
|
const FE_PACKAGES = Object.freeze({
|
|
221
|
-
ui: { exports: ['.'], dependencies: { '@heroui/react': null, '@starci/grammar': null, '@starci/heroicons': null, '@xyflow/react': null, 'next-intl': null, react: null, 'react-dom': null } },
|
|
221
|
+
ui: { exports: ['.'], dependencies: { '@heroui/react': null, '@starci/grammar': null, '@starci/heroicons': null, '@xyflow/react': null, 'react-aria-components': null, 'next-intl': null, react: null, 'react-dom': null } },
|
|
222
222
|
i18n: { exports: ['.', './proxy', './routing'], dependencies: { next: null, 'next-intl': null, 'server-only': null } },
|
|
223
223
|
});
|
|
224
224
|
|
|
@@ -304,11 +304,11 @@ export function peerDependencies(pkg, pins, pairs = parseYaml(fs.readFileSync(PE
|
|
|
304
304
|
/**
|
|
305
305
|
* The fe-stack core packages one version of which the whole install resolves (npm `overrides`, at their canon pins): a
|
|
306
306
|
* transitive dependency otherwise brings its own (zustand 4 under @xyflow/react, dayjs under typeorm, a hoisted newer zod
|
|
307
|
-
* that breaks the zodResolver types), and @xyflow/react
|
|
307
|
+
* that breaks the zodResolver types), and @xyflow/react and react-aria-components stay the grammar's one version. Two are security overrides, each dropped when
|
|
308
308
|
* upstream ships the fix (canon-pins.yaml says why): @graphql-tools/utils (@nestjs/graphql 13.x pulls <=12.0.0, GHSA-7mx3-vvmw-hjmv) and multer
|
|
309
309
|
* (@nestjs/platform-express depends on exactly 2.4.0, GHSA-q7qp-rjg7-q26m).
|
|
310
310
|
*/
|
|
311
|
-
const ROOT_OVERRIDES = Object.freeze(['@graphql-tools/utils', '@xyflow/react', 'dayjs', 'multer', 'zod', 'zustand']);
|
|
311
|
+
const ROOT_OVERRIDES = Object.freeze(['@graphql-tools/utils', '@xyflow/react', 'dayjs', 'multer', 'react-aria-components', 'zod', 'zustand']);
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
314
|
* The root package.json of a new app, the monorepo root: name, workspaces, npm, its edition's dependencies with their runtime
|
|
@@ -412,6 +412,7 @@ const LITE_DEFERRED_GENERATOR_FILES = new Set([
|
|
|
412
412
|
'src/modules/platform/database/database.sql.ts',
|
|
413
413
|
'src/modules/platform/database/migration-runner.service.ts',
|
|
414
414
|
'src/modules/platform/database/seed-runner.service.ts',
|
|
415
|
+
'src/modules/platform/primitives/sequence.policy.ts',
|
|
415
416
|
]);
|
|
416
417
|
const liteBaseSource = (rel) => !rel.startsWith('apps/cli/')
|
|
417
418
|
&& !rel.startsWith('src/features/cli/')
|
|
@@ -36,9 +36,15 @@ const REGISTRATIONS = Object.freeze({
|
|
|
36
36
|
names: ["InjectPrimaryEntityManager", "PRIMARY_ENTITY_MANAGER"],
|
|
37
37
|
},
|
|
38
38
|
],
|
|
39
|
-
// The queue and jobs capabilities state their outbox and claim statements with the sql tag
|
|
40
|
-
//
|
|
39
|
+
// The queue and jobs capabilities state their outbox and claim statements with the sql tag and walk rows with the in-order relay
|
|
40
|
+
// (the lite starter already carries the record guard the BullMQ client reads stored jobs with).
|
|
41
41
|
queue: [
|
|
42
|
+
{
|
|
43
|
+
file: "be/src/modules/platform/primitives/index.ts",
|
|
44
|
+
source: "./sequence.policy",
|
|
45
|
+
names: ["eachInOrder"],
|
|
46
|
+
beforeSource: "./record.policy",
|
|
47
|
+
},
|
|
42
48
|
{
|
|
43
49
|
file: "be/src/modules/platform/database/index.ts",
|
|
44
50
|
source: "./database.sql",
|
|
@@ -50,7 +56,7 @@ const REGISTRATIONS = Object.freeze({
|
|
|
50
56
|
{
|
|
51
57
|
file: "be/src/modules/platform/database/index.ts",
|
|
52
58
|
source: "./database.sql",
|
|
53
|
-
names: ["sql"],
|
|
59
|
+
names: ["BATCH_ROWS", "sql"],
|
|
54
60
|
beforeSource: "./errors/database.error",
|
|
55
61
|
},
|
|
56
62
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Production stack
|
|
2
2
|
|
|
3
|
-
The app and its dependencies run on Docker Swarm; Supabase, when declared, is a hosted service. The tracked model declares the application services, one digest-pinned Caddy ingress and one digest-pinned PostgreSQL service on an internal backing network, with its data on a named persistent volume and credentials supplied through mounted secrets. On the first boot of an empty data volume, PostgreSQL runs the mounted
|
|
3
|
+
The app and its dependencies run on Docker Swarm; Supabase, when declared, is a hosted service. The tracked model declares the application services, one digest-pinned Caddy ingress and one digest-pinned PostgreSQL service on an internal backing network, with its data on a named persistent volume and credentials supplied through mounted secrets. On the first boot of an empty data volume, PostgreSQL runs the mounted `.starcistacks/production/infra/swarm/postgres-init.sh` config to create the `app_be` role with access to this app's database and schema, without superuser, database-creation, role-creation, replication or RLS-bypass privileges. Existing data volumes skip initialization and retain their roles and credentials.
|
|
4
4
|
The model is a deployment declaration. It contains no owner credentials, real DNS receipt, completed release or restore proof. The public records under `.starcistacks/production/infra/swarm/` mark those owner-run operations as pending. Its all-zero application image digests are illustrative and must be replaced before deployment.
|
|
5
5
|
|
|
6
6
|
The runtime template tracks no encrypted members. Scaffolding generates the declared database connection, application password and PostgreSQL administrator password members with placeholder values encrypted to this app's own recipient in `.sops.yaml`. Replace them with `starci app secret set production` using the matching host age identity in untracked local custody. The sealed connection uses role `app_be`, database `{{project}}` and internal endpoint `postgres:5432`; its URI-encoded password matches the separate `primary-db-password` member. The administrator password is distinct. The API receives only its least-privilege connection; only PostgreSQL receives the two password files for initialization. The non-empty application password contains no line breaks. The service has no TTY: initialization creates the role without a password, then feeds the two `psql` `\password` prompts through stdin using Bash's builtin `printf`, so psql encrypts it before sending SQL. No password travels in an initialization command argument or a plaintext SQL statement.
|
|
@@ -27,7 +27,7 @@ Every item is pending. Swarm initialization, provider URIs, DNS changes and key
|
|
|
27
27
|
| DNS | Replace the reserved `example.invalid` hosts consistently in the manifest, Caddyfile and public configuration; publish address records for the product, API and landing hosts and retain a provider receipt in `.starcistacks/production/infra/swarm/owner-actions.md`. |
|
|
28
28
|
| TLS | Caddy issues certificates after real DNS resolves. Provision `{{project}}-production-ingress-data` and `{{project}}-production-ingress-config-data` on the selected node; retain an issuance and renewal receipt in `.starcistacks/production/infra/swarm/owner-actions.md`. |
|
|
29
29
|
| Database | Prepare creates `{{project}}-production-postgres-data` on the declared stateful node; the normal up path starts PostgreSQL and initializes `app_be` on its first empty-volume boot. Seal the matching role, database and password described above before up. Existing databases retain their current roles and credentials; initialization never rewrites them. Record the recovery owner without copying credentials here. |
|
|
30
|
-
| Secret custody | Replace generated placeholders in `.starcistacks/production/secrets/primary-db-url.enc`,
|
|
30
|
+
| Secret custody | Replace generated placeholders in `.starcistacks/production/secrets/primary-db-url.enc`, `.starcistacks/production/secrets/primary-db-password.enc` and `.starcistacks/production/secrets/postgres-password.enc` with the matching application connection/password and distinct administrator password; record their key names in the environment roster. The age identity stays only in the host's untracked `.claude/secret.env`. |
|
|
31
31
|
| External secrets | Materialize the sealed members in owner custody and create `{{project}}-production-primary-db-url-v1`, `{{project}}-production-primary-db-password-v1` and `{{project}}-production-postgres-password-v1`. The API and PostgreSQL read their separately granted mounted files. A later credential rotation updates the actual database role under owner authority and rotates matching immutable secrets; changing a mounted file does not rerun first-boot initialization. |
|
|
32
32
|
| Public build configuration | Build the front end with its declared public site and GraphQL URLs. Public browser values stay outside sealed secret custody. |
|
|
33
33
|
| Immutable release | Replace the illustrative all-zero application digests in the manifest, model and `.starcistacks/production/infra/swarm/releases/images.lock.yaml` with the verified release digests. Store each rendered release under `/srv/{{project}}/releases/<digest>`. Retain the last accepted record in `.starcistacks/production/infra/swarm/releases/previous.yaml`, then move the pointer and update `.starcistacks/production/infra/swarm/releases/current.yaml` after verification. |
|
|
@@ -7,7 +7,7 @@ The runtime template tracks no encrypted members. Scaffolding generates the two
|
|
|
7
7
|
|
|
8
8
|
| Command | Operation |
|
|
9
9
|
| --- | --- |
|
|
10
|
-
| prepare | Run `npm run db:start` at the app root; obtain the local Supabase connection and Auth configuration. For a declared Redis
|
|
10
|
+
| prepare | Run `npm run db:start` at the app root; obtain the local Supabase connection and Auth configuration. For a declared Redis (its `redis:create`, `redis:start` and `redis:stop` scripts arrive in package.json with the first queue or job), run the create script once, then the start script when using the native app profile. An owner who chooses local Swarm initializes it, labels its node `{{project}}=dev` and provisions the ingress volumes; the model starts its declared Redis with the app. Replace the reserved development host consistently in the manifest, Caddyfile and public configuration; resolve it to the node and record this in `.starcistacks/dev/infra/swarm/owner-actions.md`. Create the external development secrets named in the model from real sealed members. |
|
|
11
11
|
| doctor | From this directory, run `docker stack config -c infra/swarm/stack.yaml`. Confirm image, secret and local Supabase availability. |
|
|
12
12
|
| up | Run `docker stack deploy -c infra/swarm/stack.yaml {{project}}-dev` from this directory after preparation. |
|
|
13
13
|
| status | Run `docker stack services {{project}}-dev`. |
|
|
@@ -12,7 +12,10 @@ const bootstrap = async (): Promise<void> => {
|
|
|
12
12
|
const env = EnvSource.fromProcess()
|
|
13
13
|
const options = read{{appPascal}}Env(env)
|
|
14
14
|
const logger = createJsonLogger(new SystemClockService(), new SystemIds())
|
|
15
|
-
const app = await NestFactory.create(AppModule.register(options), {
|
|
15
|
+
const app = await NestFactory.create(AppModule.register(options), {
|
|
16
|
+
rawBody: true,
|
|
17
|
+
logger: createNestLogger(logger),
|
|
18
|
+
})
|
|
16
19
|
applyCorrelation(app)
|
|
17
20
|
applyHttpSecurity(app, options.httpSecurity, { trustProxy: 1 })
|
|
18
21
|
app.enableShutdownHooks()
|
|
@@ -24,6 +27,8 @@ const bootstrap = async (): Promise<void> => {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
bootstrap().catch((error: unknown) => {
|
|
27
|
-
createJsonLogger(new SystemClockService(), new SystemIds()).error(LoggingLogEvent.StartupFailed, error, {
|
|
30
|
+
createJsonLogger(new SystemClockService(), new SystemIds()).error(LoggingLogEvent.StartupFailed, error, {
|
|
31
|
+
service: "{{app}}",
|
|
32
|
+
})
|
|
28
33
|
process.exitCode = 1
|
|
29
34
|
})
|
|
@@ -4,7 +4,7 @@ import { ClockModule } from "@modules/platform/clock"
|
|
|
4
4
|
import { DatabaseModule } from "@modules/platform/database"
|
|
5
5
|
import type { DatabaseConnectionConfig, DatabaseConnectionOptions } from "@modules/platform/database"
|
|
6
6
|
import { IdsModule } from "@modules/platform/ids"
|
|
7
|
-
import {
|
|
7
|
+
import { HttpModule } from "@modules/platform/http"
|
|
8
8
|
import { LoggingModule } from "@modules/platform/logging"
|
|
9
9
|
import type { CliAppOptions } from "../cli.options"
|
|
10
10
|
|
|
@@ -5,7 +5,7 @@ export { MigrationRunnerService } from "./migration-runner.service"
|
|
|
5
5
|
export { DEFAULT_SEED_ENV } from "./seed-connections.client"
|
|
6
6
|
export { SeedRunnerService } from "./seed-runner.service"
|
|
7
7
|
export type { DatabaseConnectionConfig, DatabaseConnectionOptions } from "./database.options"
|
|
8
|
-
export {
|
|
8
|
+
export { LIST_ROWS_MAX, sql } from "./database.sql"
|
|
9
9
|
export { DATABASE_ERROR_KINDS } from "./errors/database.error"
|
|
10
10
|
export { parsePrimaryDatabaseConfig } from "./primary.config"
|
|
11
11
|
export { InjectPrimaryEntityManager, PRIMARY_ENTITY_MANAGER } from "./primary.decorators"
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export { HTTP_ERROR_KINDS
|
|
1
|
+
export { HTTP_ERROR_KINDS } from "./errors/http.error"
|
|
2
2
|
export { HTTP_MESSAGES } from "./messages/http.messages"
|
|
3
|
-
export { callGraphql } from "./graphql-call.mapper"
|
|
4
|
-
export type { GraphqlAnswer } from "./graphql-call.mapper"
|
|
5
|
-
export { HTTP_CLIENT, InjectHttpClient } from "./http.decorators"
|
|
6
3
|
export { HttpModule } from "./http.module"
|
|
7
|
-
export type { HttpClient } from "./http.port"
|
|
@@ -15,7 +15,9 @@ describe("CorrelationService", () => {
|
|
|
15
15
|
expect(service.fromHeaders({ "x-request-id": "request-1" })).toBe("request-1")
|
|
16
16
|
expect(service.fromHeaders({})).toBe("00000000-0000-4000-8000-000000000001")
|
|
17
17
|
expect(service.create()).toBe("00000000-0000-4000-8000-000000000002")
|
|
18
|
-
expect(service.run("explicit-id", () => stampLogFields({}, "root-id"))).toEqual({
|
|
18
|
+
expect(service.run("explicit-id", () => stampLogFields({}, "root-id"))).toEqual({
|
|
19
|
+
correlationId: "explicit-id",
|
|
20
|
+
})
|
|
19
21
|
expect(createCorrelationRunner(ids).run("bootstrap-id", () => stampLogFields({}, "root-id"))).toEqual({
|
|
20
22
|
correlationId: "bootstrap-id",
|
|
21
23
|
})
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
export { createJsonLogger } from "./json-logger.service"
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
LOGGER,
|
|
5
|
-
CORRELATION_IDS,
|
|
6
|
-
CORRELATION_RUNNER,
|
|
7
|
-
InjectCorrelationIds,
|
|
8
|
-
InjectCorrelationRunner,
|
|
9
|
-
} from "./logging.decorators"
|
|
10
|
-
export { applyCorrelation, correlationMiddleware } from "./correlation-request.policy"
|
|
11
|
-
export type { CorrelationIds, CorrelationRunner } from "./correlation.port"
|
|
12
|
-
export type { CorrelationHeaders, CorrelationRequest } from "./correlation.contracts"
|
|
13
|
-
export { createCorrelationRunner } from "./correlation.service"
|
|
14
|
-
export { isCorrelationId } from "./correlation.policy"
|
|
2
|
+
export { InjectLogger, LOGGER } from "./logging.decorators"
|
|
3
|
+
export { applyCorrelation } from "./correlation-request.policy"
|
|
15
4
|
export { LoggingLogEvent } from "./logging.log-events"
|
|
16
5
|
export { LoggingModule } from "./logging.module"
|
|
17
6
|
export type { Logger } from "./logging.port"
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import { Test } from "@nestjs/testing"
|
|
1
2
|
import { isRecord } from "./record.policy"
|
|
2
3
|
|
|
4
|
+
const RECORD_POLICY: unique symbol = Symbol("primitives.record")
|
|
5
|
+
|
|
3
6
|
describe("isRecord", () => {
|
|
7
|
+
let subject: typeof isRecord
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
const moduleRef = await Test.createTestingModule({
|
|
11
|
+
providers: [{ provide: RECORD_POLICY, useFactory: () => isRecord }],
|
|
12
|
+
}).compile()
|
|
13
|
+
subject = moduleRef.get<typeof isRecord>(RECORD_POLICY)
|
|
14
|
+
})
|
|
15
|
+
|
|
4
16
|
it("narrows non-null objects before provider fields are read", () => {
|
|
5
|
-
expect(
|
|
6
|
-
expect(
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
9
|
-
expect(
|
|
10
|
-
expect(
|
|
17
|
+
expect(subject({ status: 200 })).toBe(true)
|
|
18
|
+
expect(subject([])).toBe(true)
|
|
19
|
+
expect(subject(null)).toBe(false)
|
|
20
|
+
expect(subject(undefined)).toBe(false)
|
|
21
|
+
expect(subject("response")).toBe(false)
|
|
22
|
+
expect(subject(200)).toBe(false)
|
|
11
23
|
})
|
|
12
24
|
})
|
|
@@ -5,4 +5,3 @@ export type { DatabaseConnectionOptions } from "./database.options"
|
|
|
5
5
|
export { PRIMARY_DATA_SOURCE } from "./database.port"
|
|
6
6
|
export { DATABASE_ERROR_KINDS } from "./errors/database.error"
|
|
7
7
|
export { parsePrimaryDatabaseConfig } from "./primary.config"
|
|
8
|
-
export { BATCH_ROWS } from "./database.sql"
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
export { createJsonLogger } from "./json-logger.service"
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
LOGGER,
|
|
5
|
-
CORRELATION_IDS,
|
|
6
|
-
CORRELATION_RUNNER,
|
|
7
|
-
InjectCorrelationIds,
|
|
8
|
-
InjectCorrelationRunner,
|
|
9
|
-
} from "./logging.decorators"
|
|
10
|
-
export { applyCorrelation, correlationMiddleware } from "./correlation-request.policy"
|
|
11
|
-
export type { CorrelationIds, CorrelationRunner } from "./correlation.port"
|
|
12
|
-
export type { CorrelationHeaders, CorrelationRequest } from "./correlation.contracts"
|
|
13
|
-
export { createCorrelationRunner } from "./correlation.service"
|
|
14
|
-
export { isCorrelationId } from "./correlation.policy"
|
|
2
|
+
export { InjectLogger, LOGGER } from "./logging.decorators"
|
|
3
|
+
export { applyCorrelation } from "./correlation-request.policy"
|
|
15
4
|
export { LoggingLogEvent } from "./logging.log-events"
|
|
16
5
|
export { LoggingModule } from "./logging.module"
|
|
17
6
|
export type { Logger } from "./logging.port"
|
|
@@ -21,7 +21,7 @@ export const SignInFormBase = (props: SignInFormBaseProps) => (
|
|
|
21
21
|
<Input id="sign-in-email" name="email" label={props.props.emailLabel} kind="email" isRequired />
|
|
22
22
|
<Input id="sign-in-password" name="password" label={props.props.passwordLabel} kind="password" isRequired />
|
|
23
23
|
{props.props.failure === undefined ? null : <Text live="assertive">{props.props.failure}</Text>}
|
|
24
|
-
<Button type="submit"
|
|
24
|
+
<Button type="submit" intent="commit" isPending={props.state === "working"}>
|
|
25
25
|
{props.props.submitLabel}
|
|
26
26
|
</Button>
|
|
27
27
|
</Form>
|
package/templates/fe/skeleton/apps/__app__/src/components/blocks/SignOutButton/component.tsx
CHANGED
|
@@ -14,7 +14,7 @@ export interface SignOutButtonBaseProps {
|
|
|
14
14
|
export const SignOutButtonBase = (props: SignOutButtonBaseProps) => (
|
|
15
15
|
<>
|
|
16
16
|
<Text>{props.props.principal}</Text>
|
|
17
|
-
<Button
|
|
17
|
+
<Button intent="neutral" isPending={props.props.pending} onPress={props.on.press}>
|
|
18
18
|
{props.props.label}
|
|
19
19
|
</Button>
|
|
20
20
|
</>
|
package/templates/fe/skeleton/apps/__app__/src/features/overlays/AppGuideOverlay/component.tsx
CHANGED
|
@@ -21,7 +21,7 @@ export const AppGuideOverlayBase = (props: AppGuideOverlayBaseProps) => (
|
|
|
21
21
|
title={props.props.title}
|
|
22
22
|
closeLabel={props.props.closeLabel}
|
|
23
23
|
trigger={
|
|
24
|
-
<Button
|
|
24
|
+
<Button intent="neutral" startContent={<Icon />}>
|
|
25
25
|
{props.props.triggerLabel}
|
|
26
26
|
</Button>
|
|
27
27
|
}
|
|
@@ -10,12 +10,12 @@ import type { ReactNode } from "react"
|
|
|
10
10
|
/** The options a status toast takes: HeroUI's, minus the variant the status already names. */
|
|
11
11
|
type StatusToastOptions = Parameters<typeof heroToast.success>[1]
|
|
12
12
|
|
|
13
|
-
/** The one indicator of each status, from the app's one icon set. */
|
|
13
|
+
/** The one indicator of each status, from the app's one icon set; HeroUI's toast variant colours it through currentColor. */
|
|
14
14
|
const INDICATOR: Record<"success" | "danger" | "warning" | "info", ReactNode> = {
|
|
15
|
-
success: <CheckCircleIcon className="size-6
|
|
16
|
-
danger: <XCircleIcon className="size-6
|
|
17
|
-
warning: <ExclamationTriangleIcon className="size-6
|
|
18
|
-
info: <InformationCircleIcon className="size-6
|
|
15
|
+
success: <CheckCircleIcon className="size-6" />,
|
|
16
|
+
danger: <XCircleIcon className="size-6" />,
|
|
17
|
+
warning: <ExclamationTriangleIcon className="size-6" />,
|
|
18
|
+
info: <InformationCircleIcon className="size-6" />,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** The app's toast: HeroUI's imperative toast with the status indicator injected; the region is mounted by the providers. */
|
|
@@ -17,7 +17,7 @@ export const LandingPageBase = (props: LandingPageBaseProps) => (
|
|
|
17
17
|
<>
|
|
18
18
|
<Heading level={1}>{props.props.title}</Heading>
|
|
19
19
|
<Text tone="muted">{props.props.lede}</Text>
|
|
20
|
-
<Button href={props.props.appHref}
|
|
20
|
+
<Button href={props.props.appHref} intent="commit">
|
|
21
21
|
{props.props.openApp}
|
|
22
22
|
</Button>
|
|
23
23
|
</>
|
package/templates/fe/skeleton/packages/__project__-ui/src/composites/SiteShell/classNames.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The shell's frame: a full-height column
|
|
1
|
+
/** The shell's frame: a full-height column; colours come from Grammar's root. */
|
|
2
2
|
export const siteShellClassNames = {
|
|
3
|
-
frame: "flex min-h-screen flex-col
|
|
3
|
+
frame: "flex min-h-screen flex-col",
|
|
4
4
|
} as const
|
|
@@ -14,6 +14,6 @@ type SiteShellProps = {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The document chrome both apps share: Grammar's Common boundary, the brand header (the top bar carrying the wordmark that links
|
|
17
|
-
* home), then the routed body in the shell's main landmark at reading measure.
|
|
17
|
+
* home), then the routed body in the shell's main landmark at reading measure.
|
|
18
18
|
*/
|
|
19
19
|
{{> fe/common/site-shell.tsx.partial}}
|
package/templates/fe/skeleton-lite/apps/web/src/components/composites/SiteShell/classNames.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The shell's frame: a full-height column
|
|
1
|
+
/** The shell's frame: a full-height column; colours come from Grammar's root. */
|
|
2
2
|
export const siteShellClassNames = {
|
|
3
|
-
frame: "flex min-h-screen flex-col
|
|
3
|
+
frame: "flex min-h-screen flex-col",
|
|
4
4
|
} as const
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Test } from "@nestjs/testing"
|
|
2
|
-
import { mock } from "@starci/jest-preset"
|
|
3
|
-
import type { HttpClient } from "./http.port"
|
|
4
|
-
import { callGraphql } from "./graphql-call.mapper"
|
|
5
|
-
|
|
6
|
-
const SUBJECT: unique symbol = Symbol("http/graphql-call.mapper")
|
|
7
|
-
const subjectFunctions = () => ({ callGraphql })
|
|
8
|
-
|
|
9
|
-
const build = async () => {
|
|
10
|
-
const moduleRef = await Test.createTestingModule({
|
|
11
|
-
providers: [{ provide: SUBJECT, useFactory: subjectFunctions }],
|
|
12
|
-
}).compile()
|
|
13
|
-
return moduleRef.get<ReturnType<typeof subjectFunctions>>(SUBJECT)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("callGraphql", () => {
|
|
17
|
-
it("sends the operation and reads its data and string error codes", async () => {
|
|
18
|
-
const subject = await build()
|
|
19
|
-
|
|
20
|
-
const http = mock<HttpClient>()
|
|
21
|
-
http.request.mockResolvedValue({
|
|
22
|
-
status: 200,
|
|
23
|
-
body: {
|
|
24
|
-
data: { order: { id: "order-1" } },
|
|
25
|
-
errors: [
|
|
26
|
-
{ extensions: { code: "ORDER_STALE" } },
|
|
27
|
-
{ extensions: { code: 7 } },
|
|
28
|
-
{ extensions: null },
|
|
29
|
-
"malformed",
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
await expect(
|
|
35
|
-
subject.callGraphql(http, {
|
|
36
|
-
correlationId: "request-1",
|
|
37
|
-
url: "https://order.test/graphql",
|
|
38
|
-
query: "query Order($id: ID!) { order(id: $id) { id } }",
|
|
39
|
-
variables: { id: "order-1" },
|
|
40
|
-
headers: { authorization: "Bearer token" },
|
|
41
|
-
timeoutMs: 2500,
|
|
42
|
-
}),
|
|
43
|
-
).resolves.toEqual({ data: { order: { id: "order-1" } }, errorCodes: ["ORDER_STALE"] })
|
|
44
|
-
|
|
45
|
-
expect(http.request).toHaveBeenCalledWith({
|
|
46
|
-
correlationId: "request-1",
|
|
47
|
-
method: "POST",
|
|
48
|
-
url: "https://order.test/graphql",
|
|
49
|
-
headers: { authorization: "Bearer token" },
|
|
50
|
-
body: {
|
|
51
|
-
query: "query Order($id: ID!) { order(id: $id) { id } }",
|
|
52
|
-
variables: { id: "order-1" },
|
|
53
|
-
},
|
|
54
|
-
timeoutMs: 2500,
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it("returns an empty answer when data and errors do not have GraphQL shapes", async () => {
|
|
59
|
-
const subject = await build()
|
|
60
|
-
|
|
61
|
-
const http = mock<HttpClient>()
|
|
62
|
-
http.request.mockResolvedValue({ status: 200, body: { data: "malformed", errors: {} } })
|
|
63
|
-
|
|
64
|
-
await expect(
|
|
65
|
-
subject.callGraphql(http, {
|
|
66
|
-
correlationId: "request-1",
|
|
67
|
-
url: "https://order.test/graphql",
|
|
68
|
-
query: "query Health { health }",
|
|
69
|
-
timeoutMs: 1000,
|
|
70
|
-
}),
|
|
71
|
-
).resolves.toEqual({ data: undefined, errorCodes: [] })
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it.each([undefined, null, "not a response"])(
|
|
75
|
-
"returns null when the response body is not an object (%p)",
|
|
76
|
-
async (body) => {
|
|
77
|
-
const subject = await build()
|
|
78
|
-
|
|
79
|
-
const http = mock<HttpClient>()
|
|
80
|
-
http.request.mockResolvedValue({ status: 502, body })
|
|
81
|
-
|
|
82
|
-
await expect(
|
|
83
|
-
subject.callGraphql(http, {
|
|
84
|
-
correlationId: "request-1",
|
|
85
|
-
url: "https://order.test/graphql",
|
|
86
|
-
query: "query Health { health }",
|
|
87
|
-
timeoutMs: 1000,
|
|
88
|
-
}),
|
|
89
|
-
).resolves.toBeNull()
|
|
90
|
-
},
|
|
91
|
-
)
|
|
92
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { isRecord } from "@modules/platform/primitives"
|
|
2
|
-
import type { HttpClient } from "./http.port"
|
|
3
|
-
|
|
4
|
-
/** One GraphQL operation sent to another service. */
|
|
5
|
-
export interface GraphqlCall {
|
|
6
|
-
/** The correlation id of the request or delivery causing this operation. */
|
|
7
|
-
readonly correlationId: string
|
|
8
|
-
/** The GraphQL endpoint URL. */
|
|
9
|
-
readonly url: string
|
|
10
|
-
/** The operation text. */
|
|
11
|
-
readonly query: string
|
|
12
|
-
/** The operation variables. */
|
|
13
|
-
readonly variables?: Readonly<Record<string, unknown>>
|
|
14
|
-
/** Extra request headers, such as the bearer token to forward. */
|
|
15
|
-
readonly headers?: Readonly<Record<string, string>>
|
|
16
|
-
/** How long to wait for the answer. */
|
|
17
|
-
readonly timeoutMs: number
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** What a GraphQL service answered: the data object and the codes of the errors it reported. */
|
|
21
|
-
export interface GraphqlAnswer {
|
|
22
|
-
/** The `data` object, undefined when the operation failed before producing one. */
|
|
23
|
-
readonly data: Readonly<Record<string, unknown>> | undefined
|
|
24
|
-
/** The `extensions.code` of every reported error. */
|
|
25
|
-
readonly errorCodes: ReadonlyArray<string>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** What a GraphQL call yields: the answer, or null when the body is not a GraphQL response at all. */
|
|
29
|
-
export type GraphqlCallResult = GraphqlAnswer | null
|
|
30
|
-
|
|
31
|
-
const codesOf = (errors: unknown): Array<string> =>
|
|
32
|
-
Array.isArray(errors)
|
|
33
|
-
? errors.flatMap((error): Array<string> => {
|
|
34
|
-
const code: unknown = isRecord(error) && isRecord(error.extensions) ? error.extensions.code : undefined
|
|
35
|
-
return typeof code === "string" ? [code] : []
|
|
36
|
-
})
|
|
37
|
-
: []
|
|
38
|
-
|
|
39
|
-
/** Sends a GraphQL operation and reads the answer; null when the body is not a GraphQL response at all. */
|
|
40
|
-
export const callGraphql = async (http: HttpClient, call: GraphqlCall): Promise<GraphqlCallResult> => {
|
|
41
|
-
const response = await http.request({
|
|
42
|
-
correlationId: call.correlationId,
|
|
43
|
-
method: "POST",
|
|
44
|
-
url: call.url,
|
|
45
|
-
...(call.headers === undefined ? {} : { headers: call.headers }),
|
|
46
|
-
body: { query: call.query, variables: call.variables },
|
|
47
|
-
timeoutMs: call.timeoutMs,
|
|
48
|
-
})
|
|
49
|
-
const body = response.body
|
|
50
|
-
if (!isRecord(body)) return null
|
|
51
|
-
return { data: isRecord(body.data) ? body.data : undefined, errorCodes: codesOf(body.errors) }
|
|
52
|
-
}
|