refactor: 프론트 템플릿 리펙토링
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
import type { ApplicationFeatureInputs } from "../application/ports/in/application-api.ts";
|
||||
import { createReferenceFeatureInstalledInput } from "./reference-feature/adapters/create-reference-feature-input.ts";
|
||||
import { REFERENCE_FEATURE_ID } from "./reference-feature/contracts/reference-feature-contract.ts";
|
||||
import { REFERENCE_FEATURE_ADAPTER_CONTRIBUTION } from "./reference-feature/adapters/create-reference-feature-input.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURE_IDS } from "./installed-product-manifest.ts";
|
||||
|
||||
/**
|
||||
* §3.5. Partial on purpose: a feature the manifest did not select supplies no
|
||||
* driving input, so consumers have to narrow before calling one. A total type
|
||||
* here would let feature code compile against an input that is not there.
|
||||
*/
|
||||
type InstalledFeatureInputs = Readonly<
|
||||
Partial<Pick<ApplicationFeatureInputs, typeof REFERENCE_FEATURE_ID>>
|
||||
>;
|
||||
const COMPILED_FEATURE_ADAPTER_CONTRIBUTIONS = Object.freeze([
|
||||
REFERENCE_FEATURE_ADAPTER_CONTRIBUTION,
|
||||
] as const);
|
||||
|
||||
type FeatureAdapterContext = Parameters<
|
||||
(typeof COMPILED_FEATURE_ADAPTER_CONTRIBUTIONS)[number]["createInput"]
|
||||
>[0];
|
||||
|
||||
type InstalledFeatureInputs = Readonly<Partial<ApplicationFeatureInputs>>;
|
||||
|
||||
/**
|
||||
* Central adapter composition only selects and aggregates feature-owned
|
||||
* contributions. The feature owns how its application input is bound to
|
||||
* reusable platform capabilities.
|
||||
*/
|
||||
export function createInstalledFeatureInputs(
|
||||
context: Parameters<typeof createReferenceFeatureInstalledInput>[0],
|
||||
context: FeatureAdapterContext,
|
||||
): InstalledFeatureInputs {
|
||||
if (!INSTALLED_PRODUCT_FEATURE_IDS.includes(REFERENCE_FEATURE_ID)) {
|
||||
return Object.freeze({});
|
||||
}
|
||||
const referenceFeature = createReferenceFeatureInstalledInput(context);
|
||||
return Object.freeze({
|
||||
[referenceFeature.featureId]: referenceFeature.input,
|
||||
});
|
||||
const entries = COMPILED_FEATURE_ADAPTER_CONTRIBUTIONS
|
||||
.filter((contribution) =>
|
||||
INSTALLED_PRODUCT_FEATURE_IDS.includes(contribution.featureId),
|
||||
)
|
||||
.map((contribution) => {
|
||||
const installed = contribution.createInput(context);
|
||||
return [installed.featureId, installed.input] as const;
|
||||
});
|
||||
|
||||
return Object.freeze(Object.fromEntries(entries)) as InstalledFeatureInputs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user