import type { RuntimePluginReference } from '../../facade'; import type { NormalizeBasePluginInput } from './basePluginCompiler.internal'; import type { AnyBasePluginDefinition, InferApi, InferConflicts, InferEnabled, InferPluginStoreState, InferRead, InferSelectors, InferUpdate, NormalizePluginState, PluginReference, } from './PluginDefinition'; type IsAny = 0 extends 1 & TValue ? true : false; type PreservesCallable = TCurrent extends ( ...args: infer TCurrentArgs ) => infer TCurrentResult ? TNext extends (...args: infer TNextArgs) => infer TNextResult ? TCurrentArgs extends TNextArgs ? TNextResult extends TCurrentResult ? true : false : false : false : false; type PreservesPluginValue = IsAny extends true ? false : [TCurrent] extends [(...args: infer _TArgs) => infer _TResult] ? PreservesCallable : [TCurrent] extends [object] ? [TNext] extends [object] ? false extends { [TKey in keyof TCurrent & keyof TNext]-?: PreservesPluginValue< TCurrent[TKey], TNext[TKey] >; }[keyof TCurrent & keyof TNext] ? false : true : false : [TNext] extends [TCurrent] ? true : false; /** Reject contribution members that cannot preserve an inherited capability. */ export type CompatiblePluginContribution = { [TKey in keyof TNext]: TKey extends keyof TCurrent ? PreservesPluginValue extends true ? TNext[TKey] : never : TNext[TKey]; }; export type PluginContributionCompatibility = TNext extends CompatiblePluginContribution ? unknown : never; export type PluginCompatibilityArguments = [ TCompatibility, ] extends [never] ? [compatibility: never] : []; type Materialize = Readonly<{ [TKey in keyof TObject]: TObject[TKey]; }>; type DefinitionField< C, TContribution, TKey extends PropertyKey, TValue, > = TKey extends keyof C | keyof TContribution ? Readonly> : {}; type ObjectField = TContribution extends Readonly> ? TValue : {}; type Conflicts = TContribution extends Readonly<{ conflicts: infer TConflicts extends ReadonlyArray< RuntimePluginReference | PluginReference >; }> ? TConflicts : readonly []; type Enabled = TContribution extends Readonly<{ enabled: infer TEnabled }> ? Extract extends never ? boolean : Extract : boolean; type TargetPlugins = TContribution extends Readonly<{ targetPlugins: infer TTargetPlugins extends ReadonlyArray< PluginReference | string >; }> ? TTargetPlugins : readonly []; /** * Merge one normalized authoring contribution into the exact current * definition. Capability objects and state accumulate; consumer switches * replace; model identity stays owned by the original definition. */ export type MergePluginDefinitions< C extends AnyBasePluginDefinition, TContribution, TNormalized = NormalizeBasePluginInput, > = Materialize< Omit< C, | 'api' | 'conflicts' | 'enabled' | 'initialState' | 'name' | 'read' | 'selectors' | 'targetPlugins' | 'update' > & Omit< TNormalized, | 'api' | 'conflicts' | 'dependencies' | 'enabled' | 'initialState' | 'name' | 'read' | 'schema' | 'selectors' | 'targetPlugins' | 'update' > & Readonly<{ name: C['name'] }> & DefinitionField< C, TNormalized, 'api', InferApi & ObjectField > & DefinitionField< C, TNormalized, 'read', InferRead & ObjectField > & DefinitionField< C, TNormalized, 'update', InferUpdate & ObjectField > & DefinitionField< C, TNormalized, 'initialState', NormalizePluginState< InferPluginStoreState & Omit< ObjectField, keyof InferPluginStoreState > > > & DefinitionField< C, TNormalized, 'selectors', InferSelectors & ObjectField > & ('conflicts' extends keyof TNormalized ? Readonly<{ conflicts: Conflicts }> : 'conflicts' extends keyof C ? Readonly<{ conflicts: InferConflicts }> : {}) & ('enabled' extends keyof TNormalized ? Readonly<{ enabled: Enabled }> : 'enabled' extends keyof C ? Readonly<{ enabled: InferEnabled }> : {}) & ('targetPlugins' extends keyof TNormalized ? Readonly<{ targetPlugins: TargetPlugins; }> : 'targetPlugins' extends keyof C ? Pick : {}) >;