@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
|
@@ -27,7 +27,7 @@ Not every SDK exposes every entry; your language reference states what is not su
|
|
|
27
27
|
**Declaration and routing**
|
|
28
28
|
|
|
29
29
|
- **Event identity:** register a schema under its type ID; pin the ID explicitly for shared contracts, collisions or renames.
|
|
30
|
-
- **Payload shapes:** each SDK defines which field types an event may hold and how identifiers, dates, enums, geospatial and polymorphic values are stored. Use the SDK's typed values rather than strings or hand-written equivalents; an unsupported shape fails at registration, not at append. Treat an existing enum's member order and values as part of the contract: add new members at the end. The registered schema is generated from a type's members, not from its serializer: a type whose own serializer writes a different shape (such as a single string) must declare the shape it writes (C#, Kotlin and Java; Go refuses a type with its own JSON or text marshaler at registration, and TypeScript and Elixir have no declaration; see your language reference). The declaration changes only the schema, not serialization, and keeps personal-data marking and nullability; keep the serializer.
|
|
30
|
+
- **Payload shapes:** each SDK defines which field types an event may hold and how identifiers, dates, enums, geospatial and polymorphic values are stored. Use the SDK's typed values rather than strings or hand-written equivalents; an unsupported shape fails at registration, not at append. Treat an existing enum's member order and values as part of the contract: add new members at the end. Never hold money or other exact amounts in floating point. Where the SDK has a decimal type (C# `decimal`, Kotlin and Java `BigDecimal`), use it: the kernel keeps a decimal a decimal through storage, projections and read models and never converts it to binary floating point, but the storage provider limits the range and scale a read-model column holds. Where it has none (TypeScript `number` and Go fractional types are floating point), hold exact integer minor units within the SDK's supported integer range. The registered schema is generated from a type's members, not from its serializer: a type whose own serializer writes a different shape (such as a single string) must declare the shape it writes (C#, Kotlin and Java; Go refuses a type with its own JSON or text marshaler at registration, and TypeScript and Elixir have no declaration; see your language reference). The declaration changes only the schema, not serialization, and keeps personal-data marking and nullability; keep the serializer.
|
|
31
31
|
- **Generation:** retain compatible changes within a generation; pair incompatible shapes with migrations (`cratis-chronicle-evolve-event`).
|
|
32
32
|
- **Source ID:** use a typed identifier where available to keep instance keys distinct from stream IDs, subjects and type names.
|
|
33
33
|
- **Declared source:** register a named source definition with optional description and concurrency dimensions; inspect definitions when resolving a route dynamically.
|
package/package/corpus/skills/cratis-chronicle-record-event/references/csharp-coordination.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Coordinate C# writes
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Scope causation, correlation and authorship around a direct append
|
|
6
|
+
- Classify or enrich
|
|
7
|
+
- Build, retry or verify
|
|
8
|
+
- Stage and complete
|
|
9
|
+
- Observe the outcome
|
|
10
|
+
|
|
11
|
+
## Scope causation, correlation and authorship around a direct append
|
|
4
12
|
|
|
5
13
|
In a configured ASP.NET Core host inject `ICausationManager` (`Cratis.Chronicle.Auditing`). The ordinary append uses its ambient chain; dispose the scope to restore the previous chain.
|
|
6
14
|
|
|
@@ -12,6 +20,10 @@ using (causationManager.BeginScope("packing", new System.Collections.Generic.Dic
|
|
|
12
20
|
}
|
|
13
21
|
```
|
|
14
22
|
|
|
23
|
+
**Correlation.** An append without `correlationId:` takes the ambient correlation ID, which flows with the async execution context of the request or job. It does not cross a queue message, another process, or a thread started without that context: carry the value in the message and pass it as `correlationId:` on the append. To set the ambient value at a custom entry point, inject `ICorrelationIdModifier` (`Cratis.Execution`) and call `Modify(correlationId)` before the first append.
|
|
24
|
+
|
|
25
|
+
**Authorship.** Who caused an event is derived from the caller, not chosen by it. When the connection is authenticated as a signed-in Chronicle user, the kernel records that user as `CausedBy` for append, batch append, keyed append, revision and redaction, and ignores a supplied identity together with its on-behalf-of chain. An application connecting with client credentials may supply the end user and an on-behalf-of chain, and the kernel records the application itself only when the append carries no identity at all. The .NET client always sends one: its identity provider's current identity. Which identity that is depends on the provider. The base provider (`BaseIdentityProvider`) returns what `SetCurrentIdentity` set and `Identity.System` when nothing was set: outside a web request, set the end user on it before appending, otherwise the event is recorded as caused by the system identity, not by the application. The ASP.NET Core provider reads the request's `sub`, `name` and `preferred_username` claims instead, returns `Identity.NotSet` when all of them are missing, and does not use an identity set on it for an ordinary request: authenticate the request so the claims are present. Never rely on a supplied identity to attribute a write made under a user's own sign-in.
|
|
26
|
+
|
|
15
27
|
## Classify or enrich
|
|
16
28
|
|
|
17
29
|
```csharp
|
|
@@ -23,7 +35,7 @@ var result = await eventLog.AppendWithNamedTags(parcelId, assigned,
|
|
|
23
35
|
[new NamedTag("service", "express")], tags: ["priority"]);
|
|
24
36
|
```
|
|
25
37
|
|
|
26
|
-
Named tags are additive exact pairs, not replacements for plain `tags`. Use `AppendManyWithNamedTags` for a common batch label or `EventForEventSourceId.NamedTags` / `Tags` per entry. `[Audience]` has two roles. On the event type it makes an audience mandatory: appending that type without an `audience` tag, by any path (`Append`, `AppendMany`, outbox, unit of work), throws `MissingAudience` (`Cratis.Chronicle`); in a unit of work it throws when the event is added, not at commit. On a member (`[property: Audience]`) it only supplies the value from the payload and does not make an audience required. Use both when every event of the type must carry the value it holds. `using var audience = EventTags.Audience(region);` supplies the audience for appends inside the scope. Do not use audience selection as authorization.
|
|
38
|
+
Named tags are additive exact pairs, not replacements for plain `tags`. They need a kernel that supports them: an older kernel rejects the call with an `RpcException` whose status code is `Unimplemented` (a keyed append throws `IdempotentAppendsNotSupported` instead), and never drops the tags silently, so upgrade the kernel before the first named-tag append. Appends without named tags are unaffected. With SQL storage the table name `__cratis_named_tags` is reserved in each namespace database; the table Chronicle creates there is expected, but a conflicting table of that name that is not Chronicle's is detected when an event sequence is first migrated, and event-sequence operations in the namespace then fail with `NamedTagsTableCollision` until it is renamed. Use `AppendManyWithNamedTags` for a common batch label or `EventForEventSourceId.NamedTags` / `Tags` per entry. `[Audience]` has two roles. On the event type it makes an audience mandatory: appending that type without an `audience` tag, by any path (`Append`, `AppendMany`, outbox, unit of work), throws `MissingAudience` (`Cratis.Chronicle`); in a unit of work it throws when the event is added, not at commit. On a member (`[property: Audience]`) it only supplies the value from the payload and does not make an audience required. Use both when every event of the type must carry the value it holds. `using var audience = EventTags.Audience(region);` supplies the audience for appends inside the scope. Do not use audience selection as authorization.
|
|
27
39
|
|
|
28
40
|
Chronicle resolves each event's named tags in one step used by every append path (`Append`, `AppendMany`, unit-of-work staging), in this order: named tags already on the event (including call-site named tags), the ambient `EventTags.Scope` and an `[Audience]` property, then your `IEventTagEnricher`s; merged without duplicate name/value pairs. An ambient audience (`EventTags.Audience`, which is an `EventTags.Scope` for the audience tag) is stamped only on outbox appends and `[Audience]` types; other ambient pairs reach every event. Static `[Tag]` strings are plain tags: they are joined with call-site plain `tags` and de-duplicated separately, and enrichers neither see nor produce them. In a unit of work tags resolve when the event is added, not at commit. Enrichers are discovered automatically, resolved through dependency injection, all run for every event, and must be pure, synchronous and additive: they add tags and never remove or change existing ones. `EventTags.Scope(name, value)` flows with the async execution context until disposed, and nested scopes add up; open it with `using` where a request or background job starts. To change serialized content instead, provide additional event information:
|
|
29
41
|
|
|
@@ -79,6 +91,23 @@ if (!unit.IsSuccess) return; // inspect GetConstraintViolations(), GetConcurrenc
|
|
|
79
91
|
|
|
80
92
|
Staging is not storage. `Transactional.AppendWithNamedTags` and `AppendManyWithNamedTags` retain batch labels. Ordinary `eventLog.Append` is not rolled back. Do not start or commit a second unit when the host owns one.
|
|
81
93
|
|
|
94
|
+
- **Boundary:** a unit belongs to the event store and namespace it was begun on, and `Commit()` sends everything staged as one atomic append to one event sequence. Stage through a single sequence per unit; once an ordered batch (below) or a decision read takes part, staging for another sequence throws `UnitOfWorkCannotSpanEventSequences`. Calls to other services, other databases and immediate appends are outside the unit: rollback does not undo them.
|
|
95
|
+
- **Completion:** a constraint or concurrency rejection does not throw. `Commit()` completes the unit without appending anything and `IsSuccess` is false, so always check it. `Commit()` throws in two ways. A commit that is not admitted (the unit is already completed, or a protected unit is committed by something other than its owner) throws and leaves the unit as it was: nothing was appended and no completion ran. Any failure after the commit was admitted throws as well and completes the unit, whether or not an append was sent: a local failure such as a serialization error sends nothing, while after a transport error it is unknown whether the events were stored. Do not retry on the same unit; when the failure may have reached the kernel, reconcile before retrying. A completed unit cannot be committed or rolled back again (`UnitOfWorkIsAlreadyCommitted`, `UnitOfWorkIsAlreadyRolledBack`): in cleanup code check `unit.IsCompleted` before calling `Rollback()`, or rely on `using`, which rolls back an ordinary unit that was never completed and does nothing for a completed one. An open protected unit is different: disposing it throws `ProtectedUnitOfWorkRequiresOwner`, because only its owner may complete it. Disposing while a commit is in flight also does nothing; the commit finishes the unit.
|
|
96
|
+
- **After completion:** continue after `await unit.Commit()`. `unit.TryGetLastCommittedEventSequenceNumber(out var last)` returns true and the highest position the commit appended, false when nothing was appended. Do not call `unit.OnCompleted(callback)` on a unit begun through `UnitOfWorkManager`: a unit holds one completion callback and the manager uses it to stop tracking the unit, so setting your own replaces it.
|
|
97
|
+
|
|
98
|
+
When one decision spans several event sources and its events must be stored in an exact cross-source order under an explicit guard, stage an ordered batch. Prefer a decision read (`cratis-chronicle-protect-decision`), which derives the guard from what was read; use this alternative only when the code already holds the exact position it decided on:
|
|
99
|
+
|
|
100
|
+
```csharp
|
|
101
|
+
var guard = new ConcurrencyScope(observedTail, EventStreamType: "authorization");
|
|
102
|
+
unit.AddEvents(EventSequenceId.Log,
|
|
103
|
+
[new EventForEventSourceId(fromAccountId, debited), new EventForEventSourceId(toAccountId, credited)],
|
|
104
|
+
[new(new EventSourceId("authorization-history"), guard)]);
|
|
105
|
+
await unit.Commit();
|
|
106
|
+
if (!unit.IsSuccess) return;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`AddEvents` copies the events and scopes when it is called, so changing the collections afterwards has no effect, and nothing is sent before `Commit()`, which appends them in the given order together with everything else staged in the unit. A scope that narrows by event source ID is keyed by that source ID; a scope that does not (as above) may use any non-blank label. On conflict, read again and decide again.
|
|
110
|
+
|
|
82
111
|
With Chronicle ASP.NET Core unit-of-work middleware enabled, use `app.MapPost("/parcels", handler).WithUnitOfWork()` to commit before the minimal API result is returned. For MVC/Razor Pages set `ChronicleAspNetCoreOptions.UnitOfWork.ReportFailuresBeforeResponseStarts` to true (default false). For custom result handling, obtain `IUnitOfWorkCompletionFeature` from `HttpContext.Features`, await `CommitAsync()` before starting the response and inspect the returned unit. Require the feature if persistence is promised.
|
|
83
112
|
|
|
84
113
|
## Observe the outcome
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Inspect, correct and bootstrap C# history
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Read without mutating
|
|
6
|
+
- Correct, close or copy
|
|
7
|
+
- Import historical entries
|
|
8
|
+
- Seed repeatable startup history
|
|
9
|
+
|
|
3
10
|
## Read without mutating
|
|
4
11
|
|
|
5
12
|
```csharp
|
|
@@ -18,7 +25,7 @@ var page = await eventLog.GetPage(EventSequencePageRequest.Forward(null, 50, fil
|
|
|
18
25
|
var latest = await eventLog.GetLatest(20, filter);
|
|
19
26
|
```
|
|
20
27
|
|
|
21
|
-
Source/type history accepts stream type, stream ID and source type. Tail reads also accept those dimensions and event types; `GetTailSequenceNumberWithCancellation(cancellationToken, shipmentId)` supports cancellation. On a paged read consume `page.Events`; while `page.HasMore`, use `page.Next` with the same direction and filter. The request's count is the page size and must be 1–1000: a larger value throws `ArgumentOutOfRangeException` and is not clamped. To read more, including a full export, loop on `page.Next` while `page.HasMore`, keeping the same direction, filter and `Until` bound. Use `Backward` for reverse navigation, `Until` on the request for an end bound. Filter by source ID/type, stream ID/type, event types and plain tags. For a missing event check the sequence and namespace as well as every filter before writing again.
|
|
28
|
+
Sequence numbers follow append order, not business time: an event appended with an earlier `occurred:` still gets the next number, so sort by `Occurred` when business time matters. Source/type history accepts stream type, stream ID and source type. The multi-position `GetMetadataAt(positions)` accepts at most 500 positions per call, duplicates included; more throws `TooManyEventLocators`, so read a longer list in chunks. Positions without an event are left out of the result. Tail reads also accept those dimensions and event types; `GetTailSequenceNumberWithCancellation(cancellationToken, shipmentId)` supports cancellation. On a paged read consume `page.Events`; while `page.HasMore`, use `page.Next` with the same direction and filter. The request's count is the page size and must be 1–1000: a larger value throws `ArgumentOutOfRangeException` and is not clamped. To read more, including a full export, loop on `page.Next` while `page.HasMore`, keeping the same direction, filter and `Until` bound. Use `Backward` for reverse navigation, `Until` on the request for an end bound. Filter by source ID/type, stream ID/type, event types and plain tags. For a missing event check the sequence and namespace as well as every filter before writing again.
|
|
22
29
|
|
|
23
30
|
## Correct, close or copy
|
|
24
31
|
|
|
@@ -28,7 +35,7 @@ Normally append a new business fact. To link a reversal to an original without r
|
|
|
28
35
|
var reversal = await eventLog.Compensate(position, new PackingCancelled("Shipment cancelled"));
|
|
29
36
|
```
|
|
30
37
|
|
|
31
|
-
Pass no event source: the compensation takes the original's source, stream and subject, and the original is never changed. Check `reversal.IsSuccess`; a rejected compensation reports `AppendError.CompensatedEventNotFound` (no event at that position) or `AppendError.EventTypeDoesNotCompensateEventType` (the type is not declared for the original's type) in `reversal.Errors`. `correlationId`, `tags` and `occurred` can describe the correction. Observers and reducers receive the compensation as an ordinary event and read the original's position from `context.CompensationFor` (`EventSequenceNumber?`, null for other events); never copy the sequence number into the payload. Appending a compensation changes no read model and reverses no external action by itself: handle the compensating type in every projection, reducer or reactor that must apply the reversal. For mistaken recorded content rather than a later decision use `await eventLog.Revise(position, new ShipmentPacked(correctCount));`.
|
|
38
|
+
Pass no event source: the compensation takes the original's source, stream and subject, and the original is never changed. Check `reversal.IsSuccess`; a rejected compensation reports `AppendError.CompensatedEventNotFound` (no event at that position) or `AppendError.EventTypeDoesNotCompensateEventType` (the type is not declared for the original's type) in `reversal.Errors`. `correlationId`, `tags` and `occurred` can describe the correction. Observers and reducers receive the compensation as an ordinary event and read the original's position from `context.CompensationFor` (`EventSequenceNumber?`, null for other events); never copy the sequence number into the payload. Chronicle does not prevent a second compensation of the same original, and `Compensate` requests no concurrency check: when a fact may be reversed only once, enforce that yourself. A protected decision read cannot guard this call: `Compensate` is an immediate append, and inside a protected decision it is refused with `ImmediateAppendWhileReadsAreProtected`. Serialize the check and the append together per original position: one caller at a time looks for an existing compensation of that position and appends only when there is none. Serializing the appends alone still admits two compensations in turn. The compensating event does pass append constraints, but a constraint sees its payload and routing, not the position it compensates: use one only when the payload or the source already expresses the once-only rule, for example a unique value carried by the compensating type. Appending a compensation changes no read model and reverses no external action by itself: handle the compensating type in every projection, reducer or reactor that must apply the reversal. For mistaken recorded content rather than a later decision use `await eventLog.Revise(position, new ShipmentPacked(correctCount));`.
|
|
32
39
|
|
|
33
40
|
```csharp
|
|
34
41
|
var scope = ClosedStreamScope.ForEventSource(shipmentId);
|
|
@@ -45,7 +52,17 @@ await eventLog.Redact(shipmentId, new RedactionReason(reason), typeof(ShipmentPa
|
|
|
45
52
|
Guid copyJob = await eventLog.Copy(shipmentId, targetId, typeof(ShipmentPacked));
|
|
46
53
|
```
|
|
47
54
|
|
|
48
|
-
Redact by position **or** source; omit the type list for the entire source. Redaction keeps the position and replaces the content with an `EventRedacted` marker (`Cratis.Chronicle.Events`: `Reason`, `OriginalEventType`, `Occurred`, `CorrelationId`, `Causation`, `CausedBy`). Routing identifiers, tags and subject values remain on the event; the marker keeps the causation types, not their property values. Redaction does not reach earlier copies (backups, exports, events forwarded through an outbox) or derived read models by itself, and receiving the marker does not prove downstream cleanup succeeded, so confirm it before reporting an erasure complete. A reactor or reducer that already handles the original event type may add an `EventRedacted` handler to clean up what it derived: a reducer returns the sanitized model or `null` to remove it, a reactor asks the downstream system to delete its copy. Such an observer receives the marker only when the redacted event was of a type it handles, when it reads that position. That filter needs at least one ordinary event type: an observer handling nothing but `EventRedacted` receives the marker for every redaction in the sequence, whatever the original type, so check `OriginalEventType` there. Replayable observers of the affected events are also asked to replay, so review their external effects first.
|
|
55
|
+
Redact by position **or** source; omit the type list for the entire source. Redaction keeps the position and replaces the content with an `EventRedacted` marker (`Cratis.Chronicle.Events`: `Reason`, `OriginalEventType`, `Occurred`, `CorrelationId`, `Causation`, `CausedBy`). Routing identifiers, tags and subject values remain on the event; the marker keeps the causation types, not their property values. Redaction does not reach earlier copies (backups, exports, events forwarded through an outbox) or derived read models by itself, and receiving the marker does not prove downstream cleanup succeeded, so confirm it before reporting an erasure complete. A reactor or reducer that already handles the original event type may add an `EventRedacted` handler to clean up what it derived: a reducer returns the sanitized model or `null` to remove it, a reactor asks the downstream system to delete its copy. Such an observer receives the marker only when the redacted event was of a type it handles, when it reads that position. That filter needs at least one ordinary event type: an observer handling nothing but `EventRedacted` receives the marker for every redaction in the sequence, whatever the original type, so check `OriginalEventType` there. Replayable observers of the affected events are also asked to replay, so review their external effects first.
|
|
56
|
+
|
|
57
|
+
`Copy` starts a durable job that re-appends the source's events, in sequence order, under the target ID in the same sequence; pass event types to copy only those. Source and target must differ.
|
|
58
|
+
|
|
59
|
+
- Each copy is a new event with a new sequence number. It keeps the event type and generation, tags, stream and original occurred time; its audit context identifies the copy operation.
|
|
60
|
+
- Observers handle every copied event as an ordinary append, so review reactor side effects before starting.
|
|
61
|
+
- Personal data is protected again for the target. When the subject was the source ID, whether by default or assigned explicitly with that same value, the target ID becomes the subject; only a subject that differs from the source ID is kept.
|
|
62
|
+
- The job is not atomic: when a target append fails (for example on a unique constraint) the job reports the failure and the events already copied stay. Inspect the job and the target history before recovering.
|
|
63
|
+
- A resumed job does not duplicate what it already copied. A second `Copy` call is a new job and copies everything again.
|
|
64
|
+
|
|
65
|
+
Track the returned job, not just its submission.
|
|
49
66
|
|
|
50
67
|
## Import historical entries
|
|
51
68
|
|
|
@@ -83,4 +100,4 @@ public class PackingSeed : ICanSeedEvents
|
|
|
83
100
|
}
|
|
84
101
|
```
|
|
85
102
|
|
|
86
|
-
Discovered seeders declare globals or namespace-specific entries. `For<TEvent>` groups homogeneous events; `ForEventSource` accepts mixed types. Both accept `(id, streamType, streamId, events, eventSourceType?)`. `ForEvents(entries)` takes individual routes. Preserve membership, multiplicity and routing for idempotent reconciliation. For explicit bootstrap use `var seeds = store.CreateEventSeeding(); seeds.ForEvents(entries); await seeds.Register();`. Unscoped `For`/`ForEventSource`/`ForEvents` entries are global: the kernel applies them to every existing namespace and every namespace created later. Chronicle does not distinguish development from production seeds, so gate sample data by build or runtime configuration and scope it with `ForNamespace(...)`. The globals from discovered seeders are the program's declaration, owned by `ChronicleOptions.ProgramIdentifier` (the entry assembly name when unset). Each startup replaces the stored declaration, even with an empty set, so removing or scoping a global seeder stops it reaching namespaces created afterwards; if a discovered seeder fails to activate or seed, the previous declaration stays and the next registration retries. Give each program sharing a store a distinct, stable `ProgramIdentifier`. Globals added explicitly through `eventStore.Seeding` or a `CreateEventSeeding()` buffer are append-only and stay stored. Neither path retracts events already appended to existing namespaces; those need separate, deliberate remediation. Verify the history even on successful registration: check server logs for a rejected seed batch and re-register corrected entries with a fresh buffer.
|
|
103
|
+
Discovered seeders declare globals or namespace-specific entries. `For<TEvent>` groups homogeneous events; `ForEventSource` accepts mixed types. Both accept `(id, streamType, streamId, events, eventSourceType?)`. `ForEvents(entries)` takes individual routes. Preserve membership, multiplicity and routing for idempotent reconciliation. For explicit bootstrap use `var seeds = store.CreateEventSeeding(); seeds.ForEvents(entries); await seeds.Register();`. Unscoped `For`/`ForEventSource`/`ForEvents` entries are global: the kernel applies them to every existing namespace and every namespace created later. Chronicle does not distinguish development from production seeds, so gate sample data by build or runtime configuration and scope it with `ForNamespace(...)`. The globals from discovered seeders are the program's declaration, owned by `ChronicleOptions.ProgramIdentifier` (the entry assembly name when unset). Each startup replaces the stored declaration, even with an empty set, so removing or scoping a global seeder stops it reaching namespaces created afterwards; if a discovered seeder fails to activate or seed, the previous declaration stays and the next registration retries. Give each program sharing a store a distinct, stable `ProgramIdentifier`. Globals added explicitly through `eventStore.Seeding` or a `CreateEventSeeding()` buffer are append-only and stay stored. Neither path retracts events already appended to existing namespaces; those need separate, deliberate remediation. Seeds are appended in batches of 100 and a batch is validated as a whole: one constraint violation leaves every entry of that batch unseeded, registration still succeeds, and the client is not told. Verify the history even on successful registration: check server logs for a rejected seed batch and re-register corrected entries with a fresh buffer. Global seeds reach a newly created namespace asynchronously, with no guarantee that they arrive before the application's first write, so never let startup logic depend on seeded events being present. A buffer holding an entry with non-default routing needs a kernel that supports routed seeds: against an older kernel `Register()` throws `EventSeedingRoutingNotSupported` before sending anything, including the buffer's unrouted entries; upgrade the kernel, then register again.
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Record events with the C# client
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Record one fact
|
|
6
|
+
- Common mistakes
|
|
7
|
+
- Property types in events
|
|
8
|
+
- Route one decision
|
|
9
|
+
- Choose a conditional path
|
|
10
|
+
|
|
11
|
+
## Record one fact
|
|
12
|
+
|
|
3
13
|
Add `Cratis.Chronicle` to the writer project and connect to a running kernel. Names are illustrative. For local development:
|
|
4
14
|
|
|
5
15
|
```csharp
|
|
@@ -31,7 +41,7 @@ public record ShipmentPacked(int Cartons);
|
|
|
31
41
|
- Await the append and inspect `IsSuccess`; returning a result does not mean the fact was accepted.
|
|
32
42
|
- For related facts reuse the source ID, not a new GUID per append.
|
|
33
43
|
|
|
34
|
-
In a configured host inject `IEventLog` for the intended store/namespace; select a different sequence only deliberately (`store.GetEventSequence(id)`). The client discovers event types in its configured assemblies. The parameterless `[EventType]` is the default: the ID is the type name, at the first generation. Pin an explicit ID such as `[EventType("shipment-packed")]` only to keep a stored ID stable across a type rename, to resolve a name collision, or to match an ID another system publishes. For an incompatible shape pin the same ID with `generation: 2` and supply the migration (`cratis-chronicle-evolve-event`). `[Tombstone]` marks terminal meaning; it does not enforce closure. The Chronicle analyzer warns on a nullable property of an event type: record an optional fact as a separate event type instead.
|
|
44
|
+
In a configured host inject `IEventLog` for the intended store/namespace; select a different sequence only deliberately (`store.GetEventSequence(id)`). The client discovers event types in its configured assemblies. The parameterless `[EventType]` is the default: the ID is the type name, at the first generation. Pin an explicit ID such as `[EventType("shipment-packed")]` only to keep a stored ID stable across a type rename, to resolve a name collision, or to match an ID another system publishes. For an incompatible shape pin the same ID with `generation: 2` and supply the migration (`cratis-chronicle-evolve-event`). Each generation of a type ID is represented by exactly one type: two types that resolve to the same ID and generation make event type discovery fail at startup with `MultipleEventTypesWithSameIdFound`, before any append. Keep a superseded shape only as an earlier generation of the current type, with `[EventTypeGenerationFor<ShipmentPacked>(1)]` in place of `[EventType]`; never as a second `[EventType]` under the same ID. `[Tombstone]` marks terminal meaning; it does not enforce closure. The Chronicle analyzer warns on a nullable property of an event type: record an optional fact as a separate event type instead.
|
|
35
45
|
|
|
36
46
|
`IsSuccess` is true only when none of these holds. Branch on the cause rather than reporting one generic failure:
|
|
37
47
|
|
|
@@ -48,11 +58,19 @@ A refused append records nothing; use `SequenceNumber` only after success. `WasA
|
|
|
48
58
|
Chronicle describes each event type with a schema derived from the record, and uses it to read stored content back. Read models follow the same rules.
|
|
49
59
|
|
|
50
60
|
- **Default:** primitives, enums, nested records, collections, and `ConceptAs<T>` value types (`using Cratis.Concepts;`) (stored as their underlying primitive).
|
|
61
|
+
- **Money and other exact amounts:** `decimal`, or a concept wrapping one. Chronicle keeps the value a decimal through event storage, projections and read-model sinks and never converts it to binary floating point; `double` and `float` stay floating point. The storage provider still limits the range and scale a read-model column holds.
|
|
62
|
+
- **Never encode a fact as an absent member:** a nullable member holding `null` and a member missing from the stored content read back the same, as `null`, and a missing non-nullable member can read back as the type's default. Record "this did not happen" or "not yet known" as its own event type.
|
|
51
63
|
- **Location, route or area:** `Point` (longitude first, then latitude), `LineString` and `Polygon` from `Cratis.Geospatial`, e.g. `new Point(10.456, 42.123)` or `new Polygon(Shell: new LinearRing(points), Holes: [])`. A ring's first and last point are the same. Projections copy them with auto-mapping; never split a geometry into coordinate properties.
|
|
52
64
|
- **A type with its own JSON converter (edge case):** when the converter writes a different shape than the type's members, declare that shape with `[JsonSchemaType(typeof(string))]` (`Cratis.Chronicle.Schemas`) beside `[JsonConverter]`. It changes only the schema, not serialization, and keeps `[PII]` and nullability.
|
|
53
65
|
|
|
54
66
|
## Route one decision
|
|
55
67
|
|
|
68
|
+
Every event carries four routing values: event source type, event source ID, stream type and stream ID.
|
|
69
|
+
|
|
70
|
+
- **Default:** supply only the source ID; the other three take their defaults. This is right while every event of an entity shares one history and one guard.
|
|
71
|
+
- **Event source definition:** declare one when the same kind of entity is written from several places and the routing names must agree, or when the entity has parts with their own lifecycle or concurrency (a stream per month or process step, a stream that closes on its own, an observer for one stream). The definition supplies the source type and the stream type; the caller supplies the source ID and may supply a stream ID, which takes its default when omitted.
|
|
72
|
+
- **Free-form route (edge case):** pass the routing values directly only when the writer already owns a routing convention and no definition is wanted.
|
|
73
|
+
|
|
56
74
|
Use `Cratis.Chronicle.EventSources` to declare a route shared by writers:
|
|
57
75
|
|
|
58
76
|
```csharp
|
|
@@ -73,7 +91,7 @@ var mixed = await eventLog.AppendMany([
|
|
|
73
91
|
]);
|
|
74
92
|
```
|
|
75
93
|
|
|
76
|
-
These are alternatives. `
|
|
94
|
+
These are alternatives. `eventLog.Append<Shipment>(shipmentId, packed, eventStream: "Packing", eventStreamId: packingRunId)` is the generic form of `AppendThroughEventSource`, and `AppendMany<Shipment>(...)` of `AppendManyThroughEventSource`, which routes one source's batch through a definition. Append through the definition rather than repeating its source type or stream name as free-form strings at call sites. The definition's name and its stream names are stored on every event, so renaming one is a data change, not a refactoring: stored events keep the old name and observers that filter on the new name do not see them. A definition route is checked before anything is sent: `UnknownEventSource` (the definition is not registered in this store), `EventStreamDoesNotBelongToEventSource` (the named stream is not declared on it) and `EventRoutingContradictsEventSource` (an explicit `eventSourceType` or `eventStreamType` differs from the definition) are thrown, not returned in the result. Fix the route; do not drop the definition to make the append pass. Check `IsSuccess` before consuming `SequenceNumbers`. For a free-form route use `eventSourceType`, `eventStreamType`, `eventStreamId`; absent overrides use the default source type, all-stream type and default stream ID. Use `occurred:` for historical time (otherwise approximately append time), `correlationId:` for the operation, `subject:` to override the subject derived from a `[property: Subject]` member. Ordinary append records the current identity, not an import entry's `CausedBy`.
|
|
77
95
|
|
|
78
96
|
The default optimistic strategy isn't a guard for an earlier decision read (first append into an empty scope isn't checked by default). Pass `concurrencyScope: new ConcurrencyScope(observedTail, EventSourceId: shipmentId)` from `Cratis.Chronicle.EventSequences.Concurrency`, or `concurrencyScopes:` keyed by source for mixed entries. Re-decide after a conflict; see `cratis-chronicle-protect-decision`.
|
|
79
97
|
|
|
@@ -59,7 +59,7 @@ Prefer `seq.Append(ctx, source, correction)` for a later decision. `seq.Compensa
|
|
|
59
59
|
|
|
60
60
|
Erase with `seq.Redact(ctx, position, reason)` or `seq.RedactForEventSource(ctx, source, reason, assigned.Ref().ID)` (omit type IDs for the whole source). `seq.Copy(ctx, source, target, assigned.Ref().ID)` submits a job, not a completed copy; omit type IDs for all types.
|
|
61
61
|
|
|
62
|
-
`ReadSource` also accepts `SourceType`, `StreamType`, `StreamID`; empty or default route sentinels don't narrow. `seq.ReadFrom(ctx, position, eventsequences.FromFilter{SourceID: &source})` starts inclusively; optional `EventTypes` matches IDs across generations. Rows expose context, JSON, original and generational content and revisions when available. `seq.HasEvents(ctx, source)` tests existence. `seq.Next(ctx)` doesn't reserve a position. `seq.Tail(ctx, eventsequences.TailFilter{})` and `seq.TailForObserver(ctx, []events.TypeRef{assigned.Ref()})` return position, presence and error; absence isn't position zero.
|
|
62
|
+
`ReadSource` also accepts `SourceType`, `StreamType`, `StreamID`; empty or default route sentinels don't narrow. `seq.ReadFrom(ctx, position, eventsequences.FromFilter{SourceID: &source})` starts inclusively; optional `EventTypes` matches IDs across generations. Rows expose context, JSON, original and generational content and revisions when available. `seq.HasEvents(ctx, source)` tests existence. `seq.Next(ctx)` doesn't reserve a position. `seq.Tail(ctx, eventsequences.TailFilter{})` and `seq.TailForObserver(ctx, []events.TypeRef{assigned.Ref()})` return position, presence and error; absence isn't position zero. `events.First` is zero and a real position. `events.Unavailable`, `events.Max` and `events.BeforeFirst` are reserved values, not positions (the largest real position is `BeforeFirst - 1`, not `Max`); test with `IsActualValue()` before storing, comparing or passing a number on, and never use a reserved value as an exact expected position. For arithmetic use `Next()`, `Add(n)` and `Subtract(n)` and check the returned error: leaving the valid range returns `Unavailable` with `events.ErrSequenceNumberRange`, and a reserved value is returned unchanged, so `BeforeFirst.Next()` is not `First`.
|
|
63
63
|
|
|
64
64
|
## Import and seed
|
|
65
65
|
|
|
@@ -90,7 +90,7 @@ try (var unit = store.beginUnitOfWork()) {
|
|
|
90
90
|
}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
Closing an unfinished unit rolls back; `rollback()` explicitly discards. Ordinary `log.append` is immediate. For local instrumentation `var job = EventLogJavaBridge.watchAppendOperations(store.unwrap().getEventLog(), this::recordMetrics);` receives lists of events with results; cancel with `job.cancel(null)`. Not a durable subscription.
|
|
93
|
+
Closing an unfinished unit rolls back; `rollback()` explicitly discards. The current unit is tracked per thread: begin, stage, commit and close on the same thread, because `getTransactional()` called on another thread uses that thread's current unit, if it has one, and appends immediately when it has none. `commit()` appends in staging order, one atomic batch per run of consecutive events with the same sequence, source ID and options, one batch after another; a unit that stages for several sources (as above) is not atomic across them, and an earlier batch stays appended when a later one is rejected. One source alone is not enough: staging for it again after another source, or with different options, starts a new batch. When all-or-nothing matters, stage one unbroken run with the same sequence, source ID and options. Ordinary `log.append` is immediate. For local instrumentation `var job = EventLogJavaBridge.watchAppendOperations(store.unwrap().getEventLog(), this::recordMetrics);` receives lists of events with results; cancel with `job.cancel(null)`. Not a durable subscription.
|
|
94
94
|
|
|
95
95
|
See [history, import and seeding](java-history.md) for inspection, administration and bootstrap.
|
|
96
96
|
|
|
@@ -93,6 +93,9 @@ val results = ops.perform() // or ops.clear() to discard pending entries
|
|
|
93
93
|
|
|
94
94
|
Import `eventSequences.operations.operations`. For deferred writes use `val unit = store.unitOfWorkManager.begin()`, stage via `log.transactional.append(parcel.raw, weighed)` or `appendMany`, then `unit.commit()` and check `unit.isSuccess`, `getConstraintViolations()`, `getConcurrencyViolations()` and `getAppendErrors()`. Alternatively `unit.rollback()` before completion. Staged success has no assigned position; without a current unit the transactional facade writes immediately. `unitOfWorkManager.current` throws `NoUnitOfWorkHasBeenStarted` when none is active; test `hasCurrent` first. The ordinary log is always immediate.
|
|
95
95
|
|
|
96
|
+
- **One thread per unit:** the current unit is tracked per thread. `transactional` stages only on the thread that began the unit; on any other thread, including a coroutine that resumed on another dispatcher thread, it uses that thread's current unit, if there is one, and appends immediately when there is none. Begin, stage, commit and inspect on one thread, for example inside one `runBlocking` block without switching dispatcher.
|
|
97
|
+
- **Atomic per run, not per unit:** `commit()` appends in staging order, one atomic batch per run of consecutive events with the same sequence, source ID and options, one batch after another. A unit that stages for several sources is not atomic across them: an earlier batch stays appended when a later one is rejected, and `isSuccess` is then false. One source alone is not enough: staging for it again after another source, or with different options, starts a new batch. When all-or-nothing matters, stage one unbroken run with the same sequence, source ID and options.
|
|
98
|
+
|
|
96
99
|
The Spring request filter commits after the chain returns unless already completed. If the HTTP result promises persistence, commit the existing `store.unitOfWorkManager.current` and inspect it **before** sending the response; do not begin a second unit. Collect `log.appendOperations.collect { batch -> batch.forEach { inspect(it.context, it.event, it.result) } }` in a separate coroutine for client instrumentation, not durable delivery.
|
|
97
100
|
|
|
98
101
|
For corrections, imports, reads and seeding see [History and bootstrap](kotlin-history.md).
|
|
@@ -37,7 +37,8 @@ Catch-up, retry and replay must compute the same result from the same history. U
|
|
|
37
37
|
- **Sequence:** select a named event sequence when the input is not the event log.
|
|
38
38
|
- **Source store:** route a foreign store's subscribed events through its inbox; do not also select an unrelated sequence.
|
|
39
39
|
- **Active flag:** disable continuous maintenance when the client should register the definition but not keep a sink current.
|
|
40
|
-
- **Passive model:** reconstruct by key on demand when reads are rare or must fold the available history. Follow the SDK's passive declaration; an inactive observer alone does not universally enable passive reads.
|
|
40
|
+
- **Passive model:** reconstruct by key on demand when reads are rare or must fold the available history. Follow the SDK's passive declaration; an inactive observer alone does not universally enable passive reads. A passive read returns current state but does not guard a later append: another writer can append between the read and the write. When the state gates a write, guard the write. Use a reducer decision read only where the SDK offers one and admits this reducer; which reducers qualify differs per SDK, so follow the language reference and that skill. Otherwise guard a history read on the same sequence the append targets, or use a constraint that actually expresses the invariant (`cratis-chronicle-protect-decision`, `cratis-chronicle-constrain-append`).
|
|
41
|
+
- **Several sources, one instance:** not a reducer; its model is always keyed by event source. Build that model as a projection (`cratis-chronicle-project-view`). Chronicle does not apply its redelivery guard to a combined instance, so a repeated batch can be applied twice: keep its updates idempotent. Assign a value the event carries; do not turn a delta into an assignment.
|
|
41
42
|
- **Bounded fold:** where offered, request a prefix of history for analysis; an event count is not an as-of timestamp.
|
|
42
43
|
- **Labels:** attach observer tags for organization without changing which events reach the fold.
|
|
43
44
|
- **Event-tag filter:** admit events matching any configured tag when only a tagged subset contributes. That rule holds on active delivery; check your language reference for on-demand reads.
|
|
@@ -90,6 +90,8 @@ public class AccountBalanceReducer : IReducerFor<AccountBalance>
|
|
|
90
90
|
|
|
91
91
|
Same rules as above, except that methods are instance methods, the class may take constructor dependencies, and a method returning bare `Task` removes the instance. A model built by an `IReducerFor<T>` must not also declare static `Reduce` methods.
|
|
92
92
|
|
|
93
|
+
One read model per reducer class. A non-generic class that implements `IReducerFor<>` for two read models, including through a base class, fails default discovery with `TypeMustImplementOnlyOneReducer`; discovery skips generic classes. Analyzer CHR0057 reports the same shape at build time, inherited interfaces included. Split it into one reducer class per read model.
|
|
94
|
+
|
|
93
95
|
## Redacted events
|
|
94
96
|
|
|
95
97
|
When an event is redacted, a reducer class that handles its type can also handle `EventRedacted` (`Cratis.Chronicle.Events`) to sanitize the derived state, or return `null` to remove it:
|
|
@@ -127,7 +129,7 @@ public record AccountBalance(decimal Balance, int RejectedWithdrawals) { /* Redu
|
|
|
127
129
|
|
|
128
130
|
For an ordinary typed read use `var balance = await eventStore.ReadModels.GetInstanceById<AccountBalance>("account-1");`. The same call reads a materialized reducer or folds a passive reducer on demand. Handle missing state.
|
|
129
131
|
|
|
130
|
-
Use it for state read
|
|
132
|
+
Use it for state that is read rarely or must be current when read. It costs an event read per call and does not create a queryable collection. A passive read does not guard a later append: another writer can append between the read and the write. When the state gates a write, read it as a decision read (`cratis-chronicle-protect-decision`). Check `eventStore.GetDecisionReads().Admit<AccountBalance>()` first and act on `IsAdmitted` and `Reason`. Refusals include a reducer that observes another sequence than the event log, filters its events, is a separate reducer class with a constructor dependency other than `ILogger<T>`, handles more than one generation of an event type, or is asked for a single stream; the list is not exhaustive. On refusal, do not fall back to the unguarded read. Guard a history read only when the append targets the same sequence that read covered, because the concurrency check runs against the sequence being appended to. Otherwise use a constraint, and only one that actually expresses the invariant (`cratis-chronicle-constrain-append`). For explicit reconstruction:
|
|
131
133
|
|
|
132
134
|
```csharp
|
|
133
135
|
var reducers = eventStore.Reducers;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Fold a source's events in Java
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Start and read
|
|
6
|
+
- Configure input and storage
|
|
7
|
+
- Batch instead of per-event handlers
|
|
8
|
+
- Operations and boundaries
|
|
9
|
+
- Definition errors
|
|
10
|
+
|
|
3
11
|
Use `io.cratis:chronicle`. The example names are illustrative. Put the public types below in separate files in the application's discovery package. `EventType` and `EventContext` are in `io.cratis.chronicle.events`, `ReadModel` and `Passive` in `io.cratis.chronicle.readModels`, and the handler annotations and batch types in `io.cratis.chronicle.observation`.
|
|
4
12
|
|
|
5
13
|
```java
|
|
@@ -42,7 +50,8 @@ SlotState slot = store.getReadModels().getInstanceByKey(SlotState.class, "slot-7
|
|
|
42
50
|
|
|
43
51
|
## Configure input and storage
|
|
44
52
|
|
|
45
|
-
- IDs default to simple class names. Set stable IDs on the reducer and model to survive renames. `@Reducer(eventSequence = "dispatch-input")` overrides the event-log default; a nonempty `@EventSequence("dispatch-input")` on the class takes precedence.
|
|
53
|
+
- IDs default to simple class names. Set stable IDs on the reducer and model to survive renames. `@Reducer(eventSequence = "dispatch-input")` overrides the event-log default; a nonempty `@EventSequence("dispatch-input")` on the class takes precedence. There is no `@EventLog` or `@EventStore` annotation: a reducer that names no sequence already reads the event log.
|
|
54
|
+
- Every handler groups by event source ID. `@ContextKey` has no effect; for a different key use a projection: `@FromEvent(key = …)` on a model-bound projection for a key in the payload, or the key in a projection builder.
|
|
46
55
|
- `@Tag({"dispatch", "operations"})` labels the reducer without filtering. Repeat `@FilterEventsByTag("confirmed")` with another value to register multiple input tags; `@EventSourceType("slot")` and `@EventStreamType("reservations")` further restrict input. Without these annotations nothing is filtered. **Passive local reads require all configured tags**; use a single tag when the same admission rule must hold on both paths.
|
|
47
56
|
- Active is the default. Mark `SlotState` with `@Passive` or set `@Reducer(isActive = false)` to register without a sink. The same key lookup on the client hosting that registration fetches matching source history and folds from null. No matching state yields null; a fold failure reaches the caller.
|
|
48
57
|
- For a bounded passive report use `ReadModelsJavaBridge.getInstances(store.unwrap().getReadModels(), SlotState.class, 100L)`. The bound is on matching events in sequence order **across sources before grouping**, not rows per source. Omit the count for the full result.
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Fold read-model state in Kotlin
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Registration and routing
|
|
6
|
+
- Passive and bounded reads
|
|
7
|
+
- Batch alternative
|
|
8
|
+
- Operations
|
|
9
|
+
- Definition errors
|
|
10
|
+
- Not supported in this SDK
|
|
11
|
+
|
|
3
12
|
Use the `io.cratis:chronicle` client with a connected event store. Put the event, model and separate reducer in the application's discovered packages. Names are illustrative.
|
|
4
13
|
|
|
5
14
|
```kotlin
|
|
@@ -29,7 +38,7 @@ Use public regular or `suspend` member functions; the first parameter's `@EventT
|
|
|
29
38
|
|
|
30
39
|
Automatic registration is on by default. Use `options.withArtifactsFrom("example.slots")` to scope discovery, or supply `artifacts = KnownClientArtifacts(SlotReserved::class, ReservationCancelled::class, Slot::class, SlotReducer::class)` in `ChronicleOptions` rather than scan. For a manually wired reducer, with event types registered, call `store.reducers.register(SlotReducer())` from a coroutine; it returns the observation `Job`. Do not also auto-register the reducer. The instance is shared across sources; inject only dependencies safe for concurrent deterministic use. `ChronicleOptions.artifactActivator` creates each discovered reducer once, at registration; replace it to resolve reducers from a dependency container. It is not invoked per delivery.
|
|
31
40
|
|
|
32
|
-
The observer ID defaults to the reducer class's simple name; the model ID defaults to the model's simple name (override with `@ReadModel(id = "slots")`). Active maintenance reads the event log unless you set `@Reducer(eventSequence = "dispatch")`; a nonempty observation `@EventSequence("dispatch")` takes precedence. All handlers group by event source ID.
|
|
41
|
+
The observer ID defaults to the reducer class's simple name; the model ID defaults to the model's simple name (override with `@ReadModel(id = "slots")`). Active maintenance reads the event log unless you set `@Reducer(eventSequence = "dispatch")`; a nonempty observation `@EventSequence("dispatch")` takes precedence. There is no `@EventLog` or `@EventStore` annotation: a reducer that names no sequence already reads the event log. All handlers group by event source ID. `@ContextKey` has no effect; for a different key use a projection: `@FromEvent(key = …)` on a model-bound projection for a key in the payload, or the key in a projection builder.
|
|
33
42
|
|
|
34
43
|
Apply observation annotations to the reducer class as needed:
|
|
35
44
|
|
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
# Fold state in a Node server
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Register a separate reducer
|
|
6
|
+
- Configure the definition
|
|
7
|
+
- Fold a batch instead
|
|
8
|
+
- Lifecycle and operations
|
|
9
|
+
- Not supported in this SDK
|
|
10
|
+
|
|
3
11
|
## Register a separate reducer
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
Use the project's single decorator mode. Standard decorators are the default: leave `experimentalDecorators` and `emitDecoratorMetadata` unset. In standard mode every serialized member of an event or read model is a public instance field, not an accessor, whose type the client can resolve: prefer an explicit `@field(Type)` from `@cratis/fundamentals`, which works in both modes; a default value the client can infer the type from also works. Constructor parameter properties (`constructor(readonly reservation: string)`) on events and read models require legacy mode. A project in legacy mode enables `experimentalDecorators`; also enable `emitDecoratorMetadata` when member types are to be inferred from emitted metadata. Explicit `@field(Type)` members do not depend on it.
|
|
14
|
+
|
|
15
|
+
Import `reflect-metadata` before decorated modules and load those modules before obtaining the event store. Use a long-lived client with keep-alive enabled. Names below are illustrative.
|
|
6
16
|
|
|
7
17
|
```ts
|
|
8
18
|
import 'reflect-metadata';
|
|
9
19
|
import { ChronicleClient, ChronicleOptions, eventType, handles, reducer, type EventContext } from '@cratis/chronicle';
|
|
20
|
+
import { field } from '@cratis/fundamentals';
|
|
10
21
|
|
|
11
22
|
@eventType('slot-reserved')
|
|
12
|
-
class SlotReserved {
|
|
23
|
+
class SlotReserved {
|
|
24
|
+
@field(String) reservation: string;
|
|
25
|
+
constructor(reservation: string) { this.reservation = reservation; }
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
@eventType('reservation-ended')
|
|
14
|
-
class ReservationEnded {
|
|
15
|
-
|
|
29
|
+
class ReservationEnded {
|
|
30
|
+
@field(String) reservation: string;
|
|
31
|
+
constructor(reservation: string) { this.reservation = reservation; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class Occupancy {
|
|
35
|
+
@field(String) id = '';
|
|
36
|
+
@field(String) reservation = '';
|
|
37
|
+
}
|
|
16
38
|
|
|
17
39
|
@reducer('slot-occupancy', undefined, Occupancy)
|
|
18
40
|
class SlotOccupancy {
|
|
@@ -31,7 +53,7 @@ const store = await client.getEventStore('Scheduling');
|
|
|
31
53
|
const occupied = await store.readModels.findInstanceById(Occupancy, 'slot-42'); // null if absent
|
|
32
54
|
```
|
|
33
55
|
|
|
34
|
-
A handler is a prototype method (not an arrow field), named after the event in lower camel case or explicitly bound with `@handles`. Synchronous and promised results work. Treat the payload and state as data, not class instances. The optional third parameter supplies `sequenceNumber` (bigint), `occurred`, `causedBy` and other recorded metadata. Return the whole replacement, the current value to ignore, or `undefined` to remove. Never return `null`: it does not remove the model. Returning `null` passes it as current state to the next handler for the same event source in that delivery. If `null` is still the final result, a live reducer fails that event source instead of deleting the model, and `ReadModelScenario` keeps the null state; normal live delivery then skips the failed source until it recovers. When `undefined` is the final result of a successful delivery, the stored model is removed and a later reservation for the same source can recreate it. Throw on an unexpected failure.
|
|
56
|
+
A handler is a prototype method (not an arrow field), named after the event in lower camel case or explicitly bound with `@handles`. Synchronous and promised results work. On event and read-model classes (not the reducer), name each constructor parameter after the field it assigns and keep the constructor safe to call without arguments: the client constructs these types with no arguments and then assigns fields. Treat the payload and state as data, not class instances. The optional third parameter supplies `sequenceNumber` (bigint), `occurred`, `causedBy` and other recorded metadata. Return the whole replacement, the current value to ignore, or `undefined` to remove. Never return `null`: it does not remove the model. Returning `null` passes it as current state to the next handler for the same event source in that delivery. If `null` is still the final result, a live reducer fails that event source instead of deleting the model, and `ReadModelScenario` keeps the null state; normal live delivery then skips the failed source until it recovers. When `undefined` is the final result of a successful delivery, the stored model is removed and a later reservation for the same source can recreate it. Throw on an unexpected failure.
|
|
35
57
|
|
|
36
58
|
The decorator registers both classes for discovery. Without a bound model constructor the identifier falls back to the reducer class name and the SDK registers an open schema. For explicit wiring supply `clientArtifactsProvider` in the options factory with `eventTypes: [SlotReserved, ReservationEnded]`, `reducers: [SlotOccupancy]`, `readModels: [Occupancy]` and the provider's remaining artifact lists; use `discoveryPatterns: []` to avoid scanning. Normal store startup handles discovery and registration (`store.reducers.discover()` and `register()` for explicit lifecycle management).
|
|
37
59
|
|
|
@@ -24,3 +24,21 @@ Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Nod
|
|
|
24
24
|
- **Wire contracts** — choose these alone for a tool inspecting or encoding protocol messages. A serialize/decode round trip tests the message shape, not kernel acceptance. Where a language has no application client, the contracts are for offline inspection only; send application work to the owning service.
|
|
25
25
|
- **Test support** — the in-process testing dependency belongs in the specification project only, never in the service; selecting and using it is covered by `cratis-specifications-exercise-backend`.
|
|
26
26
|
- **Service boundary** — when the calling process has no application SDK or does not own the operation, call the owning service instead of implementing an application client with generated stubs.
|
|
27
|
+
- **Dapr or Wolverine** — no released Chronicle package integrates with either; do not add or assume one. Bridge from the service that owns the events: have the kernel deliver them to an HTTP receiver as a webhook (`cratis-chronicle-publish-contract`), or call the other system from a reactor (`cratis-chronicle-react-to-fact`). In a Marten and Wolverine (Critter Stack) application, both may stay live while Chronicle takes over chosen workloads; bridge them explicitly. To trace what to move, see `cratis-modeling-trace-existing-behavior`.
|
|
28
|
+
|
|
29
|
+
## What differs from the .NET client
|
|
30
|
+
|
|
31
|
+
No client outside .NET is a full copy of the .NET client. Before committing a feature to another language, confirm it in that language's reference for the feature's skill, then exercise it against the intended kernel in a disposable namespace.
|
|
32
|
+
|
|
33
|
+
| Language | Application client | How artifacts get registered |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| .NET | Yes | Discovered from the entry assembly, its project references and the package references whose names match the configured prefixes (`Cratis` by default) |
|
|
36
|
+
| TypeScript (Node) | Yes | Class-decorated artifacts in imported modules; importing also covers a read model mapped only on properties with legacy decorators. The client scans files only when run from TypeScript sources, under Vitest or with discovery patterns set; compiled JavaScript gets no scan by default. A standard-decorated read model mapped only on properties is known before an instance is constructed only when it is an exported class in a scanned file, carries a class decorator or is registered explicitly |
|
|
37
|
+
| Kotlin and Java | Yes, one JVM client | Classpath scan, which can be narrowed to named packages |
|
|
38
|
+
| Go | Yes, but not at a stable major release: the API may change and a feature is supported only in its documented shape | Only types the code registers; no package scan, but handler methods are discovered on a registered type |
|
|
39
|
+
| Elixir | Yes | Scan of the modules of the OTP application named to the client; with none named, only modules already loaded |
|
|
40
|
+
| Python | No | Not applicable; see the Python reference |
|
|
41
|
+
|
|
42
|
+
Never assume .NET-style assembly discovery in another language; registration details are in `cratis-chronicle-connect-application`.
|
|
43
|
+
|
|
44
|
+
Aggregate roots are not part of any Chronicle client. They come from Arc's Chronicle integration, and only where that language's reference in `cratis-arc-declare-command` describes them. Everywhere else, follow that language's reference in `cratis-chronicle-protect-decision`: decide from a protected reducer, projection or decision read only where that reference supports it; otherwise read the complete relevant history and guard the append on it, because an ordinary model read does not return the history position a guard needs. Either way, do not re-implement an aggregate base class on top of the client.
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# Choose the Chronicle dependency in Mix
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Service or worker: application client](#service-or-worker-application-client)
|
|
6
|
+
- [OTP host: supervise the same client](#otp-host-supervise-the-same-client)
|
|
7
|
+
- [Protocol tool: contracts only](#protocol-tool-contracts-only)
|
|
8
|
+
- [Upgrading across the module rename](#upgrading-across-the-module-rename)
|
|
9
|
+
- [Not supported in this SDK](#not-supported-in-this-sdk)
|
|
10
|
+
|
|
3
11
|
## Service or worker: application client
|
|
4
12
|
|
|
5
|
-
In the Mix project that owns the events, add `:cratis_chronicle` to `deps/0` in `mix.exs`, using the dependency tuple from its Hex listing.
|
|
13
|
+
In the Mix project that owns the events, add `:cratis_chronicle` to `deps/0` in `mix.exs`, using the dependency tuple from its Hex listing. The client requires Elixir 1.18 or later. Run `mix deps.get` and `mix compile`. In `mix deps`, expect `:cratis_chronicle_contracts` as a dependency of the client; do not override it. Compilation checks dependency selection, not connectivity.
|
|
6
14
|
|
|
7
15
|
## OTP host: supervise the same client
|
|
8
16
|
|
|
@@ -47,6 +55,18 @@ message = %EventType{Id: "parcel-scanned", Generation: 1}
|
|
|
47
55
|
|
|
48
56
|
The match checks local encoding and decoding; it neither opens a connection nor tests kernel acceptance.
|
|
49
57
|
|
|
58
|
+
## Upgrading across the module rename
|
|
59
|
+
|
|
60
|
+
Edge case, upgrades only. The major that moved the client's modules under `Cratis.Chronicle` renamed every module from `Chronicle.` to `Cratis.Chronicle.`. The rename itself needs one change in application code; other changes between majors, in behaviour or defaults, are separate, so read the release notes of every major crossed. For the rename, replace `Chronicle.` with `Cratis.Chronicle.` wherever its own code refers to a client module (`use`, `alias`, `import`, `@behaviour`, type specs, function calls and the testing helpers). Rename bare references to the top-level module too: `alias Chronicle` or `Chronicle` passed as a value has no trailing dot, so that replacement misses it, and it must become `Cratis.Chronicle`.
|
|
61
|
+
|
|
62
|
+
Do not rename anything else. These stay as they were:
|
|
63
|
+
|
|
64
|
+
- the Hex package and OTP application `:cratis_chronicle`, and every `config :cratis_chronicle` key;
|
|
65
|
+
- the Mix task `mix chronicle.discover`;
|
|
66
|
+
- telemetry event names (`[:chronicle, ...]`);
|
|
67
|
+
- event type ids, observer ids and read model names, so stored events and registered observers keep working without a migration;
|
|
68
|
+
- the application's own modules, including ids that default from their names.
|
|
69
|
+
|
|
50
70
|
## Not supported in this SDK
|
|
51
71
|
|
|
52
72
|
- A separate combined Arc and Chronicle package: `:cratis_arc` already depends on `:cratis_chronicle`. When Arc owns the command endpoint of an event-sourced application, add `:cratis_arc` instead of declaring `:cratis_chronicle` yourself, and supervise the client child above before `Cratis.Arc.Application`; host setup is in `cratis-arc-host-application`.
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Select the Go dependency by workload
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Requirements and maturity](#requirements-and-maturity)
|
|
6
|
+
- [Service or worker: application client](#service-or-worker-application-client)
|
|
7
|
+
- [Existing Arc integration: use the host's dependency set](#existing-arc-integration-use-the-hosts-dependency-set)
|
|
8
|
+
- [Protocol tool: use only the required contracts package](#protocol-tool-use-only-the-required-contracts-package)
|
|
9
|
+
- [Not supported in this SDK](#not-supported-in-this-sdk)
|
|
10
|
+
|
|
11
|
+
## Requirements and maturity
|
|
12
|
+
|
|
13
|
+
- Requires Go 1.26 or later.
|
|
14
|
+
- The client has not reached a stable major release. Its API may change between releases, and a feature is supported only in the shape its reference describes, not everything the .NET client does with the same name. Say so when Go is proposed for a workload, and verify the exact operation the workload needs against the intended kernel before committing to it.
|
|
15
|
+
|
|
3
16
|
## Service or worker: application client
|
|
4
17
|
|
|
5
18
|
In the service directory containing `go.mod`, add the client and confirm the selected module:
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Select the JVM client from Java
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Requirements](#requirements)
|
|
6
|
+
- [Standalone worker](#standalone-worker)
|
|
7
|
+
- [Spring Boot host](#spring-boot-host)
|
|
8
|
+
- [Specification module](#specification-module)
|
|
9
|
+
- [Wire inspection only](#wire-inspection-only)
|
|
10
|
+
- [Not supported in this SDK](#not-supported-in-this-sdk)
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Java 17 or later, and `kotlinx-coroutines` 1.10.2 or later on the runtime classpath. The client brings a suitable coroutines version, so a Java project declares nothing for it; the requirement matters only when the build pins an older one.
|
|
15
|
+
- The Spring Boot starter requires Spring Boot 4. Its per-request features need the servlet stack (Spring MVC); they do not apply to WebFlux.
|
|
16
|
+
- `io.cratis:chronicle`, `io.cratis:chronicle-spring-boot-starter` and `io.cratis:chronicle-testing` are released together under one version number. Keep every one the build declares on the same version; never mix versions between them.
|
|
17
|
+
|
|
3
18
|
## Standalone worker
|
|
4
19
|
|
|
5
20
|
Resolve `io.cratis:chronicle` from Maven Central. It supplies its matching `chronicle-contracts` dependency; do not select a second contracts version. Specify `io.cratis:chronicle` in the build's dependency catalog and select the latest published artifact. Then declare it in the module that uses it; `libs.cratis.chronicle` is an alias your own catalog defines:
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Select the Chronicle dependency for Kotlin
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Requirements](#requirements)
|
|
6
|
+
- [Standalone JVM service or worker](#standalone-jvm-service-or-worker)
|
|
7
|
+
- [Existing Spring Boot host](#existing-spring-boot-host)
|
|
8
|
+
- [Specification module](#specification-module)
|
|
9
|
+
- [Protocol tool only](#protocol-tool-only)
|
|
10
|
+
- [Not supported in this SDK](#not-supported-in-this-sdk)
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Java 17 or later, and `kotlinx-coroutines` 1.10.2 or later on the runtime classpath. The client brings a suitable coroutines version; the requirement matters only when the build pins an older one.
|
|
15
|
+
- The Spring Boot starter requires Spring Boot 4. Its per-request features need the servlet stack (Spring MVC); they do not apply to WebFlux.
|
|
16
|
+
- `io.cratis:chronicle`, `io.cratis:chronicle-spring-boot-starter` and `io.cratis:chronicle-testing` are released together under one version number. Keep every one the build declares on the same version; never mix versions between them.
|
|
17
|
+
|
|
3
18
|
## Standalone JVM service or worker
|
|
4
19
|
|
|
5
20
|
Use a Kotlin/JVM module and Maven Central. Declare `io.cratis:chronicle` in the module that owns the event-store operation. With a Gradle version catalog, define `libs.cratis.chronicle` for that coordinate and use `implementation(libs.cratis.chronicle)`. The client supplies its matching `io.cratis:chronicle-contracts` dependency; do not select a separate contracts version.
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Select the Chronicle dependency for Node
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Runtime and module requirements](#runtime-and-module-requirements)
|
|
6
|
+
- [Standalone server or worker](#standalone-server-or-worker)
|
|
7
|
+
- [Existing Arc server](#existing-arc-server)
|
|
8
|
+
- [Wire inspection tool only](#wire-inspection-tool-only)
|
|
9
|
+
- [Not supported in this SDK](#not-supported-in-this-sdk)
|
|
10
|
+
|
|
11
|
+
## Runtime and module requirements
|
|
12
|
+
|
|
13
|
+
- **Node.js 22.19 or later.** On an older runtime, such as Node.js 20, the package fails when it is imported. The package itself declares no `engines` requirement, so pin the runtime in the service yourself.
|
|
14
|
+
- **TypeScript 5.2 or later**, needed for standard decorators.
|
|
15
|
+
- **Module format.** The package ships ES modules only. For a new service, set `"type": "module"` in its `package.json`. An existing CommonJS host need not convert: it can `require()` the package on a Node.js version that supports requiring ES modules.
|
|
16
|
+
- **Module resolution.** With `"moduleResolution": "NodeNext"` also set `"skipLibCheck": true`; without it the compiler reports errors inside the contracts dependency's declaration files. `"moduleResolution": "Bundler"` needs no extra setting.
|
|
17
|
+
- **Imports.** Import application types from the package root, `@cratis/chronicle`. Per-feature sub-paths such as `@cratis/chronicle/events`, `/reactors`, `/reducers`, `/projections`, `/readModels` and `/transactions` export the same types as the root. The testing helpers are the exception: they are exported only from `@cratis/chronicle/testing`.
|
|
18
|
+
|
|
3
19
|
## Standalone server or worker
|
|
4
20
|
|
|
5
21
|
In the Node server's package, install `npm install @cratis/chronicle @cratis/fundamentals`. Fundamentals is a peer dependency; let the application SDK resolve its own `@cratis/chronicle.contracts` dependency. Use the SDK's ESM entry point. Names are illustrative.
|