fix(features): check declared needs and show the IndexedDB capability assembly (09-05)
A missing capability reached the feature factory as an anonymous TypeError. The composer now names the feature and the capability, and the IndexedDB provider example moves from a browser spec into an opt-in recipe with a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
30cf71b249
commit
bc7c46b2d5
@@ -557,6 +557,11 @@ export async function createRuntimeAdapters(
|
||||
...(telemetryCollector === undefined ? {} : { collector: telemetryCollector }),
|
||||
});
|
||||
// Each installed contribution receives only the capabilities it declares.
|
||||
// 09-05. `indexedDb` is not built here: IndexedDB is an opt-in reference
|
||||
// runtime (`productionComposition: false`). Installing a feature that needs
|
||||
// it makes this object fail the app typecheck until the product adds
|
||||
// `indexedDb`, built as in recipes/frontend-capabilities/
|
||||
// indexeddb-feature-capability.ts.
|
||||
const featureCapabilities = Object.freeze({
|
||||
http: contractOperations,
|
||||
telemetry: featureTelemetry,
|
||||
|
||||
@@ -174,6 +174,20 @@ export function composeFeatureAdapterInputs<
|
||||
}
|
||||
seen.add(contribution.featureId);
|
||||
if (!enabled.has(contribution.featureId)) continue;
|
||||
// 09-05. The context type already asks for every declared need, but a
|
||||
// host that widens it (or JavaScript) used to reach the feature's factory
|
||||
// and fail there as an anonymous TypeError.
|
||||
const provided = context as Readonly<
|
||||
Partial<Record<FeaturePlatformCapabilityId, unknown>>
|
||||
>;
|
||||
const missing = contribution.needs.find(
|
||||
(need) => provided[need] === undefined,
|
||||
);
|
||||
if (missing !== undefined) {
|
||||
throw new TypeError(
|
||||
`feature ${contribution.featureId} needs ${missing}, which the host did not provide`,
|
||||
);
|
||||
}
|
||||
|
||||
const installed = invokeContribution(
|
||||
contribution as unknown as FeatureAdapterContribution<
|
||||
|
||||
Reference in New Issue
Block a user