Skip to content

Commit f1aefb1

Browse files
committed
wip: keep the object's own action order; attached ones follow
1 parent df4c867 commit f1aefb1

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎packages/objectql/src/bound-action-foreign-object.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ describe('a bound top-level action reaches another package\'s object as served',
210210
expect(attached).toMatchObject({ requiredPermissions: ['org_admin'], _packageId: 'com.test.binder' });
211211
});
212212

213+
it('the object\'s own actions keep their served order; attached ones follow, ordered by `order`', async () => {
214+
const owner = structuredClone(OWNER) as any;
215+
owner.objects[0].actions = [
216+
{ name: 'second', label: 'Second', type: 'url', target: 'https://example.com/2', order: 20 },
217+
{ name: 'first', label: 'First', type: 'url', target: 'https://example.com/1', order: 10 },
218+
];
219+
const binder = {
220+
id: 'com.test.binder', name: 'binder',
221+
actions: [{ ...BOUND, name: 'late', order: 5 }, { ...BOUND, name: 'early', order: 1 }],
222+
};
223+
const { engine } = await hostWith([owner, binder]);
224+
expect(actionNames(engine.registry.getObject('ba_org'))).toEqual(['second', 'first', 'early', 'late']);
225+
});
226+
213227
it('control: an object nothing binds to is served as declared', async () => {
214228
const { protocol } = await hostWith([OWNER, BINDER, CONTROL]);
215229
const served: any = await protocol.getMetaItem({ type: 'object', name: 'ba_control' } as any);

‎packages/objectql/src/registry.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export function collectManifestObjectNames(manifest: any): string[] {
197197
* Stable sort by `order` (unset reads as `0`), by reference when no action
198198
* sets one — the rule `defineStack()` applies to each object's merged actions
199199
* (`sortActionsByOrder` in `@objectstack/spec`'s stack builder, which is
200-
* internal there), so an attached action sorts exactly as a same-stack one.
200+
* internal there), applied here to the attached actions among themselves.
201201
*/
202202
function sortActionsByOrder<T extends { order?: number }>(actions: T[]): T[] {
203203
if (!actions.some((a) => a?.order !== undefined)) return actions;
@@ -3506,6 +3506,11 @@ export class SchemaRegistry {
35063506
* before rung 2). A target no package registers is refused at boot, not
35073507
* here — see {@link findUnboundActionTargets}.
35083508
*
3509+
* The object's own `actions` keep their order exactly — re-sorting them by
3510+
* `order` here would reorder an object no package bound anything to the
3511+
* moment one did. The attached actions follow, stable-sorted among
3512+
* themselves by `order`.
3513+
*
35093514
* Returns `body` by reference when nothing attaches.
35103515
*/
35113516
private attachBoundActions<T>(body: T): T {
@@ -3524,7 +3529,9 @@ export class SchemaRegistry {
35243529
fresh.push(action);
35253530
}
35263531
if (fresh.length === 0) return body;
3527-
return { ...body, actions: sortActionsByOrder([...base, ...fresh]) };
3532+
// The object's own actions keep their served order, untouched; the
3533+
// attached ones follow, ordered among themselves by `order`.
3534+
return { ...body, actions: [...base, ...sortActionsByOrder(fresh)] };
35283535
}
35293536

35303537
/**

0 commit comments

Comments
 (0)