Skip to content

Commit 044e8f2

Browse files
committed
wip(objectql, runtime): the bare function read counts the platform and a disabled package
Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent df9fe94 commit 044e8f2

5 files changed

Lines changed: 252 additions & 47 deletions

File tree

‎packages/objectql/src/engine-hooks-and-functions.ts‎

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
resolvePackageScopedHolders,
4848
type PackageScopedHolderSource,
4949
} from '@objectstack/core';
50+
import { callerlessFunctionResolution } from './package-scoped-resolver.js';
5051
import { hookStoppedRefusal } from './summary-errors.js';
5152
import { startSummaryRefreshOnEnable } from './summary-enable-refresh.js';
5253
import { 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
*/
107112
function 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

123132
export 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) {

‎packages/objectql/src/engine.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,16 @@ export class ObjectQL implements IObjectQLEngine {
761761

762762
/**
763763
* Look up a registered function by name, with no package: the last
764-
* registration of the name. [ADR-0150 D3/D4, #31700; epic seat ruling R2-C]
765-
* A name two packages hold (two namespaces may each bind one) is refused,
766-
* `409 RESOURCE_CONFLICT` naming every holder, never answered with one of
767-
* them; a reader that knows its package resolves through
768-
* {@link functionHoldersOf}.
764+
* registration of the name. [ADR-0150 D3/D4, #31700, #32907; epic seat
765+
* ruling R2-C] A name two holders hold — two packages (two namespaces may
766+
* each bind one), or the platform (an owner-less registration) beside a
767+
* package — is refused, `409 RESOURCE_CONFLICT` naming every holder, never
768+
* answered with one of them, whichever registered last. [#32933] A disabled
769+
* package is counted as a holder and never answered: a name only a disabled
770+
* package holds answers nothing. A reader that knows its package resolves
771+
* through {@link functionHoldersOf}.
769772
*
770-
* @throws {PackageScopedNameRefusedError} for a name two packages hold.
773+
* @throws {PackageScopedNameRefusedError} for a name two holders hold.
771774
*/
772775
resolveFunction(name: string): HookHandler | undefined {
773776
// [#29986 codemod] The body moved to `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`).
@@ -780,9 +783,10 @@ export class ObjectQL implements IObjectQLEngine {
780783
* it"; a caller that must also report what the call did (the automation
781784
* engine's `script` node, feeding the #4354 run summary) needs the
782785
* declaration, and reading it off the same registry keeps the two from
783-
* drifting. Refused alike for a name two packages hold (above).
786+
* drifting. Refused alike for a name two holders hold, and answers nothing
787+
* alike for a name only a disabled package holds (above).
784788
*
785-
* @throws {PackageScopedNameRefusedError} for a name two packages hold.
789+
* @throws {PackageScopedNameRefusedError} for a name two holders hold.
786790
*/
787791
resolveFunctionEntry(name: string): Readonly<FunctionEntry> | undefined {
788792
// [#29986 codemod] The body moved to `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`).
@@ -799,7 +803,7 @@ export class ObjectQL implements IObjectQLEngine {
799803
* `script` node resolves through it (#32073), and `bindHooksToEngine` reads
800804
* a hook's own package's entry from it. `resolveFunction` and
801805
* `resolveFunctionEntry` answer the one last-registered entry per name, and
802-
* refuse a name two packages hold (#31700).
806+
* refuse a name two holders hold (#31700, #32907).
803807
*/
804808
functionHoldersOf(name: string): PackageScopedHolderSource<Readonly<FunctionEntry>> {
805809
// [#31716] The body lives in `engine-hooks-and-functions.ts` (see `HooksAndFunctionsHost`).

‎packages/objectql/src/package-scoped-resolver.ts‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ export interface PackageScopedFunctionQuery {
177177
/** The engine slice the function adapter reads — every member of it, and no other. */
178178
export type PackageScopedFunctionEngine = Pick<ObjectQL, 'registry' | 'functionHoldersOf'>;
179179

180+
/**
181+
* [ADR-0150 D3, #32933; ruling A 6824698376, #32497] A function read that
182+
* names no package — the engine's bare read (`ObjectQL#resolveFunction` /
183+
* `resolveFunctionEntry`) and {@link resolvePackageScopedFunction} with no
184+
* caller package — COUNTS every holder of the name and never RESOLVES TO a
185+
* disabled one.
186+
*
187+
* Counted: `resolution` is the rule's answer over every holder, a disabled
188+
* package's included, so a name a disabled package makes ambiguous stays
189+
* refused, naming it (ruling A: a disabled package is still a holder; a
190+
* disable never turns a refusal into an answer). Never resolved to: when the
191+
* one holder the rule picked for a caller with no package (`unique-holder`,
192+
* the step only such a caller reaches) is a disabled package, nothing answers
193+
* — the served holders (#32497's default) are none. Every other answer passes
194+
* through unchanged: a refusal, the platform's item, and a caller package's
195+
* own item or its closure's holder (`own` / `closure`, a reader that names
196+
* its package).
197+
*/
198+
export function callerlessFunctionResolution<T>(
199+
resolution: PackageScopedResolution<T>,
200+
isPackageDisabled: (packageId: string) => boolean,
201+
): PackageScopedResolution<T> {
202+
if (resolution.status !== 'resolved' || resolution.via !== 'unique-holder' || resolution.holder.kind !== 'package') {
203+
return resolution;
204+
}
205+
return isPackageDisabled(resolution.holder.packageId) ? { status: 'not-found' } : resolution;
206+
}
207+
180208
/**
181209
* Resolve the function a flow's `script` node names, in the package of that
182210
* flow (ADR-0150 D4's last row): the rule (`resolvePackageScopedHolders`)
@@ -194,17 +222,23 @@ export type PackageScopedFunctionEngine = Pick<ObjectQL, 'registry' | 'functionH
194222
* reader: it names a handler key in the action registry, which E2 resolves
195223
* by package, never a registered function. `resolveFunction` /
196224
* `resolveFunctionEntry` answer the one last-registered function per name for
197-
* any other caller, and refuse a name two packages hold (#31700, epic seat
198-
* ruling R2-C).
225+
* any other caller, and refuse a name two holders hold (#31700, epic seat
226+
* ruling R2-C; the platform beside a package, #32907).
227+
*
228+
* [#32933] A caller with no package counts a disabled package as a holder and
229+
* is never answered with its function ({@link callerlessFunctionResolution}).
199230
*/
200231
export function resolvePackageScopedFunction(
201232
engine: PackageScopedFunctionEngine,
202233
query: PackageScopedFunctionQuery,
203234
): PackageScopedResolution<Readonly<FunctionEntry>> {
204235
const registry = engine.registry;
205-
return resolvePackageScopedHolders(
206-
{ type: ENGINE_FUNCTION_TYPE, name: query.name, callerPackageId: query.callerPackageId },
207-
engine.functionHoldersOf(query.name),
208-
(callerPackageId) => packageResolutionClosure(registry, callerPackageId),
236+
return callerlessFunctionResolution(
237+
resolvePackageScopedHolders(
238+
{ type: ENGINE_FUNCTION_TYPE, name: query.name, callerPackageId: query.callerPackageId },
239+
engine.functionHoldersOf(query.name),
240+
(callerPackageId) => packageResolutionClosure(registry, callerPackageId),
241+
),
242+
(packageId) => registry.isPackageDisabled(packageId),
209243
);
210244
}

0 commit comments

Comments
 (0)