fix(adapters): defer config validation to call-time (#64)#65
Merged
Conversation
The mongodb and cf adapter factories threw on missing config at construction time, which runs during config build. That breaks `generate:types` / `generate:importmap` in environments without runtime variables (e.g. CI publishing payload-types as a separate package), since the adapter is instantiated before Payload exists. Move validation to call-time: - mongodb: uri/dbName/pools/dimensions checks run inside each data method via getCtx(); getConfigExtension builds resolved pools defensively and never throws at build time. - cf: drop the factory-time binding throw; the existing runtime getVectorizeBinding() check already enforces it at call-time. - pg: unaffected (no env-derived args at construction). Closes #64
Merged
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.
Closes #64.
Problem
The mongodb and cf adapter factories threw on missing config at construction time. Because the adapter is instantiated as a top-level statement in
payload.config.ts— before Payload (and its logger) exist, and before the plugin'sdisabledflag is ever consulted — this breakspnpm generate:typesandpnpm generate:importmapin any environment without the runtime variables present (e.g. CI that buildspayload-typesto publish as a separate package).Notably,
disabledcan't work around this: the throw happens in the adapter factory, upstream of the plugin.Fix
Move validation to call-time (every call, not memoized):
uri/dbName/pools/dimensionschecks now run inside each data method via agetCtx()helper.getConfigExtension(which runs at config-build time) builds the resolved pools defensively and never throws.binding is requiredthrow. The existing runtimegetVectorizeBinding()check already enforces the binding at call-time for the methods that need it (storeChunk/search/deleteChunks).Tests (TDD)
adapters/mongodb/dev/specs/validation.spec.ts(10 tests): construction with missing uri/dbName/pools/dimensions does not throw,getConfigExtensiondoes not throw with fully-missing config, and each data method still throws the right error at call-time.All green: mongodb 106/106 (incl. DB-backed compliance), cf adapter 16/16; both adapters typecheck clean.