@cratis/pi 8.5.0 → 8.7.0
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/package/corpus/harnesses/copilot/instructions/glossary.instructions.md +5 -3
- package/package/corpus/harnesses/copilot/instructions/react.instructions.md +3 -1
- package/package/corpus/harnesses/copilot/instructions/reactors.instructions.md +3 -1
- package/package/corpus/harnesses/copilot/instructions/specs.csharp.instructions.md +6 -3
- package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +5 -2
- package/package/corpus/rules/glossary.md +5 -3
- package/package/corpus/rules/react.md +3 -1
- package/package/corpus/rules/reactors.md +3 -1
- package/package/corpus/rules/specs.csharp.md +6 -3
- package/package/corpus/rules/vertical-slices.md +5 -2
- package/package/corpus/skills/cratis-application-growth/SKILL.md +1 -2
- package/package/corpus/skills/cratis-application-growth/references/csharp.md +0 -2
- package/package/corpus/skills/cratis-application-growth/references/move-and-untangle.md +1 -2
- package/package/corpus/skills/cratis-application-growth/references/rename-window.md +1 -3
- package/package/corpus/skills/cratis-application-growth/references/service-and-delivery.md +3 -2
- package/package/corpus/skills/cratis-application-growth/references/stages.md +2 -2
- package/package/corpus/skills/cratis-arc-authorize-request/SKILL.md +2 -2
- package/package/corpus/skills/cratis-arc-authorize-request/references/authproxy.md +19 -0
- package/package/corpus/skills/cratis-arc-authorize-request/references/csharp-query-security.md +15 -0
- package/package/corpus/skills/cratis-arc-authorize-request/references/csharp.md +12 -3
- package/package/corpus/skills/cratis-arc-declare-command/SKILL.md +2 -0
- package/package/corpus/skills/cratis-arc-declare-command/references/csharp-chronicle.md +46 -7
- package/package/corpus/skills/cratis-arc-declare-command/references/csharp-controller.md +3 -1
- package/package/corpus/skills/cratis-arc-declare-command/references/csharp-history.md +4 -1
- package/package/corpus/skills/cratis-arc-declare-command/references/csharp.md +31 -4
- package/package/corpus/skills/cratis-arc-declare-command/references/go.md +1 -1
- package/package/corpus/skills/cratis-arc-diagnose-live-query/references/csharp.md +24 -2
- package/package/corpus/skills/cratis-arc-expose-mcp-operation/references/csharp.md +49 -0
- package/package/corpus/skills/cratis-arc-expose-query/SKILL.md +3 -1
- package/package/corpus/skills/cratis-arc-expose-query/references/csharp.md +27 -4
- package/package/corpus/skills/cratis-arc-generate-proxies/SKILL.md +1 -0
- package/package/corpus/skills/cratis-arc-generate-proxies/references/csharp.md +49 -2
- package/package/corpus/skills/cratis-arc-generate-proxies/references/typescript.md +9 -0
- package/package/corpus/skills/cratis-arc-host-application/SKILL.md +1 -1
- package/package/corpus/skills/cratis-arc-host-application/references/csharp-configuration.md +54 -0
- package/package/corpus/skills/cratis-arc-host-application/references/csharp-deployment.md +98 -0
- package/package/corpus/skills/cratis-arc-host-application/references/csharp-http.md +9 -1
- package/package/corpus/skills/cratis-arc-host-application/references/csharp-identity.md +84 -2
- package/package/corpus/skills/cratis-arc-host-application/references/csharp.md +2 -0
- package/package/corpus/skills/cratis-arc-invoke-command/references/csharp.md +2 -1
- package/package/corpus/skills/cratis-arc-isolate-tenant/SKILL.md +18 -1
- package/package/corpus/skills/cratis-arc-page-query/references/csharp.md +2 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/SKILL.md +18 -16
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-commands.md +8 -3
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-host.md +84 -16
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-identity.md +22 -2
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-instant-feedback.md +81 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-localization.md +80 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-navigation.md +103 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-queries.md +40 -1
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-structure.md +117 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript.md +7 -3
- package/package/corpus/skills/cratis-arc-react-separate-view-model/SKILL.md +3 -3
- package/package/corpus/skills/cratis-arc-react-separate-view-model/references/typescript.md +27 -6
- package/package/corpus/skills/cratis-arc-validate-command/references/csharp-rules.md +23 -2
- package/package/corpus/skills/cratis-arc-validate-command/references/csharp.md +28 -2
- package/package/corpus/skills/cratis-authproxy-configure/SKILL.md +136 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/admission.md +125 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/aspire.md +154 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/operations.md +122 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/services-and-routing.md +114 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/sessions-and-logout.md +126 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/sign-in-providers.md +116 -0
- package/package/corpus/skills/cratis-authproxy-configure/references/tenant-resolution.md +135 -0
- package/package/corpus/skills/cratis-choreography-run-workflow/SKILL.md +117 -0
- package/package/corpus/skills/cratis-choreography-run-workflow/references/csharp-chronicle.md +164 -0
- package/package/corpus/skills/cratis-choreography-run-workflow/references/csharp.md +354 -0
- package/package/corpus/skills/cratis-chronicle-cli-operations/SKILL.md +2 -2
- package/package/corpus/skills/cratis-chronicle-cli-operations/references/project-tooling.md +28 -0
- package/package/corpus/skills/cratis-chronicle-connect-application/references/csharp-services.md +13 -2
- package/package/corpus/skills/cratis-chronicle-connect-application/references/csharp.md +12 -0
- package/package/corpus/skills/cratis-chronicle-connect-application/references/kotlin.md +2 -0
- package/package/corpus/skills/cratis-chronicle-connect-application/references/typescript.md +10 -1
- package/package/corpus/skills/cratis-chronicle-constrain-append/SKILL.md +8 -1
- package/package/corpus/skills/cratis-chronicle-constrain-append/references/csharp.md +35 -3
- package/package/corpus/skills/cratis-chronicle-constrain-append/references/go.md +1 -1
- package/package/corpus/skills/cratis-chronicle-constrain-append/references/operations.md +70 -0
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/SKILL.md +2 -0
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/configuration.md +27 -0
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/container-and-kubernetes.md +293 -0
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/kernel-options.md +13 -6
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/network-and-tls.md +45 -0
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/storage.md +91 -1
- package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/upgrade-and-recovery.md +9 -0
- package/package/corpus/skills/cratis-chronicle-evolve-event/SKILL.md +12 -0
- package/package/corpus/skills/cratis-chronicle-inspect-observer/SKILL.md +11 -1
- package/package/corpus/skills/cratis-chronicle-inspect-observer/references/csharp.md +1 -1
- package/package/corpus/skills/cratis-chronicle-project-view/SKILL.md +1 -1
- package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-fluent.md +14 -3
- package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-model-bound.md +3 -0
- package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-reading.md +3 -2
- package/package/corpus/skills/cratis-chronicle-project-view/references/csharp.md +23 -0
- package/package/corpus/skills/cratis-chronicle-project-view/references/elixir.md +1 -0
- package/package/corpus/skills/cratis-chronicle-project-view/references/go.md +2 -1
- package/package/corpus/skills/cratis-chronicle-project-view/references/java.md +2 -0
- package/package/corpus/skills/cratis-chronicle-project-view/references/kotlin.md +1 -0
- package/package/corpus/skills/cratis-chronicle-project-view/references/typescript.md +1 -1
- package/package/corpus/skills/cratis-chronicle-protect-decision/SKILL.md +2 -0
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/csharp-scopes.md +40 -3
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/csharp.md +20 -2
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/elixir.md +7 -0
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/go.md +9 -1
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/java.md +8 -0
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/kotlin.md +9 -0
- package/package/corpus/skills/cratis-chronicle-protect-decision/references/typescript.md +7 -0
- package/package/corpus/skills/cratis-chronicle-protect-personal-data/references/csharp.md +24 -1
- package/package/corpus/skills/cratis-chronicle-publish-contract/SKILL.md +1 -1
- package/package/corpus/skills/cratis-chronicle-publish-contract/references/csharp.md +41 -0
- package/package/corpus/skills/cratis-chronicle-publish-contract/references/webhook-signature-wire-format.md +82 -0
- package/package/corpus/skills/cratis-chronicle-react-to-fact/SKILL.md +17 -0
- package/package/corpus/skills/cratis-chronicle-react-to-fact/references/csharp-outputs.md +3 -1
- package/package/corpus/skills/cratis-chronicle-react-to-fact/references/csharp.md +35 -2
- package/package/corpus/skills/cratis-chronicle-react-to-fact/references/elixir.md +11 -0
- package/package/corpus/skills/cratis-chronicle-react-to-fact/references/java.md +1 -0
- package/package/corpus/skills/cratis-chronicle-react-to-fact/references/kotlin.md +1 -0
- package/package/corpus/skills/cratis-chronicle-record-event/SKILL.md +1 -1
- package/package/corpus/skills/cratis-chronicle-record-event/references/csharp-coordination.md +31 -2
- package/package/corpus/skills/cratis-chronicle-record-event/references/csharp-history.md +21 -4
- package/package/corpus/skills/cratis-chronicle-record-event/references/csharp.md +20 -2
- package/package/corpus/skills/cratis-chronicle-record-event/references/go.md +1 -1
- package/package/corpus/skills/cratis-chronicle-record-event/references/java.md +1 -1
- package/package/corpus/skills/cratis-chronicle-record-event/references/kotlin.md +3 -0
- package/package/corpus/skills/cratis-chronicle-reduce-state/SKILL.md +2 -1
- package/package/corpus/skills/cratis-chronicle-reduce-state/references/csharp.md +3 -1
- package/package/corpus/skills/cratis-chronicle-reduce-state/references/java.md +10 -1
- package/package/corpus/skills/cratis-chronicle-reduce-state/references/kotlin.md +10 -1
- package/package/corpus/skills/cratis-chronicle-reduce-state/references/typescript.md +27 -5
- package/package/corpus/skills/cratis-chronicle-select-client/SKILL.md +18 -0
- package/package/corpus/skills/cratis-chronicle-select-client/references/elixir.md +21 -1
- package/package/corpus/skills/cratis-chronicle-select-client/references/go.md +13 -0
- package/package/corpus/skills/cratis-chronicle-select-client/references/java.md +15 -0
- package/package/corpus/skills/cratis-chronicle-select-client/references/kotlin.md +15 -0
- package/package/corpus/skills/cratis-chronicle-select-client/references/typescript.md +16 -0
- package/package/corpus/skills/cratis-code-review/references/csharp-diagnostics.md +28 -2
- package/package/corpus/skills/cratis-code-review/references/csharp.md +1 -1
- package/package/corpus/skills/cratis-components-accessibility/SKILL.md +6 -8
- package/package/corpus/skills/cratis-components-accessibility/references/typescript.md +32 -14
- package/package/corpus/skills/cratis-components-build-canvas/SKILL.md +4 -3
- package/package/corpus/skills/cratis-components-build-canvas/references/typescript-props.md +1 -1
- package/package/corpus/skills/cratis-components-build-canvas/references/typescript.md +4 -2
- package/package/corpus/skills/cratis-components-choose-control/SKILL.md +13 -7
- package/package/corpus/skills/cratis-components-choose-control/references/from-primereact.md +116 -0
- package/package/corpus/skills/cratis-components-choose-control/references/menu.md +90 -0
- package/package/corpus/skills/cratis-components-choose-control/references/typescript-composition.md +48 -0
- package/package/corpus/skills/cratis-components-choose-control/references/typescript.md +2 -2
- package/package/corpus/skills/cratis-components-compose-toolbar/SKILL.md +2 -1
- package/package/corpus/skills/cratis-components-compose-toolbar/references/floating-toolbar.md +146 -0
- package/package/corpus/skills/cratis-components-diagnose-screen/SKILL.md +102 -0
- package/package/corpus/skills/cratis-components-display-list/SKILL.md +10 -10
- package/package/corpus/skills/cratis-components-display-list/references/typescript-custom-panel.md +74 -0
- package/package/corpus/skills/cratis-components-display-list/references/typescript-datatables.md +2 -7
- package/package/corpus/skills/cratis-components-display-list/references/typescript.md +3 -2
- package/package/corpus/skills/cratis-components-submit-form/references/typescript-commandform.md +72 -2
- package/package/corpus/skills/cratis-components-submit-form/references/typescript.md +5 -3
- package/package/corpus/skills/cratis-components-theme-application/SKILL.md +17 -15
- package/package/corpus/skills/cratis-components-theme-application/references/localization.md +166 -0
- package/package/corpus/skills/cratis-components-theme-application/references/typescript.md +18 -14
- package/package/corpus/skills/cratis-components-theme-application/references/upgrade-from-previous-major.md +141 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/SKILL.md +2 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp-domain-philosophy.md +31 -3
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp-fundamentals-helpers.md +119 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp.md +4 -0
- package/package/corpus/skills/cratis-fundamentals-concept/references/csharp-serialization.md +70 -0
- package/package/corpus/skills/cratis-fundamentals-concept/references/csharp.md +8 -0
- package/package/corpus/skills/cratis-fundamentals-concept/references/go.md +1 -0
- package/package/corpus/skills/cratis-fundamentals-concept/references/typescript-serialization.md +33 -0
- package/package/corpus/skills/cratis-fundamentals-name-value/references/csharp.md +2 -1
- package/package/corpus/skills/cratis-fundamentals-type-discovery/references/csharp-diagnostics.md +5 -0
- package/package/corpus/skills/cratis-fundamentals-type-discovery/references/go-dependency-injection.md +3 -0
- package/package/corpus/skills/cratis-modeling-design-event-model/SKILL.md +6 -4
- package/package/corpus/skills/cratis-modeling-design-event-model/references/command-inventory.md +7 -1
- package/package/corpus/skills/cratis-modeling-design-event-model/references/model-first.md +13 -1
- package/package/corpus/skills/cratis-modeling-design-event-model/references/review-one-slice.md +6 -0
- package/package/corpus/skills/cratis-multi-service-local-orchestration/SKILL.md +6 -6
- package/package/corpus/skills/cratis-multi-service-local-orchestration/references/csharp-aspire.md +116 -28
- package/package/corpus/skills/cratis-multi-service-local-orchestration/references/docker-compose.md +2 -2
- package/package/corpus/skills/cratis-observability/references/chronicle-kernel-export.md +46 -0
- package/package/corpus/skills/cratis-orleans-jobs/SKILL.md +4 -2
- package/package/corpus/skills/cratis-platform-build-application/SKILL.md +8 -0
- package/package/corpus/skills/cratis-platform-build-application/references/cratis-identity.md +71 -0
- package/package/corpus/skills/cratis-platform-build-application/references/studio-repository.md +96 -0
- package/package/corpus/skills/cratis-platform-deliver-slice/SKILL.md +14 -8
- package/package/corpus/skills/cratis-platform-deliver-slice/references/csharp.md +167 -3
- package/package/corpus/skills/cratis-platform-deliver-slice/references/eventual-consistency.md +150 -0
- package/package/corpus/skills/cratis-platform-diagnose-slice/SKILL.md +1 -1
- package/package/corpus/skills/cratis-platform-start-application/SKILL.md +21 -0
- package/package/corpus/skills/cratis-platform-start-application/references/csharp.md +77 -3
- package/package/corpus/skills/cratis-platform-upgrade-application/SKILL.md +118 -0
- package/package/corpus/skills/cratis-platform-upgrade-application/references/csharp.md +117 -0
- package/package/corpus/skills/cratis-platform-upgrade-application/references/java.md +53 -0
- package/package/corpus/skills/cratis-platform-upgrade-application/references/kotlin.md +53 -0
- package/package/corpus/skills/cratis-platform-upgrade-application/references/typescript.md +71 -0
- package/package/corpus/skills/cratis-screenplay-accept-model/references/csharp.md +29 -0
- package/package/corpus/skills/cratis-screenplay-accept-model/references/read-the-evidence.md +82 -1
- package/package/corpus/skills/cratis-screenplay-declare-slice/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-declare-slice/references/structure-and-imports.md +10 -0
- package/package/corpus/skills/cratis-screenplay-onboard-workspace/SKILL.md +5 -4
- package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/cli.md +19 -2
- package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/smallest-model.md +87 -0
- package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/typescript.md +13 -0
- package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/workspace-mcp.md +5 -0
- package/package/corpus/skills/cratis-specifications-exercise-backend/SKILL.md +2 -0
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-colocated.md +101 -0
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-command-results.md +3 -1
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-decision-reads.md +1 -0
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-events.md +1 -0
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-integration.md +4 -2
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-reactors.md +3 -3
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp.md +34 -1
- package/package/corpus/skills/cratis-specifications-exercise-backend/references/elixir.md +2 -0
- package/package/corpus/skills/cratis-specifications-isolate-behavior/SKILL.md +1 -1
- package/package/corpus/skills/cratis-specifications-isolate-behavior/references/csharp-running.md +10 -3
- package/package/corpus/skills/cratis-specifications-test-application-ui/references/typescript.md +22 -4
- package/package/corpus/skills/cratis-specifications-test-typescript-behavior/SKILL.md +2 -1
- package/package/corpus/skills/cratis-specifications-test-typescript-behavior/references/typescript.md +40 -0
- package/package/profile-catalog.json +15 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cratis-arc-react-bind-slice
|
|
3
|
-
description: Use when a developer mounts the Arc React host, binds a generated query or command proxy in a React component, coordinates several command editors with one Save/Discard (CommandScope), or reads identity, availability or slice context in React, including folder-derived slice locations from the Arc Vite SliceLocationPlugin. Not for a standard table (use cratis-components-display-list), a form that collects command input (use cratis-components-submit-form), view-model classes (use cratis-arc-react-separate-view-model) or producing the proxies (use cratis-arc-generate-proxies).
|
|
3
|
+
description: Use when a developer mounts the Arc React host, binds a generated query or command proxy in a React component, sets the UI language (locale, translations) of a React application, coordinates several command editors with one Save/Discard (CommandScope), or reads identity, availability or slice context in React, including folder-derived slice locations from the Arc Vite SliceLocationPlugin. Not for a standard table (use cratis-components-display-list), a form that collects command input (use cratis-components-submit-form), view-model classes (use cratis-arc-react-separate-view-model) or producing the proxies (use cratis-arc-generate-proxies).
|
|
4
4
|
compatibility: Requires react, react-dom, reflect-metadata, @cratis/arc, @cratis/arc.react and @cratis/fundamentals, plus proxies generated for React.
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -24,7 +24,7 @@ Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Nod
|
|
|
24
24
|
|
|
25
25
|
## When to use it
|
|
26
26
|
|
|
27
|
-
- Hand-written binding: a custom view, a live dashboard, a command
|
|
27
|
+
- Hand-written binding: a custom view, a live dashboard, a button command with known inputs, a page-level save bar.
|
|
28
28
|
- Prefer a Components surface when one fits: `cratis-components-display-list` for a query-backed table, `cratis-components-submit-form` for a form or dialog collecting command input. Never also call the hook for a query such a surface binds.
|
|
29
29
|
- Move presentation logic or collaborators into a class with `cratis-arc-react-separate-view-model`.
|
|
30
30
|
|
|
@@ -36,17 +36,18 @@ Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Nod
|
|
|
36
36
|
- **Delta transfer.** By default a shared-hub subscription asks for an initial snapshot, then only changes, applied by the ordinary hook; direct mode and Polling are outside this. Changes need items with an `Id` property: the .NET backend sends a full snapshot on every change for a collection whose items have none, and for a sorted or paged collection when a change would reorder it.
|
|
37
37
|
- **Arguments are checked before sending.** If the query's client validator reports a finding, Arc returns a ready, invalid result without sending the query; any finding blocks, even one with `withSeverity` Warning or Information (only commands filter by allowed severity). A missing required argument is a separate skip: nothing is sent and an observable hook never subscribes, so gate it with `when`.
|
|
38
38
|
- **Commands are independent instances**, stable across renders, with the host's settings, change tracking against initial values, and registration in the nearest command scope. Expected failures come back as a failed result rather than an exception: a refusal, an unknown route, a network failure and an unreadable response. The last three have `hasExceptions` true and `isRetryable` false. Execution can still reject on an unexpected error (such as a throwing headers callback), so branch on the result and also keep a `catch`.
|
|
39
|
-
- **Reads catch up after writes.** Success means the write was accepted; the read model updates
|
|
39
|
+
- **Reads catch up after writes.** Success means the write was accepted; the read model updates once the event is processed (no upper bound: never wait a fixed time) and an observable query pushes it. After a create, a record screen's ready result without data is pending, not missing (`cratis-platform-deliver-slice`). Nothing refreshes a snapshot query (neither the command nor a command scope): call its `perform()` after success; it may lag. Prefer an observable query for data the screen's own commands change.
|
|
40
40
|
- **Headers are read per request; caches keep the old caller.** Cached results, open live connections and the identity stay the previous caller's until you update the identity and reconnect (see Identity).
|
|
41
41
|
|
|
42
42
|
## Default path
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
0. Place the screen and mount it from the feature's composition page: structure (`references/typescript-structure.md`), routes (`references/typescript-navigation.md`).
|
|
45
|
+
1. Import the decorator-metadata polyfill first in the entry module, then mount the Arc host once; inside it, in order: Components provider, `DialogComponents`, MVVM provider, router.
|
|
45
46
|
2. In the component that shows data, call the generated query's ordinary hook on every render, with `when(condition)` while a required argument is unknown. Branch on the result in Result state order (see Query hooks in your language reference).
|
|
46
47
|
3. For an action whose inputs are known, call the generated command's hook, set values through its setter, execute, and classify the result in Command result order (see Commands in your language reference).
|
|
47
48
|
4. Let the query, not the command, update what is shown.
|
|
48
49
|
|
|
49
|
-
For a screen specified in an accepted model (`cratis-screenplay-accept-model`), follow [
|
|
50
|
+
For a screen specified in an accepted model (`cratis-screenplay-accept-model`), follow [this guide](references/react-screen-from-model.md).
|
|
50
51
|
|
|
51
52
|
## Capability catalog
|
|
52
53
|
|
|
@@ -57,7 +58,8 @@ For a screen specified in an accepted model (`cratis-screenplay-accept-model`),
|
|
|
57
58
|
| `microservice` | Backend service the requests address, when an ingress routes by service. |
|
|
58
59
|
| `apiBasePath` | Prefix before every Arc request when served under a sub-path; never repeat the route's `/api`. |
|
|
59
60
|
| `origin` | Backend on another origin. |
|
|
60
|
-
| `
|
|
61
|
+
| `locale` | UI language, sent as `Accept-Language` (details: `references/typescript-localization.md`). |
|
|
62
|
+
| `httpHeadersCallback` | Extra headers (tenant, bearer), read per request; never `Accept-Language`. Event streams and WebSockets carry none, so authenticate live queries with cookies, an `eventSourceFactory` or Polling (see Request configuration in your language reference). Keep the function stable. |
|
|
61
63
|
| `development` | Defers view-model disposal so StrictMode remounts keep their instance. |
|
|
62
64
|
| `detailsType` | Prefer the generated class whose decorated fields type the identity's application details. |
|
|
63
65
|
| `queryTransportMethod` | Server-sent events through a shared hub (default), WebSocket, or Polling (only when long-lived connections are cut or the backend scales to zero; it lags by the interval). |
|
|
@@ -81,12 +83,12 @@ From the Arc context, `reconnectQueries()` drops every cached result (ordinary a
|
|
|
81
83
|
| `useWithPaging(pageSize, args?, sorting?)` | collection queries | the `use` tuple plus setPage, setPageSize | The server pages the collection; never slice on the client. |
|
|
82
84
|
| `useSuspense(...)` | every query | same tuple as `use` | Suspend while loading and throw on failure, under a query boundary. |
|
|
83
85
|
| `useSuspenseWithPaging(pageSize, ...)` | collection queries | same tuple as `useWithPaging` | Paged and suspending. |
|
|
84
|
-
| `useChangeStream(args?, getKey?, sorting?)` | observable collection queries | a change set: added, replaced, removed | Sync an external collection (canvas, map layer)
|
|
85
|
-
| `when(condition)` then any hook above except the change stream | every query | same tuples | Hold the query until a condition holds
|
|
86
|
+
| `useChangeStream(args?, getKey?, sorting?)` | observable collection queries | a change set: added, replaced, removed | Sync an external collection (canvas, map layer). |
|
|
87
|
+
| `when(condition)` then any hook above except the change stream | every query | same tuples | Hold the query until a condition holds. |
|
|
86
88
|
|
|
87
89
|
- A query without parameters takes no `args` on its own hooks; through `when`, arguments always come first.
|
|
88
90
|
- **Proxy members:** `sortBy` (collection queries) has ascending and descending per model property, for initial sorting or `setSorting`. `part` and `sliceLocation`, where emitted, identify it for availability and slice context. `route`, `roles` and `defaultValue` describe it.
|
|
89
|
-
- **Paging:** `setPage` is zero-based. `result.paging` reports `page`, `size`, `totalItems` and `totalPages`.
|
|
91
|
+
- **Paging:** `setPage` is zero-based. `result.paging` reports `page`, `size`, `totalItems` and `totalPages`.
|
|
90
92
|
- **`perform(args?, options?)`** re-runs a snapshot query (the hook's arguments when none are passed); `options.timeoutMs` is a deadline for that run, after which the result is ready, unsuccessful and has exceptions.
|
|
91
93
|
- **Raw hooks** (`useQuery`, `useObservableQuery`, their paging and suspense variants, `useChangeStream`) take the query class first; `useQuery` and `useQueryWithPaging` also accept `{ isEnabled, timeoutMs }`, for a hook-level deadline. There is no paged change stream.
|
|
92
94
|
- **Disabled (`when(false)`)**: the hook returns the empty default, ready, though nothing ran; a single-item default is an empty object, so check the condition before `hasData`. A called `perform` still runs. `when` is not authorization.
|
|
@@ -117,7 +119,7 @@ The result has `data` and flags. Check in this order; stop at the first that app
|
|
|
117
119
|
- **`use(initialValues?)`** returns the command, a values setter and a values clearer. Initial values become the draft and baseline once (key the editor by record identity). Use the setter in input handlers: it re-renders, while direct assignment re-renders only when `hasChanges` flips. The clearer unsets every property.
|
|
118
120
|
- **Instance:** `execute()` sends it; success makes the submitted values the baseline, so edits made during the request stay changes. `validate()` runs server authorization and validation without executing; `validateClientSide()` runs local rules only. `hasChanges`, `setInitialValues(values)`, `revertChanges()` and `clear()` manage the draft; `setInitialValuesFromCurrentValues()` deliberately accepts the current draft, never as a post-save step. `route`, `roles`, `part`, `sliceLocation` (where emitted) and `propertyDescriptors` describe it.
|
|
119
121
|
- **Severity override:** `execute(allowedSeverity, ignoreWarnings)` for "save anyway": execute allowing Information; when only warnings fail, confirm and execute allowing Warning. Generated and server blocking-severity policies cannot be relaxed this way.
|
|
120
|
-
-
|
|
122
|
+
- Use the hook. `new` a command only outside React or per overlapping gesture (instant feedback): process-wide settings, no host `locale`, no scope.
|
|
121
123
|
- **Required inputs:** an unset non-optional property fails client validation (reason `rule`, detail `Required`) and nothing is sent. The hook creates no identifiers.
|
|
122
124
|
|
|
123
125
|
### Command result
|
|
@@ -128,7 +130,7 @@ Classify a refusal in this order: suspended, not available, unauthorized, missin
|
|
|
128
130
|
|
|
129
131
|
### Command scope
|
|
130
132
|
|
|
131
|
-
`CommandScope` gathers the commands created below it into one save bar
|
|
133
|
+
`CommandScope` gathers the commands created below it into one save bar. Props: `setHasChanges`, `setIsPerforming`, and per-command callbacks for executions the scope runs: `onBeforeExecute`, `onSuccess`, `onFailed`, `onException`, `onUnauthorized`, `onValidationFailure`. `useCommandScope()` gives `hasChanges`, `isPerforming`, `hasValidationFailures`, `hasExceptions`, `validationFailures`, `exceptions`, `aggregatedValidationFailures`, `aggregatedExceptions`, `execute()` and `revertChanges()`.
|
|
132
134
|
|
|
133
135
|
`execute()` runs the scope's own changed commands in sequence; child scopes add only failures and exceptions to the aggregates. It is not a transaction (a failure neither stops nor rolls back the others; report partial saves) and refreshes no query. `revertChanges()` does not re-render inputs; reset each editor through its setter.
|
|
134
136
|
|
|
@@ -136,7 +138,7 @@ Classify a refusal in this order: suspended, not available, unauthorized, missin
|
|
|
136
138
|
|
|
137
139
|
`useIdentity()`: `id`, `name`, `roles`, `details` (typed through `detailsType` or a type argument; may be absent), `isSet`, `isLoading`, `isInRole(role)`, `refresh()`, `clearIdentity()`.
|
|
138
140
|
|
|
139
|
-
When credentials change, change them first, then `refresh()` the identity (sign-in, new roles) or `clearIdentity()` (sign-out; it only resets the local identity), then `reconnectQueries()` before caller-scoped data renders. Arc resets no state in components that stay mounted, but `RequireRole` unmounts its children and their state for `whileLoading` during `refresh()` and for `forbidden` after `clearIdentity()`, and `refresh()` reloads the page when a signed-in identity resolves to unset.
|
|
141
|
+
When credentials change, change them first, then `refresh()` the identity (sign-in, new roles) or `clearIdentity()` (sign-out; it only resets the local identity), then `reconnectQueries()` before caller-scoped data renders. Arc resets no state in components that stay mounted, but `RequireRole` unmounts its children and their state for `whileLoading` during `refresh()` and for `forbidden` after `clearIdentity()`, and `refresh()` reloads the page when a signed-in identity resolves to unset. See Sign-in, sign-out and account switch in your language reference.
|
|
140
142
|
|
|
141
143
|
`RequireRole` renders children for `roles` (any one) and/or an `allow(details, identity)` predicate (both must pass when given), with `whileLoading` and `forbidden` slots. It forbids anonymous callers, denies when details are missing or the predicate throws, and with no rule denies everyone. It only hides; the server still authorizes every request.
|
|
142
144
|
|
|
@@ -159,10 +161,10 @@ A part is a generated proxy (class or instance) carrying its part, or a full ser
|
|
|
159
161
|
## Avoid
|
|
160
162
|
|
|
161
163
|
- Calling a hook inside a condition or loop, or reading a disabled query's default as data.
|
|
162
|
-
- Closing a dialog by waiting for a list to grow, or inserting the new row by hand.
|
|
163
|
-
- Sending a caller identifier from a form
|
|
164
|
-
- Setting the host's `basePath`: it configures nothing. Use `apiBasePath`
|
|
165
|
-
- Editing generated proxies: change the backend
|
|
164
|
+
- Closing a dialog by waiting for a list to grow, or inserting the new row by hand (edge case: instant feedback, `references/typescript-instant-feedback.md`).
|
|
165
|
+
- Sending a caller identifier from a form: the server takes the caller from the real identity.
|
|
166
|
+
- Setting the host's `basePath`: it configures nothing. Use `apiBasePath` and the router's basename.
|
|
167
|
+
- Editing generated proxies: change the backend, regenerate, type-check the client.
|
|
166
168
|
|
|
167
169
|
## Related skills
|
|
168
170
|
|
|
@@ -43,6 +43,8 @@ export function ScheduleButton({ siteId, date }: { siteId: string; date: Date })
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
**Busy state without your own flag:** `const { isExecuting } = useCommandExecutionState(command)` (from `@cratis/arc.react/commands`) is true from the first `execute()` in flight until the last one settles, whether it succeeds or fails; `validate()` does not set it. It reports pending work only, so take success or failure from the result. Outside a `CommandForm`, use it instead of the `busy` state above when the button only needs disabling.
|
|
47
|
+
|
|
46
48
|
`ScheduleVisit.use({ siteId })` seeds initial values; the returned `setCommandValues(values)` assigns several properties at once and `clearCommandValues()` empties them.
|
|
47
49
|
|
|
48
50
|
## Classify a refusal
|
|
@@ -73,7 +75,7 @@ export function describeRefusal(result: CommandResult<unknown>): string {
|
|
|
73
75
|
|
|
74
76
|
A result has `isSuccess`, `isAuthorized`, `isValid`, `hasExceptions`, `validationResults`, `exceptionMessages`, `exceptionStackTrace`, `authorizationFailureReason`, `isRetryable`, `errorCode`, `isMissingHandler`, `isNotAvailable`, `isSuspended`, `response` (typed, only on success) and `correlationId`. Each finding has `severity`, `message`, `members` (property names, for matching fields), `reason` and `reasonDetail`.
|
|
75
77
|
|
|
76
|
-
The `reason` of a finding is one of `rule`, `concurrencyViolation`, `constraintViolation`, `validatorFailed`, `dependencyUnavailable`, `malformedRequest` or `frameworkFailure` (`concurrencyViolation` and `constraintViolation` come with Chronicle); `reasonDetail` narrows it. Treat an unknown reason as `rule`. Use them to select application-approved copy. Exception messages and stack traces are diagnostics.
|
|
78
|
+
The `reason` of a finding is one of `rule`, `concurrencyViolation`, `constraintViolation`, `validatorFailed`, `dependencyUnavailable`, `malformedRequest` or `frameworkFailure` (`concurrencyViolation` and `constraintViolation` come with Chronicle); `reasonDetail` narrows it. Treat an unknown reason as `rule`. Use them to select application-approved copy: branch on `reason` and `reasonDetail` (the client's own check for an unset required property gives `rule` with `reasonDetail` `Required`; a rule authored on the server that rejects a missing value need not carry that detail, so match it by `members`), never on the message text, which changes with wording and language. Exception messages and stack traces are diagnostics.
|
|
77
79
|
|
|
78
80
|
The result also chains callbacks for simple cases:
|
|
79
81
|
|
|
@@ -181,6 +183,8 @@ export function VisitEditor({ initial }: { initial: Draft }) {
|
|
|
181
183
|
|
|
182
184
|
For one Save/Discard bar, register all editors in the same nearest scope. Dirty tracking, sequential execution and discard cover only its directly registered commands. Only aggregated failures and exceptions include child scopes; coordinate separate scopes explicitly if they must save together. After reverting, pass each editor’s restored values through its setter to refresh its inputs.
|
|
183
185
|
|
|
186
|
+
`scope.execute()` runs only the commands that have changes and returns their combined result: `isSuccess`, `isValid` and `isAuthorized` are true only when they are true for every executed command, and `validationResults` and `exceptionMessages` hold the findings of all of them. For a summary that stays on screen after the call, read the scope instead: `hasValidationFailures` with `aggregatedValidationFailures`, and `hasExceptions` with `aggregatedExceptions`.
|
|
187
|
+
|
|
184
188
|
Use `setHasChanges` and `setIsPerforming` on the scope if its parent needs dirty and busy indicators. `onSuccess` signals one command’s success, not a successful batch. A later failure does not undo earlier saves.
|
|
185
189
|
|
|
186
190
|
## Outside React
|
|
@@ -192,9 +196,10 @@ command.scheduledFor = date;
|
|
|
192
196
|
const result = await command.execute();
|
|
193
197
|
```
|
|
194
198
|
|
|
195
|
-
A constructed command uses the
|
|
199
|
+
A constructed command uses the process-wide configuration, which the host writes when it mounts (service, API prefix, origin and headers callback); it does not register with a scope and does not get the host's `locale`. Prefer the hook inside components; the exception is one instance per gesture when gestures can overlap (see [instant feedback](typescript-instant-feedback.md)).
|
|
196
200
|
|
|
197
201
|
`execute()` does not throw on a network failure or an unreadable response: it returns a result with `hasExceptions` true and `isRetryable` false, so handle those by branching on the result flags. The server may already have run the command in that case; resend only a command that is safe to repeat. The call can still reject on an unexpected error, such as a headers callback that throws, so keep a `catch` for that, as in the React example above.
|
|
198
202
|
|
|
203
|
+
- Busy state without React: `getCommandExecutionState(command).isExecuting` reads it, and `subscribeToCommandExecutionState(command, onChange)` calls `onChange` when the first execution starts and when the last one settles; it returns the function that unsubscribes. Both come from `@cratis/arc/commands`.
|
|
199
204
|
- `command.onPropertyChanged(property => ..., this)` notifies when a command property is assigned, for code that must react to edits without React state.
|
|
200
|
-
- `IdentityProvider` from `@cratis/arc/identity` is the non-React identity access
|
|
205
|
+
- `IdentityProvider` from `@cratis/arc/identity` is the non-React identity access; see Outside React in [Identity and availability](typescript-identity.md).
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
- Packages and compiler settings
|
|
6
6
|
- Entry point
|
|
7
7
|
- Provider order
|
|
8
|
+
- Development proxy
|
|
9
|
+
- Build and lint
|
|
8
10
|
- Request configuration
|
|
9
11
|
- Observable query transport
|
|
10
12
|
- Startup globals
|
|
@@ -14,7 +16,7 @@ Names such as `App`, `fleet` and the header values are illustrative; use the app
|
|
|
14
16
|
|
|
15
17
|
## Packages and compiler settings
|
|
16
18
|
|
|
17
|
-
Install `@cratis/arc`, `@cratis/arc.react`, `@cratis/fundamentals`, `reflect-metadata`, `react` and `react-dom`. Keep `@cratis/arc` and `@cratis/arc.react` on the same release so one runtime is shared.
|
|
19
|
+
Install `@cratis/arc`, `@cratis/arc.react`, `@cratis/fundamentals`, `reflect-metadata`, `react` and `react-dom`. Keep `@cratis/arc` and `@cratis/arc.react` on the same release so one runtime is shared. Declare every package a screen imports directly, such as an icon package, in the application's own dependencies.
|
|
18
20
|
|
|
19
21
|
Generated proxies and models use decorators. In `tsconfig.json`:
|
|
20
22
|
|
|
@@ -27,6 +29,8 @@ Generated proxies and models use decorators. In `tsconfig.json`:
|
|
|
27
29
|
}
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
In an application created from the Cratis template these options live in `.frontend/tsconfig.json`, which includes every `.ts` and `.tsx` file of the project, and the root `tsconfig.json` only extends it. Keep that file's `useDefineForClassFields: false`, bundler module resolution and `noEmit`.
|
|
33
|
+
|
|
30
34
|
Vite's default transform does not emit decorator metadata. Add `@cratis/arc.vite` as a development dependency when classes rely on constructor injection or typed parameters (view models):
|
|
31
35
|
|
|
32
36
|
```ts
|
|
@@ -39,7 +43,9 @@ export default defineConfig({
|
|
|
39
43
|
});
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
The plugin processes `.ts` files; keep decorated classes out of `.tsx`, or pass `EmitMetadataPlugin({ fileRegEx: /\.tsx?$/ })`.
|
|
46
|
+
- The plugin processes `.ts` files; keep decorated classes out of `.tsx`, or pass `EmitMetadataPlugin({ fileRegEx: /\.tsx?$/ })`.
|
|
47
|
+
- It reads the compiler options from `tsconfig.json` in the folder the dev server or build is started from, and does not follow `extends`. When the options live in another file, pass `EmitMetadataPlugin({ tsconfigPath })` with that file's path.
|
|
48
|
+
- **Edge case:** `AddQueryStringToReferences('v=42')`, also from `@cratis/arc.vite`, appends that query string to the module paths of `import ... from` and `export ... from` statements in the built chunks, and to root-relative `url(/...)` references in the built CSS. It rewrites nothing else, such as dynamic imports or relative CSS URLs. Use it only for a host that cannot serve content-hashed file names.
|
|
43
49
|
|
|
44
50
|
## Entry point
|
|
45
51
|
|
|
@@ -64,31 +70,93 @@ createRoot(document.getElementById('root')!).render(
|
|
|
64
70
|
|
|
65
71
|
```tsx
|
|
66
72
|
<Arc>
|
|
67
|
-
<CratisComponentsProvider> {/* @cratis/components */}
|
|
68
|
-
<
|
|
69
|
-
<
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
<CratisComponentsProvider toaster> {/* @cratis/components */}
|
|
74
|
+
<DialogComponents confirmation={ConfirmationDialog} busyIndicator={BusyIndicatorDialog}>
|
|
75
|
+
<MVVM> {/* @cratis/arc.react.mvvm */}
|
|
76
|
+
<BrowserRouter> {/* react-router-dom */}
|
|
77
|
+
<Routes>
|
|
78
|
+
<Route path="/vehicles" element={<Vehicles />} />
|
|
79
|
+
</Routes>
|
|
80
|
+
</BrowserRouter>
|
|
81
|
+
</MVVM>
|
|
82
|
+
</DialogComponents>
|
|
73
83
|
</CratisComponentsProvider>
|
|
74
84
|
</Arc>
|
|
75
85
|
```
|
|
76
86
|
|
|
87
|
+
- **Where it lives.** The entry module renders `<Arc>` and the Components provider around `<App />`; `App.tsx` renders the rest, with one route per feature composition page (see [Routes, layout and menu](typescript-navigation.md)).
|
|
88
|
+
- **`DialogComponents`** (`@cratis/arc.react/dialogs`) supplies the confirmation and busy-indicator dialogs that `useConfirmationDialog()` and `useBusyIndicator()` open; `ConfirmationDialog` and `BusyIndicatorDialog` come from `@cratis/components/Dialogs`. Without it a confirmation resolves as cancelled at once and nothing is shown. See `cratis-components-coordinate-feedback`.
|
|
89
|
+
- **Components provider and the router.** The provider sits directly inside `<Arc>` and outside the router, as shown. The one exception: when you pass it `value.router` so that Components links navigate client-side, render it inside the router, because that value is built from router hooks. See `cratis-components-theme-application`.
|
|
90
|
+
- For a multilingual application, `ArcComponentsProvider` takes the place of `CratisComponentsProvider`; see [UI language](typescript-localization.md).
|
|
91
|
+
|
|
92
|
+
## Development proxy
|
|
93
|
+
|
|
94
|
+
The browser talks to the Vite dev server, so every backend path it calls needs a proxy entry. Arc needs two: `/.cratis` (identity and the live-query hub) and `/api` (generated command and query routes).
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export default defineConfig({
|
|
98
|
+
server: {
|
|
99
|
+
proxy: {
|
|
100
|
+
'/.cratis': { target: 'http://localhost:5000', ws: true },
|
|
101
|
+
'/api': { target: 'http://localhost:5000', ws: true }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- The target is the backend's own address; change it when the backend port changes.
|
|
108
|
+
- `ws: true` forwards WebSocket upgrades. Set it on every path that can carry a live query.
|
|
109
|
+
- Proxying only `/api` breaks the identity request and every live query through the hub.
|
|
110
|
+
- Add an entry for every other backend path the browser calls, such as an API description page.
|
|
111
|
+
|
|
112
|
+
## Build and lint
|
|
113
|
+
|
|
114
|
+
- **Build.** The template's `build` script type-checks the whole frontend before it bundles. It is the check that catches a renamed or removed backend property after proxies are regenerated: run it after every backend contract change. The bundle goes to the folder the backend serves as static files; that folder is build output, never edited by hand.
|
|
115
|
+
- **Lint.** One flat configuration at the project root:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import cratis from '@cratis/eslint-config';
|
|
119
|
+
import arc from '@cratis/eslint-plugin-arc';
|
|
120
|
+
import components from '@cratis/eslint-plugin-components';
|
|
121
|
+
|
|
122
|
+
export default [
|
|
123
|
+
{ ignores: ['.cratis/**'] },
|
|
124
|
+
...cratis.configs.consumer,
|
|
125
|
+
...arc.configs.recommended,
|
|
126
|
+
...components.configs.recommended,
|
|
127
|
+
];
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The Arc configuration skips generated proxies, recognizing them by their content, so proxies beside hand-written files need no path list. Never add a suppression to a generated file. For what the rules check, see `cratis-code-review`.
|
|
131
|
+
|
|
77
132
|
## Request configuration
|
|
78
133
|
|
|
79
134
|
```tsx
|
|
80
135
|
<Arc
|
|
81
136
|
microservice="fleet"
|
|
82
137
|
apiBasePath="/portal"
|
|
83
|
-
httpHeadersCallback={
|
|
138
|
+
httpHeadersCallback={accessTokenHeader}>
|
|
84
139
|
<App />
|
|
85
140
|
</Arc>
|
|
86
141
|
```
|
|
87
142
|
|
|
88
|
-
|
|
143
|
+
`accessTokenHeader` is an application function defined outside the component; the token source is illustrative:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
const accessTokenHeader = () => ({ Authorization: `Bearer ${session.accessToken}` });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- `microservice`: only when the backend consists of named services. The value travels as the `x-cratis-microservice` header, and as a query argument of the same name on WebSocket URLs and on the shared server-sent-events stream. A direct server-sent-events stream carries neither.
|
|
89
150
|
- `apiBasePath`: only when the deployment adds a prefix in front of the generated routes. Client-side routing has its own base in the router.
|
|
151
|
+
- **Served under a path prefix:** set `apiBasePath` for requests and the router's `basename` for routes, to the same prefix. The host's `basePath` configures nothing.
|
|
90
152
|
- `origin`: only for a backend on a different origin.
|
|
91
|
-
- `httpHeadersCallback`:
|
|
153
|
+
- `httpHeadersCallback`: for headers the application owns, such as a bearer token. Called as each request is sent, so new credentials apply to the next request. Keep the function stable (define it outside the component or memoize it). Never return `Accept-Language` from it: Arc sends the UI language itself from the host's `locale` (see [UI language](typescript-localization.md)).
|
|
154
|
+
- **Outside React**, `<Arc>` has written `microservice`, `apiBasePath`, `origin` and the callback to the process-wide `Globals`. An instance constructed with `new` uses the first three. Whether it sends the callback's headers depends on the request:
|
|
155
|
+
- **A command:** yes, on execution and validation.
|
|
156
|
+
- **A query's snapshot request** (`perform()`, on an observable query too): no.
|
|
157
|
+
- **An observable query's subscription:** yes on polling requests and on the hub's subscribe and unsubscribe calls, as in the table below.
|
|
158
|
+
|
|
159
|
+
No constructed instance gets the host's `locale` (see [UI language](typescript-localization.md)). To supply either, call `instance.setRequestDefaults({ httpHeadersCallback, locale })`. That call replaces the process-wide defaults for the instance, so pass the callback together with the locale; passing only one drops the other. For the same header, a callback set on one instance with `setHttpHeadersCallback` wins over those defaults.
|
|
92
160
|
|
|
93
161
|
Which requests carry those headers depends on the observable transport:
|
|
94
162
|
|
|
@@ -103,7 +171,7 @@ So a live query behind header-based authentication needs cookie authentication,
|
|
|
103
171
|
|
|
104
172
|
## Observable query transport
|
|
105
173
|
|
|
106
|
-
Server-sent events through a shared hub is the default and needs no configuration. Change it only for a reason:
|
|
174
|
+
Server-sent events through a shared hub is the default of `<Arc>` and needs no configuration. (Without `<Arc>`, the core default is WebSocket.) Change it only for a reason:
|
|
107
175
|
|
|
108
176
|
```tsx
|
|
109
177
|
import { ObservableQueryTransferMode } from '@cratis/arc';
|
|
@@ -120,14 +188,14 @@ import { QueryTransportMethod } from '@cratis/arc/queries';
|
|
|
120
188
|
|
|
121
189
|
| Prop | Choose a non-default value when |
|
|
122
190
|
| --- | --- |
|
|
123
|
-
| `queryTransportMethod` | `WebSocket` when the infrastructure handles it better than server-sent events
|
|
191
|
+
| `queryTransportMethod` | `WebSocket` when the infrastructure handles it better than server-sent events, or when the backend runs several instances and the load balancer does not keep a browser on one instance: with server-sent events the subscribe requests are separate calls that must reach the instance holding the stream, while WebSocket sends them on the stream's own connection. `Polling` when something cuts long-lived connections or the backend should scale to zero. Polling updates lag by the interval. |
|
|
124
192
|
| `queryConnectionCount` | Many concurrent live queries saturate one hub connection (server-sent events cap at four). |
|
|
125
193
|
| `queryDirectMode` | Each query must use its own endpoint instead of the hub: a direct server-sent-events stream with the default transport, a direct WebSocket with `WebSocket`. Polling is always per query. |
|
|
126
194
|
| `observableQueryTransferMode` | A consumer needs whole collections on every update (for example suspending observable collections). |
|
|
127
195
|
| `queryCacheRetentionMs` | Cached data must be dropped immediately on unmount (`0`) or kept longer than the default. |
|
|
128
196
|
| `eventSourceFactory` | The runtime has no global server-sent-events client, or the stream needs credentials the default client cannot send. |
|
|
129
197
|
|
|
130
|
-
A development proxy must forward the hub endpoints as well as the API routes, including upgrade and streaming support.
|
|
198
|
+
A development proxy must forward the hub endpoints as well as the API routes, including upgrade and streaming support; see Development proxy.
|
|
131
199
|
|
|
132
200
|
## Startup globals
|
|
133
201
|
|
|
@@ -143,8 +211,8 @@ Globals.queryHttpMethod = QueryHttpMethod.Query;
|
|
|
143
211
|
Globals.queryHttpMethodResolver = lengthBasedQueryHttpMethod({ threshold: 1500 });
|
|
144
212
|
```
|
|
145
213
|
|
|
146
|
-
- **Polling timing** (`queryPollingOptions`): `intervalMs
|
|
147
|
-
- **Snapshot-query HTTP method**: a method the generator emitted on the proxy wins, then `queryHttpMethodResolver`, then `queryHttpMethod` (`Get` unless set). `Query`
|
|
214
|
+
- **Polling timing** (`queryPollingOptions`), with defaults: `intervalMs` 5000, `minIntervalMs` 1000, `maxIntervalMs` 60000, `backoffMultiplier` 2, `jitterRatio` 0.2. An observable query instance used outside the hooks overrides them with `setPollingOptions({ intervalMs })` before it subscribes.
|
|
215
|
+
- **Snapshot-query HTTP method**: a method the generator emitted on the proxy wins, then `queryHttpMethodResolver`, then `queryHttpMethod` (`Get` unless set). `Query` sends arguments, paging and sorting in the request body and never falls back; an argument bound to a route parameter is still part of the URL path, so keep sensitive values out of the route. `Auto` tries QUERY and retries as GET when the server refuses the method or the request fails with a network or CORS error, and then stays on GET for that backend, so use it only when arguments are safe in a URL. `lengthBasedQueryHttpMethod` switches above a URL length (2000 characters unless `threshold` is given) to `whenLong` (`Auto` unless given). `resetQueryHttpMethodResolution()` forgets what `Auto` learned, after a network change or between tests.
|
|
148
216
|
|
|
149
217
|
## Slice and application context
|
|
150
218
|
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
- Typed identity details
|
|
7
7
|
- Gate by role
|
|
8
8
|
- Sign-in, sign-out and account switch
|
|
9
|
+
- Behind Cratis AuthProxy
|
|
10
|
+
- Outside React
|
|
9
11
|
- Availability
|
|
10
12
|
|
|
11
13
|
Role names, detail properties and proxies are illustrative. Client-side checks only hide what the server would refuse; the server authorizes every query and command.
|
|
@@ -18,12 +20,12 @@ import { useIdentity } from '@cratis/arc.react/identity';
|
|
|
18
20
|
export function UserBadge() {
|
|
19
21
|
const identity = useIdentity();
|
|
20
22
|
if (identity.isLoading) return <span>…</span>;
|
|
21
|
-
if (!identity.isSet) return <
|
|
23
|
+
if (!identity.isSet) return <span>Not signed in</span>;
|
|
22
24
|
return <span>{identity.name}{identity.isInRole('Planner') && ' (planner)'}</span>;
|
|
23
25
|
}
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
The identity exposes `id`, `name`, `roles`, `details`, `isSet`, `isLoading`, `isInRole(role)`, `refresh()` and `clearIdentity()`. Keep the loading branch: deciding access from a not-yet-loaded identity flashes the wrong UI.
|
|
28
|
+
The identity exposes `id`, `name`, `roles`, `details`, `isSet`, `isLoading`, `isInRole(role)`, `refresh()` and `clearIdentity()`. Keep the loading branch: deciding access from a not-yet-loaded identity flashes the wrong UI. What the not-signed-in branch offers depends on what signs the user in: the application's own sign-in screen, or nothing at all behind Cratis AuthProxy (below).
|
|
27
29
|
|
|
28
30
|
## Typed identity details
|
|
29
31
|
|
|
@@ -94,6 +96,24 @@ While `refresh()` runs, the current identity stays in place and `isLoading` is t
|
|
|
94
96
|
- **Reloaded:** when the result is unset and the identity whose `refresh` you called was set, the provider also reloads the page so the host can redirect to sign-in. The promise still resolves, with the unset identity. Call `refresh()` on the current `useIdentity()` value.
|
|
95
97
|
- **Rejected:** a network error, or a response that could not be read even though the request succeeded: no reload, the provider's current identity stays, `isLoading` returns to false and the promise rejects. Catch it and decide what to show.
|
|
96
98
|
|
|
99
|
+
## Behind Cratis AuthProxy
|
|
100
|
+
|
|
101
|
+
When Cratis AuthProxy fronts the application (`cratis-authproxy-configure`), the proxy owns sign-in, sign-out and tenant selection; the application has no login route and no login screen.
|
|
102
|
+
|
|
103
|
+
- **Sign-in.** An unset identity is not proof that the proxy refused the caller: any unsuccessful identity request resolves to unset as well (see Resolved above). Show the not-signed-in element and let the proxy decide on the next page navigation. A page navigation to a protected path starts sign-in; a background request such as `fetch` is refused with a status code instead and never shows a sign-in page. Never link to an application `/login`.
|
|
104
|
+
- **Sign-out.** Navigate the whole page: `window.location.href = '/.cratis/logout'`. The proxy ends the session and returns the browser to the application root. Never call the endpoint with `fetch`, and no `clearIdentity()` or `reconnectQueries()` is needed, because the page is replaced. To land elsewhere, add `?redirect=` with either a path on the same site (starting with a single `/`) or an absolute `http` or `https` URL whose origin the proxy allows (the site the user is on always is). A missing or disallowed target falls back to the root.
|
|
105
|
+
- **Tenant switcher.** Offer one only when the `.cratis-tenants` cookie lists more than one tenant. Its value is a URL-encoded JSON array of `{ id, name }`; a user with a single tenant has no such cookie. Switch with a page navigation to `/.cratis/select-tenant?tenantId=<id>&returnUrl=<current path>`.
|
|
106
|
+
|
|
107
|
+
## Outside React
|
|
108
|
+
|
|
109
|
+
`IdentityProvider` from `@cratis/arc/identity` serves code with no component, such as a route guard or a startup module:
|
|
110
|
+
|
|
111
|
+
- `await IdentityProvider.getCurrent(StaffDetails)` returns the identity. A set identity is kept in memory and returned without another request. An unset identity or a failed request is not kept, so the next call asks the server again. The details class is optional.
|
|
112
|
+
- `await IdentityProvider.refresh(StaffDetails)` asks the server again.
|
|
113
|
+
- `IdentityProvider.clearCache()` forgets the cached identity after a sign-out. `clearIdentityCookie()` is deprecated and does the same; use `clearCache()`.
|
|
114
|
+
|
|
115
|
+
Inside a component, use `useIdentity()`.
|
|
116
|
+
|
|
97
117
|
## Availability
|
|
98
118
|
|
|
99
119
|
Availability decides whether a part of the application is offered to the current tenant or user at all, and changes live. It needs a backend that serves availability and proxies that carry their part; see Generated metadata in the main reference for which backends do and what to use otherwise.
|
package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-instant-feedback.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Showing a change before the read model has it (edge case)
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- When this applies
|
|
6
|
+
- Created items
|
|
7
|
+
- Removed items
|
|
8
|
+
- Rules
|
|
9
|
+
- Avoid
|
|
10
|
+
|
|
11
|
+
The default is to show nothing extra: the command succeeds, the read model catches up and the observable query pushes the change (see `cratis-platform-deliver-slice`, `references/eventual-consistency.md`). This reference is the exception to "never insert the new row by hand", for the few gestures where that wait is visible. `AllNotes` (observable query), `AddNote` (command), `Note` and their properties are illustrative.
|
|
12
|
+
|
|
13
|
+
## When this applies
|
|
14
|
+
|
|
15
|
+
Only when a gesture must show its result in the same frame: dropping a dragged item, pasting, drawing or moving things on a canvas. A dialog that creates a record does not qualify: it closes on success and the list updates on its own.
|
|
16
|
+
|
|
17
|
+
## Created items
|
|
18
|
+
|
|
19
|
+
Keep the items the user just created in a separate local list, and render the query's items plus the local ones the query does not contain yet.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
const [notes] = AllNotes.use();
|
|
23
|
+
const [justAdded, setJustAdded] = useState<Note[]>([]);
|
|
24
|
+
|
|
25
|
+
const shown = useMemo(() => {
|
|
26
|
+
const known = new Set(notes.data.map(note => note.id.toString()));
|
|
27
|
+
return [...notes.data, ...justAdded.filter(note => !known.has(note.id.toString()))];
|
|
28
|
+
}, [notes.data, justAdded]);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const known = new Set(notes.data.map(note => note.id.toString()));
|
|
32
|
+
setJustAdded(previous => previous.some(note => known.has(note.id.toString()))
|
|
33
|
+
? previous.filter(note => !known.has(note.id.toString()))
|
|
34
|
+
: previous);
|
|
35
|
+
}, [notes.data]);
|
|
36
|
+
|
|
37
|
+
const forget = (id: Guid) =>
|
|
38
|
+
setJustAdded(previous => previous.filter(note => note.id.toString() !== id.toString()));
|
|
39
|
+
|
|
40
|
+
const add = async (text: string) => {
|
|
41
|
+
const id = Guid.create();
|
|
42
|
+
setJustAdded(previous => [...previous, { id, text }]);
|
|
43
|
+
|
|
44
|
+
const command = new AddNote(); // one instance per gesture: gestures can overlap
|
|
45
|
+
command.id = id;
|
|
46
|
+
command.text = text;
|
|
47
|
+
try {
|
|
48
|
+
const result = await command.execute();
|
|
49
|
+
if (!result.isSuccess) forget(id); // and tell the user why
|
|
50
|
+
} catch {
|
|
51
|
+
forget(id); // outcome unknown: the query shows the note if it was accepted
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- The command carries an identity made on the client (`Guid.create()` from `@cratis/fundamentals`), so the local item and the query's item can be matched.
|
|
57
|
+
- A local item leaves the list when the query contains it, and when the command is refused or fails. Classify the refusal as for any command (see [Commands](typescript-commands.md)).
|
|
58
|
+
- The command is constructed per gesture so that two quick gestures never share one instance's values; see Outside React in the same reference for what a constructed command does not get.
|
|
59
|
+
|
|
60
|
+
## Removed items
|
|
61
|
+
|
|
62
|
+
Keep the identities the user just removed and filter them from what is shown. Only filter: the item stays in the query's result, so forgetting its identity brings it back.
|
|
63
|
+
|
|
64
|
+
- **Command refused or failed:** forget the identity, so the item comes back, and tell the user why. This holds for an item from the query and for one still in the local created list.
|
|
65
|
+
- **Command accepted:** keep filtering. A result that lacks the item is not proof that the removal was processed: the query can be loading, filtered, or on another page. Forget the identity only when the item was present in a ready, successful result of that query and is absent from a later one that would contain it (same arguments, not paged past it). When the screen cannot tell, keep the identity; it is dropped with the component.
|
|
66
|
+
- **Item still only in the local created list:** leave it in that list and filter it by identity like any other item; apply the filter to the local items as well as the query's. Deleting the local entry instead would leave nothing to show again when the removal is refused. Keep the identity filtered after the removal is accepted: the create can reach the read model after the user removed the item, and without the filter the item would reappear until the removal is processed too.
|
|
67
|
+
|
|
68
|
+
## Rules
|
|
69
|
+
|
|
70
|
+
- The query stays the source of truth. The local lists only bridge the gap. Nothing guarantees they empty: a read model can stay behind indefinitely, so a local entry may live until the component unmounts. Never show a local created item as confirmed; mark it as pending when the difference matters.
|
|
71
|
+
- Never modify the query result or its array; build the shown list from it.
|
|
72
|
+
- Match by identity, compared as a string or other primitive.
|
|
73
|
+
- Do not guess the time the read model needs: there is no upper bound. Remove a local entry on evidence (the query has the created item, the item was seen and is now gone, or the command failed), never on a timer.
|
|
74
|
+
|
|
75
|
+
## Avoid
|
|
76
|
+
|
|
77
|
+
- Using this for ordinary create dialogs, lists or forms.
|
|
78
|
+
- Replacing the query data with local state.
|
|
79
|
+
- Local entries with no rule that removes them.
|
|
80
|
+
- Treating an item's absence from one result as proof that it was removed.
|
|
81
|
+
- Showing server-computed values (totals, generated numbers, status) in the local item: show only what the user entered.
|
package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-localization.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# UI language in Arc React
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Default path
|
|
6
|
+
- What Arc does with the language
|
|
7
|
+
- Validation text
|
|
8
|
+
- Outside React
|
|
9
|
+
- Avoid
|
|
10
|
+
|
|
11
|
+
This is the home for the client side of the UI language: the texts of the application's own screens and the language Arc sends to the backend. Texts and formats of Cratis Components controls follow it through `ArcComponentsProvider`; see `cratis-components-theme-application` (`references/localization.md`). The backend decides which cultures it honours; see Request localization in `cratis-arc-host-application`. Language tags, text keys and the storage key below are illustrative.
|
|
12
|
+
|
|
13
|
+
## Default path
|
|
14
|
+
|
|
15
|
+
1. **Define the texts** in one catalogue. The first pack is the fallback and defines the shape; every other pack provides the same keys and value kinds.
|
|
16
|
+
2. **Create one locale store** at module level, outside every component.
|
|
17
|
+
3. **Pass the store to the Arc host.** Providers that need the language go inside `<Arc>`.
|
|
18
|
+
4. **Read texts** with `useTranslation(catalogue)` and **switch** with `useLocale()`.
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { createLocale, defineTranslations } from '@cratis/arc/localization';
|
|
22
|
+
import { Arc, useLocale, useTranslation } from '@cratis/arc.react';
|
|
23
|
+
|
|
24
|
+
const translations = defineTranslations('en', { name: 'Name' }, {
|
|
25
|
+
nb: { name: 'Navn' },
|
|
26
|
+
});
|
|
27
|
+
const locale = createLocale({ catalogue: translations, storageKey: 'ui-language' });
|
|
28
|
+
|
|
29
|
+
function Profile() {
|
|
30
|
+
const selection = useLocale();
|
|
31
|
+
const text = useTranslation(translations);
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<select aria-label="Language" value={selection?.locale} onChange={event => selection?.setLocale(event.target.value)}>
|
|
35
|
+
<option value="en" lang="en">English</option>
|
|
36
|
+
<option value="nb" lang="nb">Norsk bokmål</option>
|
|
37
|
+
</select>
|
|
38
|
+
<label>{text.name}<input name="name" /></label>
|
|
39
|
+
</>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const App = () => <Arc locale={locale}><Profile /></Arc>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- **Lookup:** a text is taken from the pack for the exact tag, then its parent (`nb-NO` → `nb`), then the fallback pack.
|
|
47
|
+
- **Supported languages** are the catalogue's packs unless `supported` lists them. Without a catalogue the store defaults to `en`.
|
|
48
|
+
- **Initial language:** a valid saved choice wins, then the browser language when `detectBrowserLanguage: true` is set (off by default), then `defaultLocale`.
|
|
49
|
+
- **`storageKey`** remembers the choice and follows a change made in another tab. Leave it out for a language that lasts only for the page.
|
|
50
|
+
- **`formatLocale`** follows the UI language; set it only to pin `Intl` formatting to another tag.
|
|
51
|
+
- **`useLocale()`** returns `locale`, `supported`, `formatLocale` and `setLocale(tag)`. `setLocale` accepts a supported tag. When the host has no `locale`, `useLocale()` returns `undefined` and `useTranslation` returns the fallback pack, so keep the optional chaining.
|
|
52
|
+
- `<Arc locale>` also accepts the options object directly. Keep the store or options reference stable across renders.
|
|
53
|
+
|
|
54
|
+
For a ready-made selector and Components controls in the same language, mount `ArcComponentsProvider` inside `<Arc locale={locale}>` instead of `CratisComponentsProvider`, as described in `cratis-components-theme-application`.
|
|
55
|
+
|
|
56
|
+
## What Arc does with the language
|
|
57
|
+
|
|
58
|
+
- **Requests.** Commands, query requests, polling and the server-sent-events hub's subscribe and unsubscribe requests send the active language as `Accept-Language`. Do not add the header yourself.
|
|
59
|
+
- **Live streams.** A WebSocket or server-sent-events stream cannot carry the header. When the host has a locale, Arc puts one language tag in the stream URL instead: the value the `Accept-Language` header would have had, when that is a single valid tag. The backend uses it only when it has localization configured and supports that culture.
|
|
60
|
+
- **Switching.** A change refreshes query results and reopens live subscriptions. Nothing is remounted, so inputs and component state keep their values.
|
|
61
|
+
- **Document.** The localized host sets `<html lang>`. Use one localized `<Arc>` per page.
|
|
62
|
+
|
|
63
|
+
## Validation text
|
|
64
|
+
|
|
65
|
+
- With a locale on the host, `CommandForm` shows Arc-owned failures (such as a missing required field) in English or Norwegian Bokmål. Messages authored in a rule pass through unchanged; without a locale the original messages are shown.
|
|
66
|
+
- To change the wording, supply `formatValidationResult` on the form or in `CommandFormDefaults`. Decide by `reason` and `reasonDetail`, never by message text. For your own display, `formatValidationResult(result, locale, { fieldTitle, fieldName })` from `@cratis/arc/localization` returns the platform text for those failures and the original message for every other.
|
|
67
|
+
- **Rule messages translated by the server** only reach the screen when the rule runs on the server. By default the generated proxy carries a copy of the rule, which rejects first with the wording from build time. Generate proxies with client validation set to `server` (see `cratis-arc-generate-proxies`); required-property and route checks still run in the browser.
|
|
68
|
+
|
|
69
|
+
## Outside React
|
|
70
|
+
|
|
71
|
+
- A command or query instance used without the host: `instance.setRequestDefaults({ locale })`. The call replaces the process-wide defaults for that instance, so include `httpHeadersCallback` when the application has one.
|
|
72
|
+
- A browser application without React: set `Globals.locale = locale` (from `@cratis/arc`) once at startup.
|
|
73
|
+
- **Edge case: server rendering.** Create one store per request with the same default language on server and client. Never put a per-user store in `Globals` on a server.
|
|
74
|
+
|
|
75
|
+
## Avoid
|
|
76
|
+
|
|
77
|
+
- Returning `Accept-Language` from `httpHeadersCallback`: an explicit header replaces the automatic one, and a live stream gets it only when it is a single valid language tag. A preference list (`nb, en;q=0.8`) is dropped, so the stream has no language.
|
|
78
|
+
- Creating the store or the options object inside a component.
|
|
79
|
+
- A second localized `<Arc>` on the same page: a document has one language.
|
|
80
|
+
- Matching on message text to translate a validation failure.
|