perf(features)!: 기능 실행부를 초기 청크에서 떼어 라우트 진입 때 적재한다 (15-01)
문제 초기 JS는 203,572 / 204,800 B(gzip)였다. 생성 인덱스가 각 기능의 feature-module.ts를 정적으로 import하고, 그 파일이 계약(zod 스키마·mapper 포함), HTTP 계약 contribution, application input 팩토리, route codec까지 모두 끌고 왔다. 참조 모양 기능 1개를 더하면 +3,922 B가 늘어 첫 기능에서 예산을 넘었다. 고른 방법 - 기능을 두 부분으로 나눈다. 선언(FeatureModule: route 표, route runtime 계약, invalidation, 문구, 부팅 때 release manifest와 맞춰 볼 contractPackages)은 초기 청크에 남는다. 실행부(FeatureRuntime: V2 API 계약, adapter contribution, contract contribution)는 feature-runtime.ts로 옮기고 loadRuntime이 동적 import한다. route codec은 context-routes.ts의 route handle에 실어 route와 함께 적재한다. - 적재 시점은 그 기능의 route에 들어갈 때다. ContextRouteGateway가 route 모듈과 함께 application.features.load(featureId)를 부르고, 끝난 뒤에 화면을 그린다(공개 포트에는 load만 추가). 들어온 URL의 기능은 route 모듈과 병렬로 적재해 왕복을 늘리지 않는다. 런타임 설정으로 꺼진 기능은 적재하지 않는다. - 조립부는 기능별 로더를 만든다(installed-feature-adapters.ts). contract registry는 기능이 적재될 때마다 전체를 다시 합쳐 검증한다 (installed-contract-contributions.ts). 선언하지 않은 contract package를 적재하면 거절한다. - 모든 실행부를 한꺼번에 읽는 registry(V2 API, contract contribution)는 installed-feature-runtime-registries.ts의 async 함수로, Node·테스트· registry 거버넌스용 상수는 top-level await 모듈 loaded-feature-runtimes.ts로 둔다. src에서 후자를 import하면 새 아키텍처 규칙 boot-does-not-load-every-feature-runtime이 막는다. 플랫폼 구성 화면은 route 로더에서 async 함수를 불러 결과를 prop으로 받는다. - vite.config.ts에 청크 그룹 2개를 둔다. rolldown은 부팅 그래프와 lazy 청크가 같이 쓰는 모듈을 importer 집합마다 따로 청크로 뗀다. 그대로 두면 기능마다 선언 청크가 하나씩 늘고(기능당 +1,471 B), 실행부와 공유하는 플랫폼 모듈(HTTP executor, contract runtime, zod)이 6개 청크로 쪼개져 템플릿 자체가 +438 B 커졌다. feature-declarations는 모든 기능의 선언을, feature-platform은 실행부가 같이 쓰는 부팅 모듈을 한 청크로 묶는다. render-boot-failure.tsx가 쓰는 모듈은 feature-platform에서 뺀다(09-03: 애플리케이션 그래프가 평가 중 던져도 실패 화면은 떠야 한다). 버린 대안 - 부팅 때 feature 청크를 미리 동적 import하고 기다린 뒤 렌더: 분류기는 lazy로 세지만 첫 렌더 경로의 바이트는 그대로다. 예산을 속이는 것이라 버렸다. - 실행부 일부만 지연(adapter와 contribution만): 모두 같은 zod 스키마를 공유해 줄지 않았다. 실측 +4,031 B로 오히려 늘었다. - 선언과 실행부를 같은 lazy 청크(context-routes)에 두기: 기능당 -60 B 수준이라 그룹 없이 목표에 못 미쳤다. - 페이지 문구까지 실행부로 옮기기: 기능당 약 300~450 B를 더 줄이지만 i18n catalog를 런타임 등록 구조로 바꿔야 해 이번 범위에서 뺐다. - boot.tsx를 별도 진입점으로 추가: 분류기가 boot의 동적 import를 모두 초기로 세어 218,303 B가 됐다. 위험·한계 - FeatureModule 모양이 바뀐다. 다운스트림 기능은 feature-runtime.ts로 실행부를 옮겨야 한다(BREAKING CHANGE). - 기능 계약 간 중복(operation, schema, contribution) 검사가 부팅이 아니라 그 기능의 적재 시점과 Node 검사(loaded-feature-runtimes를 읽는 스크립트· 테스트)로 옮겨 간다. - 기능 route에 처음 들어갈 때 실행부 청크(약 5 KB gzip)를 받는다. 플랫폼 구성 화면은 모든 기능의 실행부를 받은 뒤 그린다. lab 게이트(FE-GATE-026)가 재는 화면이라 LCP가 조금 늘 수 있다. 측정하지 않았다. - 청크 그룹은 rolldown 자동 분할을 일부 대신한다. feature-declarations가 비면 기능당 증가 상한 테스트가 실패한다. feature-platform이 비면 템플릿 총량(약 2 KB)만 늘고 번들 예산 검사가 잡는다. - config/contracts/registry-baseline.json의 FE-REG-API/SCHEMA source는 아직 installed-feature-contracts.ts다. 승인 digest가 걸려 있어 소유자 재승인 때 고친다. check-registries는 통과한다. - 예산 안에 들어가는 참조 모양 기능은 약 3개다. 플랫폼 자체가 예산의 98.8%다. 수치 (vite build, classifyViteJavascript + gzipSync 기본 수준) - 템플릿: 203,572 B(13파일) -> 202,361 B(16파일), -1,211 B - 참조 복사본 +1: 207,494 B(+3,922) -> 203,102 B(+741) - 참조 복사본 +2: 210,818 B(+3,324) -> 203,750 B(+648) - 참조 복사본 +5: 205,629 B - lazy JS: 23,516 B -> 28,204 B 검증 - RED: node scripts/run-vitest.ts run tests/unit/feature-shape-growth.test.ts "adds at most 1 KiB ... (15-01)" 실패: expected 3934 to be less than or equal to 1024 - GREEN: 같은 테스트 통과(+741 B) - node scripts/run-vitest.ts run tests/unit: 168파일 2,383 통과 - node scripts/run-vitest.ts run tests/component tests/features tests/integration tests/contract tests/runtime-schema tests/architecture tests/platform tests/recipes (security-followup-archive 제외, pnpm 호출): 109파일 787 통과 - npx tsc --noEmit: app, node, test, recipes, web-worker, service-worker 통과 - npx eslint 바뀐 파일 통과 - check-architecture.ts(pnpm exec 대신 eslint를 부르는 shim): PASS, 새 규칙이 boot.tsx의 import를 거절하는 것 확인 - check-adapter-inventory, check-registries, verify-documentation-readiness, check-ci-contract: PASS - e2e Chromium 전체(pnpm 없는 build-frontend + vite preview, 별도 포트): 55 통과 - storybook build 성공 - 미실행: Firefox·WebKit e2e, 시각 회귀, lab 성능(FE-GATE-026), pnpm 경로의 check:bundle, test:system BREAKING CHANGE: FeatureModule은 id, contracts(선언), routes, messages, loadRuntime만 가진다. adapters, contractContributions와 V2 API 계약 (apiOperations, schemas, runtimeSchemas, mappers)은 defineFeatureRuntime으로 만든 feature-runtime.ts로, route codec은 context-routes.ts의 route handle codecs로 옮긴다. contracts에는 contractPackages를 추가한다. Refs: docs/reviews/2026-11-01-maturity-review/15-performance.md 15-01, 16-structure-patterns.md 9절
This commit is contained in:
@@ -2,25 +2,36 @@ export type FeatureContractIdentity = Readonly<{ featureId: string }>;
|
||||
|
||||
type EmptyRecord = Readonly<Record<never, never>>;
|
||||
|
||||
/**
|
||||
* 15-01. A feature has two halves. The declaration (`FeatureModule`) is what
|
||||
* the shell needs before any of the feature's routes is entered: its route
|
||||
* table, its messages, its cache invalidation identities and the external
|
||||
* contract packages the release manifest is checked against at boot. It is
|
||||
* imported statically and lands in the initial chunk, so it stays data.
|
||||
*
|
||||
* Everything executable (API contracts with their runtime schemas and mappers,
|
||||
* the application input factory, the HTTP contract contributions) is the
|
||||
* runtime half (`FeatureRuntime`). `loadRuntime` imports it dynamically when
|
||||
* one of the feature's routes is entered. Before 15-01 both halves loaded at
|
||||
* boot and each feature added about 3.9 KB gzip to the initial chunk.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zero-feature products are a supported topology. The fallback contract keeps
|
||||
* every composer's property access valid without pretending that any feature
|
||||
* route, operation, schema, mapper, or invalidation edge exists.
|
||||
* route, invalidation edge or contract package exists.
|
||||
*/
|
||||
export type EmptyFeatureContract = FeatureContractIdentity &
|
||||
Readonly<{
|
||||
routes: EmptyRecord;
|
||||
routeRuntimeContracts: EmptyRecord;
|
||||
apiOperations: EmptyRecord;
|
||||
invalidation: Readonly<{
|
||||
topics: readonly [];
|
||||
namespaces: readonly [];
|
||||
edges: readonly [];
|
||||
}>;
|
||||
topicVersions: readonly [];
|
||||
schemas: EmptyRecord;
|
||||
runtimeSchemas: EmptyRecord;
|
||||
mappers: EmptyRecord;
|
||||
contractPackages: readonly [];
|
||||
}>;
|
||||
|
||||
export type FeatureMessageCatalogs = Readonly<
|
||||
@@ -31,12 +42,32 @@ type EmptyFeatureMessageCatalogs = Readonly<
|
||||
Record<string, Readonly<Record<never, never>>>
|
||||
>;
|
||||
|
||||
type EmptyFeatureRuntimeDescriptor = Readonly<{
|
||||
featureId: string;
|
||||
routeCodecs: EmptyRecord;
|
||||
routeRuntime: EmptyRecord;
|
||||
/** The V2 API contract: operations, schema metadata, runtime codecs, mappers. */
|
||||
export type EmptyFeatureApiContract = Readonly<{
|
||||
apiOperations: EmptyRecord;
|
||||
schemas: EmptyRecord;
|
||||
runtimeSchemas: EmptyRecord;
|
||||
mappers: EmptyRecord;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* The executable half. `featureId` must equal the declaring module's id; the
|
||||
* loader checks it, and checks that every adapter and contract contribution in
|
||||
* it belongs to that feature.
|
||||
*/
|
||||
export type FeatureRuntime<
|
||||
ApiContract = EmptyFeatureApiContract,
|
||||
Adapter = never,
|
||||
ContractContribution = never,
|
||||
> = Readonly<{
|
||||
featureId: string;
|
||||
apiContract: ApiContract;
|
||||
adapters: readonly Adapter[];
|
||||
contractContributions: readonly ContractContribution[];
|
||||
}>;
|
||||
|
||||
export type AnyFeatureRuntime = FeatureRuntime<unknown, unknown, unknown>;
|
||||
|
||||
/**
|
||||
* The default parameters deliberately describe the empty-product fallback.
|
||||
* Concrete generated modules retain their literal types; only an empty
|
||||
@@ -45,28 +76,32 @@ type EmptyFeatureRuntimeDescriptor = Readonly<{
|
||||
export type FeatureModule<
|
||||
Contract extends FeatureContractIdentity = EmptyFeatureContract,
|
||||
Routes extends Readonly<Record<string, unknown>> = EmptyRecord,
|
||||
Adapter = never,
|
||||
Runtime = EmptyFeatureRuntimeDescriptor,
|
||||
Messages extends FeatureMessageCatalogs = EmptyFeatureMessageCatalogs,
|
||||
ContractContribution = never,
|
||||
Runtime extends AnyFeatureRuntime = FeatureRuntime,
|
||||
> = Readonly<{
|
||||
id: string;
|
||||
contracts: Contract;
|
||||
routes: Routes;
|
||||
adapters: readonly Adapter[];
|
||||
runtimes: readonly Runtime[];
|
||||
messages: Messages;
|
||||
contractContributions: readonly ContractContribution[];
|
||||
/**
|
||||
* Must dynamically import the feature's `feature-runtime.ts`: a static
|
||||
* import here would put the runtime half back into the initial chunk
|
||||
* (tests/unit/feature-shape-growth.test.ts measures it).
|
||||
*/
|
||||
loadRuntime(): Promise<Runtime>;
|
||||
}>;
|
||||
|
||||
/** Structural supertype used when accepting any concrete feature descriptor. */
|
||||
export type AnyFeatureModule = FeatureModule<
|
||||
FeatureContractIdentity,
|
||||
Readonly<Record<string, unknown>>,
|
||||
unknown,
|
||||
unknown,
|
||||
FeatureMessageCatalogs,
|
||||
unknown
|
||||
AnyFeatureRuntime
|
||||
>;
|
||||
|
||||
/** The runtime half a module's `loadRuntime` resolves to. */
|
||||
export type FeatureModuleRuntime<Module extends AnyFeatureModule> = Awaited<
|
||||
ReturnType<Module["loadRuntime"]>
|
||||
>;
|
||||
|
||||
export function defineFeatureModule<const Module extends AnyFeatureModule>(
|
||||
@@ -77,10 +112,32 @@ export function defineFeatureModule<const Module extends AnyFeatureModule>(
|
||||
`Feature module id ${module.id} does not match contract featureId ${module.contracts.featureId}`,
|
||||
);
|
||||
}
|
||||
return Object.freeze({ ...module }) as unknown as Readonly<Module>;
|
||||
}
|
||||
|
||||
export function defineFeatureRuntime<const Runtime extends AnyFeatureRuntime>(
|
||||
runtime: Runtime,
|
||||
): Readonly<Runtime> {
|
||||
return Object.freeze({
|
||||
...module,
|
||||
adapters: Object.freeze([...module.adapters]),
|
||||
runtimes: Object.freeze([...module.runtimes]),
|
||||
contractContributions: Object.freeze([...module.contractContributions]),
|
||||
}) as unknown as Readonly<Module>;
|
||||
...runtime,
|
||||
adapters: Object.freeze([...runtime.adapters]),
|
||||
contractContributions: Object.freeze([...runtime.contractContributions]),
|
||||
}) as unknown as Readonly<Runtime>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a module's runtime half and refuses one that belongs to another
|
||||
* feature. Composers call this instead of `module.loadRuntime()` directly.
|
||||
*/
|
||||
export async function loadFeatureRuntime<const Module extends AnyFeatureModule>(
|
||||
module: Module,
|
||||
): Promise<FeatureModuleRuntime<Module>> {
|
||||
const runtime = (await module.loadRuntime()) as FeatureModuleRuntime<Module>;
|
||||
const owner = (runtime as AnyFeatureRuntime).featureId;
|
||||
if (owner !== module.id) {
|
||||
throw new TypeError(
|
||||
`Feature module ${module.id} loaded the runtime of ${String(owner)}`,
|
||||
);
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,117 @@ import {
|
||||
composeContractContributions,
|
||||
type InstalledContractContribution,
|
||||
type InstalledContractPackageIdentity,
|
||||
type InstalledHttpContract,
|
||||
} from "../contracts/external-contract-runtime.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURE_MODULES } from "./installed-product-manifest.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURES } from "./installed-product-manifest.ts";
|
||||
|
||||
export const INSTALLED_CONTRACT_CONTRIBUTIONS: readonly InstalledContractContribution[] =
|
||||
Object.freeze(
|
||||
INSTALLED_PRODUCT_FEATURE_MODULES.flatMap(
|
||||
(module) => module.contractContributions,
|
||||
/**
|
||||
* 15-01. Contract contributions are executable (validators, effect
|
||||
* classifiers) and load with each feature's runtime half. The release
|
||||
* manifest is still checked at boot, before any feature loads, so the external
|
||||
* packages a feature pins are declared up front in its declaration
|
||||
* (`contracts.contractPackages`). A loaded contribution that pins a package no
|
||||
* feature declared is refused (`createInstalledContractRegistry`), and
|
||||
* `loaded-feature-runtimes.ts` checks the two sets are equal.
|
||||
*/
|
||||
function composeDeclaredPackages(
|
||||
declarations: readonly (readonly InstalledContractPackageIdentity[])[],
|
||||
): readonly InstalledContractPackageIdentity[] {
|
||||
const byId = new Map<string, InstalledContractPackageIdentity>();
|
||||
for (const identity of declarations.flat()) {
|
||||
const existing = byId.get(identity.packageId);
|
||||
if (existing && !samePackage(existing, identity)) {
|
||||
throw new TypeError(
|
||||
`contract package ${identity.packageId} is declared with conflicting identities`,
|
||||
);
|
||||
}
|
||||
byId.set(identity.packageId, Object.freeze({ ...identity }));
|
||||
}
|
||||
return Object.freeze([...byId.values()]);
|
||||
}
|
||||
|
||||
function samePackage(
|
||||
left: InstalledContractPackageIdentity,
|
||||
right: InstalledContractPackageIdentity,
|
||||
): boolean {
|
||||
return (
|
||||
left.packageId === right.packageId &&
|
||||
left.version === right.version &&
|
||||
left.digest === right.digest &&
|
||||
left.runtimeProtocolVersion === right.runtimeProtocolVersion &&
|
||||
left.sourceRevision === right.sourceRevision
|
||||
);
|
||||
}
|
||||
|
||||
export const EXPECTED_CONTRACT_SET_PACKAGES: readonly InstalledContractPackageIdentity[] =
|
||||
composeDeclaredPackages(
|
||||
INSTALLED_PRODUCT_FEATURES.map(
|
||||
(contract) =>
|
||||
contract.contractPackages as readonly InstalledContractPackageIdentity[],
|
||||
),
|
||||
);
|
||||
|
||||
export const COMPOSED_CONTRACT_CONTRIBUTIONS = composeContractContributions(
|
||||
INSTALLED_CONTRACT_CONTRIBUTIONS,
|
||||
);
|
||||
/** Throws unless every package the composed contributions pin was declared. */
|
||||
export function assertDeclaredContractPackages(
|
||||
featureId: string,
|
||||
pinned: readonly InstalledContractPackageIdentity[],
|
||||
declared: readonly InstalledContractPackageIdentity[] = EXPECTED_CONTRACT_SET_PACKAGES,
|
||||
): void {
|
||||
for (const identity of pinned) {
|
||||
if (!declared.some((entry) => samePackage(entry, identity))) {
|
||||
throw new TypeError(
|
||||
`${featureId} contributes contract package ${identity.packageId}, which no installed feature declares in contracts.contractPackages`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const EXPECTED_CONTRACT_SET_PACKAGES: readonly InstalledContractPackageIdentity[] =
|
||||
COMPOSED_CONTRACT_CONTRIBUTIONS.externalPackages;
|
||||
export type InstalledContractRegistry = Readonly<{
|
||||
/**
|
||||
* Adds one feature's contributions. The whole installed set is composed
|
||||
* again, so a duplicate operation or contribution id across features is
|
||||
* refused exactly as it was when every contribution composed at boot.
|
||||
*/
|
||||
install(
|
||||
featureId: string,
|
||||
contributions: readonly InstalledContractContribution[],
|
||||
): void;
|
||||
resolveHttp(
|
||||
operationId: string,
|
||||
): InstalledHttpContract<unknown, unknown, unknown> | undefined;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* The composition root owns the only instance; the HTTP executor gets
|
||||
* `resolveHttp`, the feature loader `install`. Nothing else can add a row
|
||||
* (LIVE-03 kept the composed registry read-only for the same reason).
|
||||
*/
|
||||
export function createInstalledContractRegistry(
|
||||
declaredPackages: readonly InstalledContractPackageIdentity[] = EXPECTED_CONTRACT_SET_PACKAGES,
|
||||
): InstalledContractRegistry {
|
||||
let installed: readonly InstalledContractContribution[] = Object.freeze([]);
|
||||
let composed = composeContractContributions(installed);
|
||||
return Object.freeze({
|
||||
install(featureId, contributions) {
|
||||
for (const contribution of contributions) {
|
||||
if (contribution.featureId !== featureId) {
|
||||
throw new TypeError(
|
||||
`feature ${featureId} loaded a contract contribution of ${contribution.featureId}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const next = Object.freeze([...installed, ...contributions]);
|
||||
const nextComposed = composeContractContributions(next);
|
||||
assertDeclaredContractPackages(
|
||||
featureId,
|
||||
nextComposed.externalPackages,
|
||||
declaredPackages,
|
||||
);
|
||||
installed = next;
|
||||
composed = nextComposed;
|
||||
},
|
||||
resolveHttp(operationId) {
|
||||
return composed.httpByOperationId.get(operationId);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,47 +1,86 @@
|
||||
import type { InstalledContractContribution } from "../contracts/external-contract-runtime.ts";
|
||||
import {
|
||||
composeFeatureAdapterInputs,
|
||||
type ContributionsCapabilityContext,
|
||||
type InstalledFeatureInputs,
|
||||
} from "./feature-adapter-contribution.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURE_MODULES } from "./installed-product-manifest.ts";
|
||||
import {
|
||||
loadFeatureRuntime,
|
||||
type FeatureModuleRuntime,
|
||||
} from "./feature-module.ts";
|
||||
import {
|
||||
INSTALLED_PRODUCT_FEATURE_MODULES,
|
||||
type ProductFeatureModule,
|
||||
} from "./installed-product-manifest.ts";
|
||||
|
||||
type InstalledFeatureRuntime = FeatureModuleRuntime<ProductFeatureModule>;
|
||||
|
||||
// 09-01. Indexed access distributes over the installed-module union, so this is
|
||||
// every installed contribution. `flatMap` alone infers its element type from
|
||||
// the first union member and rejected the second installed feature.
|
||||
type InstalledFeatureAdapterContribution =
|
||||
(typeof INSTALLED_PRODUCT_FEATURE_MODULES)[number]["adapters"][number];
|
||||
|
||||
const INSTALLED_FEATURE_ADAPTER_CONTRIBUTIONS: readonly InstalledFeatureAdapterContribution[] =
|
||||
Object.freeze(
|
||||
INSTALLED_PRODUCT_FEATURE_MODULES.flatMap(
|
||||
(module): readonly InstalledFeatureAdapterContribution[] => module.adapters,
|
||||
),
|
||||
);
|
||||
InstalledFeatureRuntime["adapters"][number];
|
||||
|
||||
type InstalledFeatureCapabilityContext = ContributionsCapabilityContext<
|
||||
typeof INSTALLED_FEATURE_ADAPTER_CONTRIBUTIONS
|
||||
readonly InstalledFeatureAdapterContribution[]
|
||||
>;
|
||||
|
||||
/** One feature's input, created when its runtime half has loaded. */
|
||||
export type InstalledFeatureLoader = () => Promise<InstalledFeatureInputs>;
|
||||
|
||||
/**
|
||||
* Adapter installation is a projection of feature-owned descriptors. Adding a
|
||||
* feature changes its descriptor and the generated index, not this composer
|
||||
* 15-01. Adapter installation is a projection of feature-owned descriptors, as
|
||||
* before, but each feature's descriptors now arrive with its runtime half. The
|
||||
* composition root hands these loaders to the application; the router calls
|
||||
* `application.features.load` before it renders the feature's routes. Adding a
|
||||
* feature still changes only its descriptor and the generated index
|
||||
* (tests/unit/two-feature-install-typecheck.test.ts installs a second one).
|
||||
*
|
||||
* Q-6.9-5. The runtime composer passes `activeFeatureIds` (installed minus
|
||||
* `FEATURE_OVERRIDES`). A feature switched off there gets no input, so
|
||||
* `application.features.get()` cannot hand out its API; the router was the
|
||||
* only place that honoured the switch before. The default (every installed
|
||||
* feature) is for callers that have no runtime configuration.
|
||||
* Q-6.9-5. Only `activeFeatureIds` (installed minus `FEATURE_OVERRIDES`) get a
|
||||
* loader. A feature switched off there has no input, so
|
||||
* `application.features.get()` cannot hand out its API. The default (every
|
||||
* installed feature) is for callers that have no runtime configuration.
|
||||
*
|
||||
* `installContracts` receives the runtime's contract contributions before its
|
||||
* input is created, so the HTTP executor can resolve the feature's operations
|
||||
* by the time the feature can call them.
|
||||
*/
|
||||
export function createInstalledFeatureInputs(
|
||||
export function createInstalledFeatureLoaders(
|
||||
context: InstalledFeatureCapabilityContext,
|
||||
activeFeatureIds: readonly string[] = INSTALLED_PRODUCT_FEATURE_MODULES.map(
|
||||
(module) => module.id,
|
||||
),
|
||||
): InstalledFeatureInputs {
|
||||
return composeFeatureAdapterInputs(
|
||||
INSTALLED_FEATURE_ADAPTER_CONTRIBUTIONS,
|
||||
activeFeatureIds,
|
||||
context,
|
||||
installContracts: (
|
||||
featureId: string,
|
||||
contributions: readonly InstalledContractContribution[],
|
||||
) => void = () => undefined,
|
||||
): Readonly<Record<string, InstalledFeatureLoader>> {
|
||||
const active = new Set(activeFeatureIds);
|
||||
return Object.freeze(
|
||||
Object.fromEntries(
|
||||
INSTALLED_PRODUCT_FEATURE_MODULES.filter((module) =>
|
||||
active.has(module.id),
|
||||
).map((module) => [
|
||||
module.id,
|
||||
async (): Promise<InstalledFeatureInputs> => {
|
||||
const runtime: InstalledFeatureRuntime =
|
||||
await loadFeatureRuntime(module);
|
||||
const adapters: readonly InstalledFeatureAdapterContribution[] =
|
||||
runtime.adapters;
|
||||
for (const adapter of adapters) {
|
||||
if (adapter.featureId !== module.id) {
|
||||
throw new TypeError(
|
||||
`feature ${module.id} loaded an adapter contribution of ${adapter.featureId}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
installContracts(
|
||||
module.id,
|
||||
runtime.contractContributions as readonly InstalledContractContribution[],
|
||||
);
|
||||
return composeFeatureAdapterInputs(adapters, [module.id], context);
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import {
|
||||
composeApiOperations,
|
||||
validateApiRuntimeBindings,
|
||||
} from "../contracts/api-operations.ts";
|
||||
import { composeBoundaryMapperRegistry } from "../contracts/boundary-mapper.ts";
|
||||
import { PLATFORM_ROUTE_RUNTIME_CONTRACT } from "../contracts/route-runtime-contract.ts";
|
||||
import { validateRestProfileBindings } from "../contracts/rest-profiles.ts";
|
||||
import { PLATFORM_ROUTE_REGISTRY } from "../contracts/routes.ts";
|
||||
import {
|
||||
composeRuntimeSchemaCodecs,
|
||||
composeSchemaRegistry,
|
||||
PLATFORM_SCHEMA_REGISTRY,
|
||||
} from "../contracts/schema-registry.ts";
|
||||
import { composeUniqueRecord } from "../platform/cardinality/compose-unique-record.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURES } from "./installed-product-manifest.ts";
|
||||
|
||||
/**
|
||||
* 15-01. Boot-time registries composed from the features' declarations: the
|
||||
* route table, route runtime contracts, cache invalidation and navigation.
|
||||
* The V2 API registries need the executable half of every feature and live in
|
||||
* `loaded-feature-runtimes.ts`, which the app boot never imports.
|
||||
*/
|
||||
export const INSTALLED_FEATURE_CONTRACTS = INSTALLED_PRODUCT_FEATURES;
|
||||
|
||||
// 09-01. The registries keep composeUniqueRecord's own type, the intersection
|
||||
@@ -38,13 +33,6 @@ export const ROUTE_RUNTIME_CONTRACT = composeUniqueRecord(
|
||||
() => "route runtime contract",
|
||||
);
|
||||
|
||||
export const API_OPERATIONS = composeApiOperations(
|
||||
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.apiOperations),
|
||||
);
|
||||
export const REST_PROFILE_BINDINGS_VALID = validateRestProfileBindings(
|
||||
API_OPERATIONS,
|
||||
Object.freeze({ PRIMARY_API: Object.freeze(["omit"] as const) }),
|
||||
);
|
||||
// 09-01. Element types are spelled out for the same reason as in
|
||||
// installed-feature-adapters.ts: flatMap over the installed-contract union
|
||||
// otherwise returns the member arrays unflattened.
|
||||
@@ -78,22 +66,6 @@ export const INVALIDATION_TOPIC_VERSIONS = Object.freeze(
|
||||
(contract): readonly InstalledTopicVersion[] => contract.topicVersions,
|
||||
),
|
||||
);
|
||||
export const SCHEMA_REGISTRY = composeSchemaRegistry([
|
||||
PLATFORM_SCHEMA_REGISTRY,
|
||||
...INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.schemas),
|
||||
]);
|
||||
export const RUNTIME_SCHEMA_CODECS = composeRuntimeSchemaCodecs(
|
||||
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.runtimeSchemas),
|
||||
);
|
||||
export const MAPPER_REGISTRY = composeBoundaryMapperRegistry(
|
||||
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.mappers),
|
||||
);
|
||||
export const API_RUNTIME_BINDINGS_VALID = validateApiRuntimeBindings(
|
||||
API_OPERATIONS,
|
||||
SCHEMA_REGISTRY,
|
||||
RUNTIME_SCHEMA_CODECS,
|
||||
MAPPER_REGISTRY,
|
||||
);
|
||||
|
||||
export const ROUTE_FEATURE_OWNER: Readonly<Record<string, string>> =
|
||||
Object.freeze(
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import {
|
||||
composeApiOperations,
|
||||
validateApiRuntimeBindings,
|
||||
} from "../contracts/api-operations.ts";
|
||||
import { composeBoundaryMapperRegistry } from "../contracts/boundary-mapper.ts";
|
||||
import {
|
||||
composeContractContributions,
|
||||
type InstalledContractContribution,
|
||||
} from "../contracts/external-contract-runtime.ts";
|
||||
import { validateRestProfileBindings } from "../contracts/rest-profiles.ts";
|
||||
import {
|
||||
composeRuntimeSchemaCodecs,
|
||||
composeSchemaRegistry,
|
||||
PLATFORM_SCHEMA_REGISTRY,
|
||||
} from "../contracts/schema-registry.ts";
|
||||
import { loadFeatureRuntime } from "./feature-module.ts";
|
||||
import {
|
||||
assertDeclaredContractPackages,
|
||||
EXPECTED_CONTRACT_SET_PACKAGES,
|
||||
} from "./installed-contract-contributions.ts";
|
||||
import { INSTALLED_PRODUCT_FEATURE_MODULES } from "./installed-product-manifest.ts";
|
||||
|
||||
/**
|
||||
* 15-01. Loads every installed feature's runtime half and composes the
|
||||
* registries that need all of them: the V2 API registries and the contract
|
||||
* contributions. Duplicates across features throw here, as they did at boot
|
||||
* before 15-01.
|
||||
*
|
||||
* The app boot never calls this: at runtime the composition root loads one
|
||||
* feature at a time when its routes are entered (`installed-feature-adapters.ts`).
|
||||
* The platform overview route calls it before it renders, and Node scripts and
|
||||
* tests read the same result through `loaded-feature-runtimes.ts`.
|
||||
*/
|
||||
export async function loadInstalledFeatureRuntimeRegistries() {
|
||||
const runtimes = Object.freeze(
|
||||
await Promise.all(INSTALLED_PRODUCT_FEATURE_MODULES.map(loadFeatureRuntime)),
|
||||
);
|
||||
type LoadedApiContract = (typeof runtimes)[number]["apiContract"];
|
||||
const apiContracts: readonly LoadedApiContract[] = runtimes.map(
|
||||
(runtime) => runtime.apiContract,
|
||||
);
|
||||
|
||||
const apiOperations = composeApiOperations(
|
||||
apiContracts.map((contract) => contract.apiOperations),
|
||||
);
|
||||
const restProfileBindingsValid = validateRestProfileBindings(
|
||||
apiOperations,
|
||||
Object.freeze({ PRIMARY_API: Object.freeze(["omit"] as const) }),
|
||||
);
|
||||
const schemaRegistry = composeSchemaRegistry([
|
||||
PLATFORM_SCHEMA_REGISTRY,
|
||||
...apiContracts.map((contract) => contract.schemas),
|
||||
]);
|
||||
const runtimeSchemaCodecs = composeRuntimeSchemaCodecs(
|
||||
apiContracts.map((contract) => contract.runtimeSchemas),
|
||||
);
|
||||
const mapperRegistry = composeBoundaryMapperRegistry(
|
||||
apiContracts.map((contract) => contract.mappers),
|
||||
);
|
||||
const apiRuntimeBindingsValid = validateApiRuntimeBindings(
|
||||
apiOperations,
|
||||
schemaRegistry,
|
||||
runtimeSchemaCodecs,
|
||||
mapperRegistry,
|
||||
);
|
||||
|
||||
const contractContributions: readonly InstalledContractContribution[] =
|
||||
Object.freeze(
|
||||
runtimes.flatMap(
|
||||
(runtime): readonly InstalledContractContribution[] =>
|
||||
runtime.contractContributions,
|
||||
),
|
||||
);
|
||||
const composedContractContributions = composeContractContributions(
|
||||
contractContributions,
|
||||
);
|
||||
// The declared packages (checked against the release manifest at boot) and
|
||||
// the packages the loaded contributions actually pin must be the same set.
|
||||
assertDeclaredContractPackages(
|
||||
"installed features",
|
||||
composedContractContributions.externalPackages,
|
||||
);
|
||||
for (const declared of EXPECTED_CONTRACT_SET_PACKAGES) {
|
||||
if (
|
||||
!composedContractContributions.externalPackages.some(
|
||||
(pinned) => pinned.packageId === declared.packageId,
|
||||
)
|
||||
) {
|
||||
throw new TypeError(
|
||||
`contract package ${declared.packageId} is declared, but no loaded contribution pins it`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
runtimes,
|
||||
apiOperations,
|
||||
restProfileBindingsValid,
|
||||
schemaRegistry,
|
||||
runtimeSchemaCodecs,
|
||||
mapperRegistry,
|
||||
apiRuntimeBindingsValid,
|
||||
contractContributions,
|
||||
composedContractContributions,
|
||||
});
|
||||
}
|
||||
|
||||
export type InstalledFeatureRuntimeRegistries = Awaited<
|
||||
ReturnType<typeof loadInstalledFeatureRuntimeRegistries>
|
||||
>;
|
||||
@@ -1,36 +0,0 @@
|
||||
import { composeUniqueRecord } from "../platform/cardinality/compose-unique-record.ts";
|
||||
import { PLATFORM_ROUTE_CODECS } from "../presentation/routes/platform-route-codecs.ts";
|
||||
import { PLATFORM_ROUTE_RUNTIME } from "../presentation/routes/route-runtime.tsx";
|
||||
import { INSTALLED_PRODUCT_FEATURE_MODULES } from "./installed-product-manifest.ts";
|
||||
|
||||
// 09-01. See installed-feature-adapters.ts: the element type is spelled out so
|
||||
// a second installed feature widens it instead of failing inference.
|
||||
type InstalledFeatureRuntimeContribution =
|
||||
(typeof INSTALLED_PRODUCT_FEATURE_MODULES)[number]["runtimes"][number];
|
||||
|
||||
const INSTALLED_FEATURE_RUNTIME_CONTRIBUTIONS: readonly InstalledFeatureRuntimeContribution[] =
|
||||
Object.freeze(
|
||||
INSTALLED_PRODUCT_FEATURE_MODULES.flatMap(
|
||||
(module): readonly InstalledFeatureRuntimeContribution[] => module.runtimes,
|
||||
),
|
||||
);
|
||||
|
||||
export const ROUTE_CODECS = composeUniqueRecord(
|
||||
[
|
||||
PLATFORM_ROUTE_CODECS,
|
||||
...INSTALLED_FEATURE_RUNTIME_CONTRIBUTIONS.map(
|
||||
(contribution) => contribution.routeCodecs,
|
||||
),
|
||||
],
|
||||
() => "route codec",
|
||||
);
|
||||
|
||||
export const ROUTE_RUNTIME = composeUniqueRecord(
|
||||
[
|
||||
PLATFORM_ROUTE_RUNTIME,
|
||||
...INSTALLED_FEATURE_RUNTIME_CONTRIBUTIONS.map(
|
||||
(contribution) => contribution.routeRuntime,
|
||||
),
|
||||
],
|
||||
() => "route runtime",
|
||||
);
|
||||
@@ -31,3 +31,5 @@ export const INSTALLED_PRODUCT_FEATURE_IDS: readonly string[] = Object.freeze(
|
||||
|
||||
export const INSTALLED_PRODUCT_FEATURE_ID_SET: ReadonlySet<string> =
|
||||
new Set(INSTALLED_PRODUCT_FEATURE_IDS);
|
||||
|
||||
export type { ProductFeatureModule };
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { loadInstalledFeatureRuntimeRegistries } from "./installed-feature-runtime-registries.ts";
|
||||
|
||||
/**
|
||||
* 15-01. The registries composed from every installed feature's runtime half,
|
||||
* as module constants (top-level await), for Node scripts, tests and the
|
||||
* registry governance (`config/contracts/registry-governance.json` reads
|
||||
* `API_OPERATIONS` and `SCHEMA_REGISTRY` here).
|
||||
*
|
||||
* Nothing under `src` may import this module (architecture rule
|
||||
* `boot-does-not-load-every-feature-runtime`). On the boot path it would make
|
||||
* the first render wait for every feature's code, which the initial-chunk
|
||||
* budget cannot see because the runtimes are dynamic imports; and any
|
||||
* top-level await in the browser graph turns off rolldown's chunk
|
||||
* optimizations for the whole build.
|
||||
*/
|
||||
const registries = await loadInstalledFeatureRuntimeRegistries();
|
||||
|
||||
export const LOADED_FEATURE_RUNTIMES = registries.runtimes;
|
||||
export const API_OPERATIONS = registries.apiOperations;
|
||||
export const REST_PROFILE_BINDINGS_VALID = registries.restProfileBindingsValid;
|
||||
export const SCHEMA_REGISTRY = registries.schemaRegistry;
|
||||
export const RUNTIME_SCHEMA_CODECS = registries.runtimeSchemaCodecs;
|
||||
export const MAPPER_REGISTRY = registries.mapperRegistry;
|
||||
export const API_RUNTIME_BINDINGS_VALID = registries.apiRuntimeBindingsValid;
|
||||
export const INSTALLED_CONTRACT_CONTRIBUTIONS = registries.contractContributions;
|
||||
export const COMPOSED_CONTRACT_CONTRIBUTIONS =
|
||||
registries.composedContractContributions;
|
||||
@@ -13,7 +13,8 @@ reference implementation이다.
|
||||
adapter, 독립 form schema/command mapper와 list/detail/form/status page
|
||||
|
||||
generic application은 비어 있는 `ApplicationFeatureInputs`와 typed
|
||||
`features.has/get` registry만 소유한다. 이 feature의 application API가 module
|
||||
`features.has/get/load` registry만 소유한다. input은 reference route에 처음
|
||||
들어갈 때 router가 `features.load`로 실행부를 적재한 뒤에 생긴다. 이 feature의 application API가 module
|
||||
augmentation으로 `"reference-feature": ReferenceFeatureInput`을 기여하므로
|
||||
등록되지 않은 ID와 잘못된 input shape는 typecheck에서 거절된다. feature hook은
|
||||
별도 cast나 runtime shape 확인 없이 정확한 input type을 받는다. 다만 동적 호출로
|
||||
@@ -44,15 +45,20 @@ route codec과 URL builder는 `src/presentation/routes/route-codecs.ts`, route t
|
||||
|
||||
feature가 실제 contribution을 소유한다.
|
||||
|
||||
- contract: `reference-feature-contract.ts`
|
||||
- route codec: `REFERENCE_FEATURE_RUNTIME_DESCRIPTOR` (`feature-module.ts`가 설치)
|
||||
- page component: `REFERENCE_FEATURE_ROUTE_RUNTIME` (`context-routes.ts`가 lazy로 적재)
|
||||
- bootstrap input: `REFERENCE_FEATURE_ADAPTER_CONTRIBUTION`
|
||||
- 선언(초기 청크, `feature-module.ts`): route 표와 invalidation은
|
||||
`reference-feature-contract.ts`, 문구는 `reference-message-catalog.ts`
|
||||
- 실행부(`feature-runtime.ts`, reference route에 들어갈 때 적재): API 계약
|
||||
`reference-api-contract.ts`, bootstrap input
|
||||
`REFERENCE_FEATURE_ADAPTER_CONTRIBUTION`, HTTP contract contribution
|
||||
- route codec과 page component: `REFERENCE_FEATURE_ROUTE_CODECS`,
|
||||
`REFERENCE_FEATURE_ROUTE_RUNTIME` (`context-routes.ts`가 route handle에 실어
|
||||
lazy로 적재)
|
||||
|
||||
중앙 파일인 `installed-feature-contracts.ts`,
|
||||
`installed-feature-runtimes.tsx`, `installed-feature-adapters.ts`는 선택된
|
||||
contribution을 합치는 역할만 한다. 새 기능의 내부 조립 규칙을 중앙 catalog에
|
||||
추가하지 않는다.
|
||||
`feature-module.ts`는 `feature-runtime.ts`를 동적 import로만 가리킨다. 정적
|
||||
import로 바꾸면 실행부 전체가 다시 초기 청크에 들어간다(15-01). 중앙 파일인
|
||||
`installed-feature-contracts.ts`, `installed-feature-adapters.ts`,
|
||||
`installed-contract-contributions.ts`는 선택된 contribution을 합치는 역할만
|
||||
한다. 새 기능의 내부 조립 규칙을 중앙 catalog에 추가하지 않는다.
|
||||
|
||||
## 검증과 제거
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { RouteObject } from "react-router-dom";
|
||||
|
||||
import { REFERENCE_FEATURE_CONTRACT } from "./contracts/reference-feature-contract.ts";
|
||||
import { REFERENCE_FEATURE_ROUTE_RUNTIME } from "./presentation/reference-feature-runtime.ts";
|
||||
import {
|
||||
REFERENCE_FEATURE_ROUTE_CODECS,
|
||||
REFERENCE_FEATURE_ROUTE_RUNTIME,
|
||||
} from "./presentation/reference-feature-runtime.ts";
|
||||
|
||||
export const FEATURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze(
|
||||
Object.values(REFERENCE_FEATURE_CONTRACT.routes).map((definition) => {
|
||||
@@ -14,6 +17,8 @@ export const FEATURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze(
|
||||
handle: Object.freeze({
|
||||
routeId: definition.routeId,
|
||||
runtime,
|
||||
// 15-01. The route's params/search codecs load with its routes.
|
||||
codecs: REFERENCE_FEATURE_ROUTE_CODECS,
|
||||
}),
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import { defineRestOperation } from "../../../contracts/api-operations.ts";
|
||||
import { REFERENCE_RUNTIME_SCHEMA_CODECS } from "./reference-schemas.ts";
|
||||
import { REFERENCE_BOUNDARY_MAPPERS } from "./reference-mapper.ts";
|
||||
|
||||
/**
|
||||
* 15-01. The V2 API contract of the reference feature: operations, schema
|
||||
* metadata, runtime schema codecs and boundary mappers. Runtime half only
|
||||
* (`feature-runtime.ts`); the app boot never imports it.
|
||||
*/
|
||||
export const REFERENCE_API_CONTRACT = Object.freeze({
|
||||
runtimeSchemas: REFERENCE_RUNTIME_SCHEMA_CODECS,
|
||||
mappers: REFERENCE_BOUNDARY_MAPPERS,
|
||||
schemas: Object.freeze({
|
||||
ReferenceResourceParams: Object.freeze({
|
||||
schemaId: "ReferenceResourceParams",
|
||||
boundary: "route-params",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourceListQuery: Object.freeze({
|
||||
schemaId: "ReferenceResourceListQuery",
|
||||
boundary: "route-search-api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
CreateReferenceResourceCommand: Object.freeze({
|
||||
schemaId: "CreateReferenceResourceCommand",
|
||||
boundary: "api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
NoRequest: Object.freeze({
|
||||
schemaId: "NoRequest",
|
||||
boundary: "api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourceListPayload: Object.freeze({
|
||||
schemaId: "ReferenceResourceListPayload",
|
||||
boundary: "api-response",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "RESPONSE",
|
||||
unknownFieldPolicy: "STRIP_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourcePayload: Object.freeze({
|
||||
schemaId: "ReferenceResourcePayload",
|
||||
boundary: "api-response",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "RESPONSE",
|
||||
unknownFieldPolicy: "STRIP_UNKNOWN",
|
||||
}),
|
||||
}),
|
||||
apiOperations: Object.freeze({
|
||||
LIST_REFERENCE_RESOURCES: defineRestOperation({
|
||||
method: "GET",
|
||||
path: "/api/reference-resources",
|
||||
operationId: "LIST_REFERENCE_RESOURCES",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "safe",
|
||||
retry: "runtime",
|
||||
requestSource: "search",
|
||||
requestSchema: "ReferenceResourceListQuery",
|
||||
responseSchema: "ReferenceResourceListPayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "QUERY",
|
||||
replayPolicy: "SAFE",
|
||||
idempotencyKeyPolicy: "NONE",
|
||||
mapperId: "ReferenceResourceListMapper",
|
||||
successStatuses: [200],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 262_144,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "NoRequest",
|
||||
pathParameterNames: [],
|
||||
maxEncodedSearchBytes: 4_096,
|
||||
}),
|
||||
CREATE_REFERENCE_RESOURCE: defineRestOperation({
|
||||
method: "POST",
|
||||
path: "/api/reference-resources",
|
||||
operationId: "CREATE_REFERENCE_RESOURCE",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "keyed",
|
||||
retry: "runtime",
|
||||
requestSource: "body",
|
||||
requestSchema: "CreateReferenceResourceCommand",
|
||||
responseSchema: "ReferenceResourcePayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "COMMAND",
|
||||
replayPolicy: "KEYED_COMMAND",
|
||||
idempotencyKeyPolicy: "REQUIRED",
|
||||
mapperId: "ReferenceResourceMapper",
|
||||
successStatuses: [200, 201],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 32_768,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "NoRequest",
|
||||
pathParameterNames: [],
|
||||
maxEncodedSearchBytes: 0,
|
||||
}),
|
||||
GET_REFERENCE_RESOURCE: defineRestOperation({
|
||||
method: "GET",
|
||||
path: "/api/reference-resources/{resourceId}",
|
||||
operationId: "GET_REFERENCE_RESOURCE",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "safe",
|
||||
retry: "runtime",
|
||||
requestSource: "none",
|
||||
requestSchema: "NoRequest",
|
||||
responseSchema: "ReferenceResourcePayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "QUERY",
|
||||
replayPolicy: "SAFE",
|
||||
idempotencyKeyPolicy: "NONE",
|
||||
mapperId: "ReferenceResourceMapper",
|
||||
successStatuses: [200],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 32_768,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "ReferenceResourceParams",
|
||||
pathParameterNames: ["resourceId"],
|
||||
maxEncodedSearchBytes: 0,
|
||||
}),
|
||||
}),
|
||||
} as const);
|
||||
@@ -1,8 +1,5 @@
|
||||
import { defineQueryNamespaceIdentity } from "../../../contracts/query-keys.ts";
|
||||
import { defineQueryInvalidationTopic } from "../../../contracts/query-invalidation.ts";
|
||||
import { defineRestOperation } from "../../../contracts/api-operations.ts";
|
||||
import { REFERENCE_RUNTIME_SCHEMA_CODECS } from "./reference-schemas.ts";
|
||||
import { REFERENCE_BOUNDARY_MAPPERS } from "./reference-mapper.ts";
|
||||
|
||||
export const REFERENCE_FEATURE_ID = "reference-feature";
|
||||
export const REFERENCE_RESOURCE_QUERY_NAMESPACE = defineQueryNamespaceIdentity(
|
||||
@@ -12,66 +9,14 @@ export const REFERENCE_RESOURCE_QUERY_NAMESPACE = defineQueryNamespaceIdentity(
|
||||
export const REFERENCE_RESOURCE_INVALIDATION_TOPIC =
|
||||
defineQueryInvalidationTopic("qinv.01k10f7m3w9p6r2c8v5n4x");
|
||||
|
||||
/**
|
||||
* 15-01. The declaration half: what the shell reads before a reference route
|
||||
* is entered. It is in the initial chunk, so it holds data only. The API
|
||||
* contract with its runtime schemas and mappers is
|
||||
* `reference-api-contract.ts`, loaded with `feature-runtime.ts`.
|
||||
*/
|
||||
export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
|
||||
featureId: REFERENCE_FEATURE_ID,
|
||||
runtimeSchemas: REFERENCE_RUNTIME_SCHEMA_CODECS,
|
||||
mappers: REFERENCE_BOUNDARY_MAPPERS,
|
||||
schemas: Object.freeze({
|
||||
ReferenceResourceParams: Object.freeze({
|
||||
schemaId: "ReferenceResourceParams",
|
||||
boundary: "route-params",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourceListQuery: Object.freeze({
|
||||
schemaId: "ReferenceResourceListQuery",
|
||||
boundary: "route-search-api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
CreateReferenceResourceCommand: Object.freeze({
|
||||
schemaId: "CreateReferenceResourceCommand",
|
||||
boundary: "api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
NoRequest: Object.freeze({
|
||||
schemaId: "NoRequest",
|
||||
boundary: "api-request",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "REQUEST",
|
||||
unknownFieldPolicy: "REJECT_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourceListPayload: Object.freeze({
|
||||
schemaId: "ReferenceResourceListPayload",
|
||||
boundary: "api-response",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "RESPONSE",
|
||||
unknownFieldPolicy: "STRIP_UNKNOWN",
|
||||
}),
|
||||
ReferenceResourcePayload: Object.freeze({
|
||||
schemaId: "ReferenceResourcePayload",
|
||||
boundary: "api-response",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
runtime: "zod",
|
||||
schemaVersion: 1,
|
||||
direction: "RESPONSE",
|
||||
unknownFieldPolicy: "STRIP_UNKNOWN",
|
||||
}),
|
||||
}),
|
||||
routes: Object.freeze({
|
||||
REFERENCE_RESOURCE_LIST: Object.freeze({
|
||||
routeId: "REFERENCE_RESOURCE_LIST",
|
||||
@@ -153,92 +98,6 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
|
||||
searchCodec: "none",
|
||||
}),
|
||||
}),
|
||||
apiOperations: Object.freeze({
|
||||
LIST_REFERENCE_RESOURCES: defineRestOperation({
|
||||
method: "GET",
|
||||
path: "/api/reference-resources",
|
||||
operationId: "LIST_REFERENCE_RESOURCES",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "safe",
|
||||
retry: "runtime",
|
||||
requestSource: "search",
|
||||
requestSchema: "ReferenceResourceListQuery",
|
||||
responseSchema: "ReferenceResourceListPayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "QUERY",
|
||||
replayPolicy: "SAFE",
|
||||
idempotencyKeyPolicy: "NONE",
|
||||
mapperId: "ReferenceResourceListMapper",
|
||||
successStatuses: [200],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 262_144,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "NoRequest",
|
||||
pathParameterNames: [],
|
||||
maxEncodedSearchBytes: 4_096,
|
||||
}),
|
||||
CREATE_REFERENCE_RESOURCE: defineRestOperation({
|
||||
method: "POST",
|
||||
path: "/api/reference-resources",
|
||||
operationId: "CREATE_REFERENCE_RESOURCE",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "keyed",
|
||||
retry: "runtime",
|
||||
requestSource: "body",
|
||||
requestSchema: "CreateReferenceResourceCommand",
|
||||
responseSchema: "ReferenceResourcePayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "COMMAND",
|
||||
replayPolicy: "KEYED_COMMAND",
|
||||
idempotencyKeyPolicy: "REQUIRED",
|
||||
mapperId: "ReferenceResourceMapper",
|
||||
successStatuses: [200, 201],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 32_768,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "NoRequest",
|
||||
pathParameterNames: [],
|
||||
maxEncodedSearchBytes: 0,
|
||||
}),
|
||||
GET_REFERENCE_RESOURCE: defineRestOperation({
|
||||
method: "GET",
|
||||
path: "/api/reference-resources/{resourceId}",
|
||||
operationId: "GET_REFERENCE_RESOURCE",
|
||||
auth: "external-session",
|
||||
timeoutMs: null,
|
||||
idempotency: "safe",
|
||||
retry: "runtime",
|
||||
requestSource: "none",
|
||||
requestSchema: "NoRequest",
|
||||
responseSchema: "ReferenceResourcePayload",
|
||||
owner: "feature-frontend-reference-feature-vertical-slice",
|
||||
contractVersion: 2,
|
||||
protocol: "REST",
|
||||
semantics: "QUERY",
|
||||
replayPolicy: "SAFE",
|
||||
idempotencyKeyPolicy: "NONE",
|
||||
mapperId: "ReferenceResourceMapper",
|
||||
successStatuses: [200],
|
||||
responseMediaTypes: ["application/json"],
|
||||
maxResponseBytes: 32_768,
|
||||
providerId: "PRIMARY_API",
|
||||
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
||||
csrfProfileId: "NO_CSRF_BEARER",
|
||||
pathSchema: "ReferenceResourceParams",
|
||||
pathParameterNames: ["resourceId"],
|
||||
maxEncodedSearchBytes: 0,
|
||||
}),
|
||||
}),
|
||||
invalidation: Object.freeze({
|
||||
topics: Object.freeze([REFERENCE_RESOURCE_INVALIDATION_TOPIC]),
|
||||
namespaces: Object.freeze([REFERENCE_RESOURCE_QUERY_NAMESPACE]),
|
||||
@@ -255,4 +114,6 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
|
||||
topicVersion: 1,
|
||||
}),
|
||||
]),
|
||||
// TEMPLATE_FIXTURE contributions are not part of the contract set.
|
||||
contractPackages: Object.freeze([]),
|
||||
} as const);
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { defineFeatureModule } from "../feature-module.ts";
|
||||
import { REFERENCE_FEATURE_ADAPTER_CONTRIBUTION } from "./adapters/create-reference-feature-input.ts";
|
||||
import {
|
||||
REFERENCE_FEATURE_CONTRACT,
|
||||
REFERENCE_FEATURE_ID,
|
||||
} from "./contracts/reference-feature-contract.ts";
|
||||
import { REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION } from "./contracts/reference-feature-contract-contribution.ts";
|
||||
import { REFERENCE_MESSAGE_CATALOGS } from "./contracts/reference-message-catalog.ts";
|
||||
import { REFERENCE_FEATURE_RUNTIME_DESCRIPTOR } from "./presentation/reference-feature-runtime-descriptor.ts";
|
||||
|
||||
export const FEATURE_MODULE_ID =
|
||||
"reference-feature" satisfies typeof REFERENCE_FEATURE_ID;
|
||||
/** Owning bounded context (route root and budget live in its declaration). */
|
||||
export const FEATURE_CONTEXT_ID = "reference-context";
|
||||
|
||||
/**
|
||||
* 15-01. Declaration only: this file and what it imports statically are in the
|
||||
* initial chunk. The executable half is `feature-runtime.ts`, imported here
|
||||
* dynamically and loaded when a reference route is entered.
|
||||
*/
|
||||
export const REFERENCE_FEATURE_MODULE = defineFeatureModule({
|
||||
id: FEATURE_MODULE_ID,
|
||||
contracts: REFERENCE_FEATURE_CONTRACT,
|
||||
routes: REFERENCE_FEATURE_CONTRACT.routes,
|
||||
adapters: [REFERENCE_FEATURE_ADAPTER_CONTRIBUTION],
|
||||
runtimes: [REFERENCE_FEATURE_RUNTIME_DESCRIPTOR],
|
||||
messages: REFERENCE_MESSAGE_CATALOGS,
|
||||
contractContributions: [REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION],
|
||||
loadRuntime: async () => (await import("./feature-runtime.ts")).FEATURE_RUNTIME,
|
||||
} as const);
|
||||
|
||||
export const FEATURE_MODULE = REFERENCE_FEATURE_MODULE;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineFeatureRuntime } from "../feature-module.ts";
|
||||
import { REFERENCE_FEATURE_ADAPTER_CONTRIBUTION } from "./adapters/create-reference-feature-input.ts";
|
||||
import { REFERENCE_API_CONTRACT } from "./contracts/reference-api-contract.ts";
|
||||
import { REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION } from "./contracts/reference-feature-contract-contribution.ts";
|
||||
import { REFERENCE_FEATURE_ID } from "./contracts/reference-feature-contract.ts";
|
||||
|
||||
/**
|
||||
* 15-01. The executable half of the reference feature. `feature-module.ts`
|
||||
* imports this file dynamically; the router loads it when a reference route
|
||||
* is entered (`application.features.load`), so none of it is in the initial
|
||||
* chunk.
|
||||
*/
|
||||
export const FEATURE_RUNTIME = defineFeatureRuntime({
|
||||
featureId: REFERENCE_FEATURE_ID,
|
||||
apiContract: REFERENCE_API_CONTRACT,
|
||||
adapters: [REFERENCE_FEATURE_ADAPTER_CONTRIBUTION],
|
||||
contractContributions: [REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION],
|
||||
} as const);
|
||||
@@ -1,21 +0,0 @@
|
||||
import { REFERENCE_FEATURE_ID } from "../contracts/reference-feature-contract.ts";
|
||||
import {
|
||||
referenceResourceListQuerySchema,
|
||||
referenceResourceParamsSchema,
|
||||
} from "../contracts/reference-schemas.ts";
|
||||
|
||||
export const REFERENCE_FEATURE_ROUTE_CODECS = {
|
||||
ReferenceResourceListQuery: referenceResourceListQuerySchema,
|
||||
ReferenceResourceParams: referenceResourceParamsSchema,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Boot-safe feature runtime metadata. Page components are deliberately absent:
|
||||
* executable route chunks are owned and loaded by the bounded context route
|
||||
* module, so Node-side composition and app boot do not pull the page graph in.
|
||||
*/
|
||||
export const REFERENCE_FEATURE_RUNTIME_DESCRIPTOR = Object.freeze({
|
||||
featureId: REFERENCE_FEATURE_ID,
|
||||
routeCodecs: REFERENCE_FEATURE_ROUTE_CODECS,
|
||||
routeRuntime: Object.freeze({}),
|
||||
});
|
||||
@@ -1,9 +1,21 @@
|
||||
import { lazy } from "react";
|
||||
|
||||
import { REFERENCE_FEATURE_ID } from "../contracts/reference-feature-contract.ts";
|
||||
import { REFERENCE_FEATURE_ROUTE_CODECS } from "./reference-feature-runtime-descriptor.ts";
|
||||
import {
|
||||
referenceResourceListQuerySchema,
|
||||
referenceResourceParamsSchema,
|
||||
} from "../contracts/reference-schemas.ts";
|
||||
|
||||
export { REFERENCE_FEATURE_ROUTE_CODECS } from "./reference-feature-runtime-descriptor.ts";
|
||||
/**
|
||||
* 15-01. Route codecs travel with the context routes (`context-routes.ts` puts
|
||||
* them on each route handle), not with the boot-time feature module: zod
|
||||
* schemas are executable and the shell needs none of them before a reference
|
||||
* route is entered.
|
||||
*/
|
||||
export const REFERENCE_FEATURE_ROUTE_CODECS = {
|
||||
ReferenceResourceListQuery: referenceResourceListQuerySchema,
|
||||
ReferenceResourceParams: referenceResourceParamsSchema,
|
||||
} as const;
|
||||
|
||||
export const REFERENCE_FEATURE_ROUTE_RUNTIME = {
|
||||
REFERENCE_RESOURCE_LIST: Object.freeze({
|
||||
|
||||
Reference in New Issue
Block a user