@@ -47,6 +47,7 @@ import {
4747 resolvePackageScopedHolders ,
4848 type PackageScopedHolderSource ,
4949} from '@objectstack/core' ;
50+ import { callerlessFunctionResolution } from './package-scoped-resolver.js' ;
5051import { hookStoppedRefusal } from './summary-errors.js' ;
5152import { startSummaryRefreshOnEnable } from './summary-enable-refresh.js' ;
5253import { HookTargetRebindError } from './hook-target-rebind-errors.js' ;
@@ -93,31 +94,39 @@ export interface HooksAndFunctionsHost {
9394/** The bodies of the "Class head: units, hooks, functions, body runners, hook dispatch" section of `ObjectQL`: a stateless facet, called by the class's stubs. */
9495
9596/**
96- * [ADR-0150 D3/D4, #31700; epic seat ruling R2-C, 6812862622] The bare
97- * function map's entry for `name` — the last registration of the name —
98- * unless two PACKAGES hold it, which two namespaces may since #31700: then no
99- * entry is picked, and the read is refused as the rule refuses a caller with
100- * no package (`resolvePackageScopedHolders`, `ambiguous-in-environment`),
101- * naming every holder. A name one package holds, and an owner-less (platform)
102- * registration, answer as before. A reader that knows its package resolves
103- * through `functionHoldersOf` (the flow `script` node, #32073).
97+ * [ADR-0150 D3/D4, #31700, #32907; epic seat ruling R2-C, 6812862622] The
98+ * bare function map's entry for `name` — the last registration of the name —
99+ * when ONE holder holds it. Two or more holders get no pick, in whatever
100+ * order they registered: two PACKAGES (two namespaces may each hold one since
101+ * #31700), or the PLATFORM (an owner-less registration) beside a package. The
102+ * read is refused as the rule refuses a caller with no package
103+ * (`resolvePackageScopedHolders`, `ambiguous-in-environment`), naming every
104+ * holder. A disabled package is counted and never answered
105+ * ({@link callerlessFunctionResolution}, #32933). A name one package holds,
106+ * and one only the platform holds, answer as before. A reader that knows its
107+ * package resolves through `functionHoldersOf` (the flow `script` node,
108+ * #32073).
104109 *
105110 * @throws {PackageScopedNameRefusedError } `409 RESOURCE_CONFLICT`, every holder named.
106111 */
107112function bareFunctionEntry (
108- host : Pick < HooksAndFunctionsHost , 'functions' | 'functionHolders' > ,
113+ host : Pick < HooksAndFunctionsHost , '_registry' | ' functions' | 'functionHolders' > ,
109114 name : string ,
110115) : Readonly < FunctionEntry > | undefined {
111- const holders = host . functionHolders . get ( name ) ;
112- if ( holders && [ ...holders . keys ( ) ] . filter ( ( holder ) => holder !== null ) . length > 1 ) {
113- const refused = resolvePackageScopedHolders (
116+ const resolution = callerlessFunctionResolution (
117+ resolvePackageScopedHolders (
114118 { type : ENGINE_FUNCTION_TYPE , name, callerPackageId : null } ,
115119 HooksAndFunctionsFacet . functionHoldersOf . call ( host , name ) ,
116120 ( ) => new Set < string > ( ) ,
117- ) ;
118- if ( refused . status === 'refused' ) throw new PackageScopedNameRefusedError ( refused ) ;
119- }
120- return host . functions . get ( name ) ;
121+ ) ,
122+ ( packageId ) => host . _registry . isPackageDisabled ( packageId ) ,
123+ ) ;
124+ if ( resolution . status === 'refused' ) throw new PackageScopedNameRefusedError ( resolution ) ;
125+ // The one holder's answer is the bare map's entry, as it always was: the
126+ // holder set keeps the same entry object for it (`registerFunction`), and
127+ // `unregisterFunctionsByPackage` puts it back when the last registration
128+ // leaves (#32534).
129+ return resolution . status === 'resolved' ? host . functions . get ( name ) : undefined ;
121130}
122131
123132export class HooksAndFunctionsFacet {
@@ -303,12 +312,12 @@ export class HooksAndFunctionsFacet {
303312 }
304313
305314 /** The body of `ObjectQL#resolveFunction`; the method's docblock there is its contract. */
306- static resolveFunction ( this : Pick < HooksAndFunctionsHost , 'functions' | 'functionHolders' > , name : string ) : HookHandler | undefined {
315+ static resolveFunction ( this : Pick < HooksAndFunctionsHost , '_registry' | ' functions' | 'functionHolders' > , name : string ) : HookHandler | undefined {
307316 return bareFunctionEntry ( this , name ) ?. handler ;
308317 }
309318
310319 /** The body of `ObjectQL#resolveFunctionEntry`; the method's docblock there is its contract. */
311- static resolveFunctionEntry ( this : Pick < HooksAndFunctionsHost , 'functions' | 'functionHolders' > , name : string ) : Readonly < FunctionEntry > | undefined {
320+ static resolveFunctionEntry ( this : Pick < HooksAndFunctionsHost , '_registry' | ' functions' | 'functionHolders' > , name : string ) : Readonly < FunctionEntry > | undefined {
312321 return bareFunctionEntry ( this , name ) ;
313322 }
314323
@@ -331,8 +340,9 @@ export class HooksAndFunctionsFacet {
331340 // [#32534] The bare entry left with the last registration while ONE
332341 // holder of the name remains: that holder's entry is the bare answer, as
333342 // a one-holder name's always is. Two or more remaining holders get no
334- // pick (the bare read of two packages' name stays refused, naming them),
335- // and an owner-less registration never leaves with a package.
343+ // pick (the bare read of two holders' name stays refused, naming them,
344+ // the platform's owner-less registration among them, #32907), and an
345+ // owner-less registration never leaves with a package.
336346 else if ( holders . size === 1 && ! this . functions . has ( name ) ) this . functions . set ( name , [ ...holders . values ( ) ] [ 0 ] ) ;
337347 }
338348 if ( removed > 0 ) {
0 commit comments