Skip to content

Commit 859141d

Browse files
committed
feat(objectql): registerAction warns when another owner's handler under the same key is replaced
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PmE7dZP8v5iv3z1dgybAtT
1 parent 5026b15 commit 859141d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎packages/objectql/src/engine.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,9 +5560,28 @@ export class ObjectQL implements IObjectQLEngine {
55605560
* action's declared param contract at dispatch before the handler runs.
55615561
* The seam itself stays untyped so existing untyped handlers keep working.
55625562
* @param packageName Optional package owner (for cleanup)
5563+
*
5564+
* [#24472] A key another package already holds is still replaced — the last
5565+
* registration runs, as before — but no longer silently: the replacement is
5566+
* warned, naming both owners. The same owner re-registering (a re-bind, a
5567+
* reload, the authored-action resync, which tears its set down first) is
5568+
* not. A registration with no `packageName` is its own owner here, so it
5569+
* replacing a package's handler, or the reverse, is warned too.
55635570
*/
55645571
registerAction(objectName: string, actionName: string, handler: (ctx: any) => Promise<any> | any, packageName?: string): void {
55655572
const key = `${objectName}:${actionName}`;
5573+
const replaced = this.actions.get(key);
5574+
if (replaced !== undefined && replaced.package !== packageName) {
5575+
const owner = (name: string | undefined) => (name ? `package '${name}'` : 'a registration with no package');
5576+
this.logger.warn(
5577+
`Action handler '${key}' registered by ${owner(packageName)} replaces the one ${owner(replaced.package)} `
5578+
+ `registered: the action door now runs the handler of ${owner(packageName)}, whichever declaration `
5579+
+ `object '${objectName}' lists, and withdrawing ${owner(packageName)} leaves the action with no handler. `
5580+
+ `Two owners share one handler key only when both declare action '${actionName}' on object `
5581+
+ `'${objectName}' — rename one of them.`,
5582+
{ objectName, actionName, package: packageName, replacedPackage: replaced.package },
5583+
);
5584+
}
55665585
this.actions.set(key, { handler, package: packageName });
55675586
this.logger.debug('Registered action', { objectName, actionName, package: packageName });
55685587
}

0 commit comments

Comments
 (0)