Repository navigation
Store Chronicle read models in the collection Arc reads them from - #144
Merged
Merged
Conversation
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an app uses Arc's MongoDB integration together with its Chronicle integration, Chronicle now stores each projected read model in the collection Arc reads it from.
Before, Chronicle's TypeScript client named the container after the read model identifier (
User), while Arc's MongoDB naming policy read a pluralized collection (Users). Apps needed thecollectionName: type => type.nameworkaround.Changes
resolveMongoCollectionName(options, type)in@cratis/arc.mongodbis now the only place that computescollectionName?.(type) ?? namingPolicy.collectionName(type).withMongoDBuses it for its collection tokens and registers it as a service under a newreadModelCollectionNameResolvertoken in@cratis/arc.core. That avoids a dependency fromarc.chronicleonarc.mongodb.withChroniclelooks the rule up lazily when the runtime is built, so the order in which the two integrations are registered doesn't matter. The Chronicle client Arc creates getsreadModelNamingPolicy = (identifier, type) => rule(type) ?? identifier, using@cratis/chronicle6.29.0's new option.withMongoDB'sreadModels, which are the ones Arc reads, are renamed. Anything else keeps its identifier.ChronicleRegistration.readModelNamingPolicyoverrides the rule. If you pass your ownclient, Arc leaves it alone. Passing a policy together with your own client throws, because Arc can't apply it; the docs show the one-liner to set it yourself.withMongoDB: no policy is passed, so the identifier is used as before.@cratis/chroniclegoes to 6.29.0, and its peer floor rises to^6.29.0.mongodb/naming-policies.md,chronicle/registration-options.mdandchronicle/read-models/index.mddescribe the behaviour.Upgrade notes (for the release notes)
@cratis/chroniclemust be 6.29.0 or later.withMongoDB+withChroniclewith the default policy, Chronicle now writes read models to the pluralized collection Arc was already reading. That collection is populated once the projection is replayed. The previous, unread collection is left as it is.collectionName: type => type.nameget identical names.collectionNameoverride now fails when the Chronicle client registers its read models.Specs
withMongoDBrule, including classes outsidereadModels.withMongoDB+withChroniclein both orders.Checked locally, split into CI's
yarn cisteps:yarn test(2896 tests)docs:lintdocs:examplesanddocs:snippets, each with its self-testset-version --checkNot run locally: the Library Docker e2e (the local kernel container's MongoDB refused connections),
tutorial-e2eanddrizzle-integration. CI runs them.Review: same-provider (Anthropic-only). No defects were found; the minor findings are addressed. It's labelled
minor: packages are 0.x and the Chronicle integration is experimental, and the peer floor and the collection change are called out above.Refs Cratis/Documentation#19, Cratis/Chronicle.TypeScript#149