Build composable Camino packages with explicit type and source dependencies
This commit is contained in:
@@ -137,6 +137,7 @@ export function generatePackageQueryClientBindings(
|
||||
export function generateComponentClientBindings(plan: ExecutionPlan, packageRevision: string): string {
|
||||
const pkg = plan.definition.workspace.packageImports.find((pkg) => pkg.revisionId === packageRevision);
|
||||
const components = plan.definition.packages.find((pkg) => pkg.revision === packageRevision)?.components;
|
||||
const modules = plan.definition.packages.find((pkg) => pkg.revision === packageRevision)?.modules ?? [];
|
||||
if (!pkg || !components?.length)
|
||||
throw new ExecutionPlanError("NO_COMPONENT_CONTRACT", packageRevision, "Package declares no component entries");
|
||||
const byId = new Map(plan.definition.workspace.interfaceImports.map((iface) => [iface.revisionId as string, iface]));
|
||||
@@ -166,12 +167,15 @@ export function generateComponentClientBindings(plan: ExecutionPlan, packageRevi
|
||||
subjectBindings +
|
||||
"\n" +
|
||||
queries +
|
||||
"\nexport interface Components {\n" +
|
||||
"\nexport interface ModuleProps {}\n" +
|
||||
"export type ExtraModuleProps<K extends string> = K extends keyof ModuleProps ? ModuleProps[K] : {};\n" +
|
||||
"export interface Modules {\n" +
|
||||
components
|
||||
.map(
|
||||
(component) =>
|
||||
`${JSON.stringify(component.displayName)}: ComponentType<ComponentProps<${JSON.stringify(component.subject)}>>;`,
|
||||
)
|
||||
.map((component) => {
|
||||
const module = modules.find((module) => module.id === component.id)!;
|
||||
const key = JSON.stringify([module.interfaceRevisionId, module.memberId]);
|
||||
return `${JSON.stringify(component.displayName)}: ComponentType<ComponentProps<${JSON.stringify(component.subject)}> & ExtraModuleProps<${JSON.stringify(key)}>>;`;
|
||||
})
|
||||
.join("\n") +
|
||||
"\n}\n"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user