3333
3434import type { ActionActivationRow , ActionActivationStore , ActionActivationWriteOptions } from './action-activation.js' ;
3535import type { ObjectQL } from './engine.js' ;
36+ import { standaloneActionOwnerKey } from './action-governance.js' ;
3637
3738/**
3839 * One registered action handler. [#30065] `override` marks a declared action
3940 * override's handler ({@link ActionsFacet.registerActionOverride}); `beneath`
40- * is the handler it was bound over, or one registered for the key after it,
41- * kept so removing the override restores it.
41+ * is the handler it was bound over, or the declared base's registered for the
42+ * key after it, kept so removing the override restores it. [#30542] `base` is
43+ * the package the override declares (`overrides.package`): only a handler of
44+ * the action that package ships slots beneath it.
4245 */
4346export interface ActionHandlerEntry {
4447 handler : ( ctx : any ) => Promise < any > | any ;
4548 package ?: string ;
4649 override ?: true ;
50+ base ?: string ;
4751 beneath ?: ActionHandlerEntry ;
4852}
4953
@@ -58,21 +62,24 @@ export interface ActionsHost {
5862 readonly actionActivation : ObjectQL [ 'actionActivation' ] ;
5963 readonly actions : ObjectQL [ 'actions' ] ;
6064 readonly logger : ObjectQL [ 'logger' ] ;
65+ readonly registry : ObjectQL [ 'registry' ] ;
6166}
6267
6368/** The bodies of the "Action system and packaged-action activation" section of `ObjectQL`: a stateless facet, called by the class's stubs. */
6469export class ActionsFacet {
6570 /** The body of `ObjectQL#registerAction`; the method's docblock there is its contract. */
66- static registerAction ( this : Pick < ActionsHost , 'actions' | 'logger' > , objectName : string , actionName : string , handler : ( ctx : any ) => Promise < any > | any , packageName ?: string ) : void {
71+ static registerAction ( this : Pick < ActionsHost , 'actions' | 'logger' | 'registry' > , objectName : string , actionName : string , handler : ( ctx : any ) => Promise < any > | any , packageName ?: string ) : void {
6772 const key = `${ objectName } :${ actionName } ` ;
6873 const replaced = this . actions . get ( key ) ;
69- // [#30065, ADR-0146 D9 `action`] Another package 's handler arriving under
70- // a key a declared override holds — a marketplace base's, bound by its
74+ // [#30065, ADR-0146 D9 `action`] The declared base 's handler arriving
75+ // under a key the override holds — a marketplace base's, bound by its
7176 // `kernel:ready` rehydrate after the authored-action resync bound the
72- // override, or a bundle's handlers re-bound — is the base's: it slots
73- // beneath the override, which stays the one that runs, and is the one a
74- // removal of the override binds again.
75- if ( replaced ?. override === true && replaced . package !== packageName ) {
77+ // override, or a bundle's handlers re-bound — slots beneath the override,
78+ // which stays the one that runs, and is the one a removal of the override
79+ // binds again. [#30542] Only the declared base's: any other registration
80+ // replaces it and is warned below, like every other collision.
81+ if ( replaced ?. override === true && replaced . package !== packageName
82+ && ActionsFacet . arrivesAsDeclaredBase . call ( this , replaced , objectName , actionName , packageName ) ) {
7683 this . actions . set ( key , { ...replaced , beneath : { handler, package : packageName } } ) ;
7784 this . logger . debug ( 'Registered action beneath an override' , { objectName, actionName, package : packageName , override : replaced . package } ) ;
7885 return ;
@@ -92,14 +99,35 @@ export class ActionsFacet {
9299 this . logger . debug ( 'Registered action' , { objectName, actionName, package : packageName } ) ;
93100 }
94101
102+ /**
103+ * [#30542] Whether a registration under a key a declared override holds is
104+ * the declared base's own handler: the registry's code artifact of the
105+ * action (`getArtifactItem`, which a package's items are registered in
106+ * before its handlers are bound) belongs to the package the override
107+ * declares, on this object — the judgement the authored-action resync
108+ * binds the override by once that artifact is registered. A registration
109+ * with no package is no package's. An override bound with no declared base
110+ * keeps taking any package's handler beneath it.
111+ */
112+ static arrivesAsDeclaredBase ( this : Pick < ActionsHost , 'registry' > , override : ActionHandlerEntry , objectName : string , actionName : string , packageName : string | undefined ) : boolean {
113+ if ( packageName === undefined ) return false ;
114+ if ( override . base === undefined ) return true ;
115+ const artifact : any = this . registry ?. getArtifactItem ?.( 'action' , actionName ) ;
116+ return artifact ?. _packageId === override . base && standaloneActionOwnerKey ( artifact ) === objectName ;
117+ }
118+
95119 /** The body of `ObjectQL#registerActionOverride`; the method's docblock there is its contract. */
96- static registerActionOverride ( this : Pick < ActionsHost , 'actions' | 'logger' > , objectName : string , actionName : string , handler : ( ctx : any ) => Promise < any > | any , packageName : string ) : void {
120+ static registerActionOverride ( this : Pick < ActionsHost , 'actions' | 'logger' > , objectName : string , actionName : string , handler : ( ctx : any ) => Promise < any > | any , packageName : string , base ?: string ) : void {
97121 const key = `${ objectName } :${ actionName } ` ;
98122 const current = this . actions . get ( key ) ;
99123 // Re-binding the same package's override replaces it in place, over the
100124 // same handler beneath.
101125 const beneath = current ?. package === packageName ? current . beneath : current ;
102- this . actions . set ( key , { handler, package : packageName , override : true , ...( beneath !== undefined ? { beneath } : { } ) } ) ;
126+ this . actions . set ( key , {
127+ handler, package : packageName , override : true ,
128+ ...( base !== undefined ? { base } : { } ) ,
129+ ...( beneath !== undefined ? { beneath } : { } ) ,
130+ } ) ;
103131 this . logger . debug ( 'Registered action override' , { objectName, actionName, package : packageName , beneath : beneath ?. package } ) ;
104132 }
105133
0 commit comments