Skip to content

Commit b88e001

Browse files
committed
refactor(objectql): one shared host per facet in the engine.ts codemod stubs
The engine codemod now builds each facet's host once per engine (engine-facet-hosts.ts, installed by a static block on the class) instead of a host literal per call. Regenerated from engine.ts at c2d353d; every moved body is byte-identical. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfeJWRytJdoFWR9Pc8
1 parent c23501b commit b88e001

19 files changed

Lines changed: 847 additions & 1149 deletions

‎packages/objectql/src/engine-actions.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
* with its body. The state stays on `ObjectQL`.
2020
*
2121
* The bodies reach the class through {@link ActionsHost}: exactly the
22-
* `ObjectQL` members they read, private ones included. Each stub hands its
23-
* body one literal of the members that body reads, plus a `.call`: methods go
24-
* as closures that call them on the engine at call time, so a subclass
25-
* override or an instance spy is still the one reached; fields and accessors
26-
* go as GETTERS, read when the body reads them, as they were on the class,
27-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
22+
* `ObjectQL` members they read, private ones included. Every stub hands its
23+
* body, by a `.call`, the same host: `actionsHost` in `engine-facet-hosts.ts`, built
24+
* once per engine by the class's static block. Methods go as closures that
25+
* call them on the engine at call time, so a subclass override or an instance
26+
* spy is still the one reached; fields and accessors go as GETTERS, read when
27+
* the body reads them, as they were on the class, and a field a body assigns
28+
* goes with a SETTER that assigns it on the engine.
2829
*
2930
* The module imports `engine.ts` for types only, so the two modules form no
3031
* evaluation cycle. `index.ts` re-exports nothing from this module.

‎packages/objectql/src/engine-cascade-planning.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
* with its body. The state stays on `ObjectQL`.
2525
*
2626
* The bodies reach the class through {@link CascadePlanningHost}: exactly the
27-
* `ObjectQL` members they read, private ones included. Each stub hands its
28-
* body one literal of the members that body reads, plus a `.call`: methods go
29-
* as closures that call them on the engine at call time, so a subclass
30-
* override or an instance spy is still the one reached; fields and accessors
31-
* go as GETTERS, read when the body reads them, as they were on the class,
32-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
27+
* `ObjectQL` members they read, private ones included. Every stub hands its
28+
* body, by a `.call`, the same host: `cascadePlanningHost` in `engine-facet-hosts.ts`, built
29+
* once per engine by the class's static block. Methods go as closures that
30+
* call them on the engine at call time, so a subclass override or an instance
31+
* spy is still the one reached; fields and accessors go as GETTERS, read when
32+
* the body reads them, as they were on the class, and a field a body assigns
33+
* goes with a SETTER that assigns it on the engine.
3334
*
3435
* `ObjectQL` here is `ObjectQLStatics` (imported AS `ObjectQL`): forwarders to the
3536
* statics the bodies read, private ones included, which the class fills in a

‎packages/objectql/src/engine-compatibility-section.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* with its body. The state stays on `ObjectQL`.
1818
*
1919
* The bodies reach the class through {@link CompatibilitySectionHost}: exactly the
20-
* `ObjectQL` members they read, private ones included. Each stub hands its
21-
* body one literal of the members that body reads, plus a `.call`: methods go
22-
* as closures that call them on the engine at call time, so a subclass
23-
* override or an instance spy is still the one reached; fields and accessors
24-
* go as GETTERS, read when the body reads them, as they were on the class,
25-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
20+
* `ObjectQL` members they read, private ones included. Every stub hands its
21+
* body, by a `.call`, the same host: `compatibilitySectionHost` in `engine-facet-hosts.ts`, built
22+
* once per engine by the class's static block. Methods go as closures that
23+
* call them on the engine at call time, so a subclass override or an instance
24+
* spy is still the one reached; fields and accessors go as GETTERS, read when
25+
* the body reads them, as they were on the class, and a field a body assigns
26+
* goes with a SETTER that assigns it on the engine.
2627
*
2728
* Values that stayed in `engine.ts` are imported from it (lever (a) of
2829
* ruling 6591753301); every use is inside a function body, so the import

‎packages/objectql/src/engine-defaults-and-autonumbers.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
* with its body. The state stays on `ObjectQL`.
1919
*
2020
* The bodies reach the class through {@link DefaultsAndAutonumbersHost}: exactly the
21-
* `ObjectQL` members they read, private ones included. Each stub hands its
22-
* body one literal of the members that body reads, plus a `.call`: methods go
23-
* as closures that call them on the engine at call time, so a subclass
24-
* override or an instance spy is still the one reached; fields and accessors
25-
* go as GETTERS, read when the body reads them, as they were on the class,
26-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
21+
* `ObjectQL` members they read, private ones included. Every stub hands its
22+
* body, by a `.call`, the same host: `defaultsAndAutonumbersHost` in `engine-facet-hosts.ts`, built
23+
* once per engine by the class's static block. Methods go as closures that
24+
* call them on the engine at call time, so a subclass override or an instance
25+
* spy is still the one reached; fields and accessors go as GETTERS, read when
26+
* the body reads them, as they were on the class, and a field a body assigns
27+
* goes with a SETTER that assigns it on the engine.
2728
*
2829
* The module imports `engine.ts` for types only, so the two modules form no
2930
* evaluation cycle. `index.ts` re-exports nothing from this module.

‎packages/objectql/src/engine-delete-and-aggregate.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
* with its body. The state stays on `ObjectQL`.
1616
*
1717
* The bodies reach the class through {@link DeleteAndAggregateHost}: exactly the
18-
* `ObjectQL` members they read, private ones included. Each stub hands its
19-
* body one literal of the members that body reads, plus a `.call`: methods go
20-
* as closures that call them on the engine at call time, so a subclass
21-
* override or an instance spy is still the one reached; fields and accessors
22-
* go as GETTERS, read when the body reads them, as they were on the class,
23-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
18+
* `ObjectQL` members they read, private ones included. Every stub hands its
19+
* body, by a `.call`, the same host: `deleteAndAggregateHost` in `engine-facet-hosts.ts`, built
20+
* once per engine by the class's static block. Methods go as closures that
21+
* call them on the engine at call time, so a subclass override or an instance
22+
* spy is still the one reached; fields and accessors go as GETTERS, read when
23+
* the body reads them, as they were on the class, and a field a body assigns
24+
* goes with a SETTER that assigns it on the engine.
2425
*
2526
* The module imports `engine.ts` for types only, so the two modules form no
2627
* evaluation cycle. `index.ts` re-exports nothing from this module.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#29986 codemod] The host of each facet of `ObjectQL`, built ONCE per engine (#30051):
5+
* what every stub of a facet hands that facet's bodies as `this`, in place of
6+
* a host literal built on every call. Each `FacetHost` below is filled by the
7+
* factory `ObjectQL`'s static block installs, the one place that can read
8+
* the class's private members; the host is built on the first call that needs
9+
* it and kept for the engine's life. A method goes as a closure that calls it
10+
* on the engine at call time, a field or accessor as a getter (and a setter
11+
* when a body assigns it), so a body reads and writes the engine exactly as
12+
* the per-call literal let it.
13+
*
14+
* Written by `scripts/codemod-split-engine.mjs`; it imports types only, so it forms no
15+
* evaluation cycle and is evaluated before the class whichever module loads
16+
* first. `index.ts` re-exports nothing from this module.
17+
*/
18+
19+
import type { ObjectQL } from './engine.js';
20+
import type { ActionsHost } from './engine-actions.js';
21+
import type { CascadePlanningHost } from './engine-cascade-planning.js';
22+
import type { CompatibilitySectionHost } from './engine-compatibility-section.js';
23+
import type { DefaultsAndAutonumbersHost } from './engine-defaults-and-autonumbers.js';
24+
import type { DeleteAndAggregateHost } from './engine-delete-and-aggregate.js';
25+
import type { FindHost } from './engine-find.js';
26+
import type { HooksAndFunctionsHost } from './engine-hooks-and-functions.js';
27+
import type { InsertHost } from './engine-insert.js';
28+
import type { MiddlewareAndContextHost } from './engine-middleware-and-context.js';
29+
import type { MigrationStateHost } from './engine-migration-state.js';
30+
import type { ReferencesAndMasterDetailHost } from './engine-references-and-master-detail.js';
31+
import type { RegistrationHost } from './engine-registration.js';
32+
import type { SecretsAndRoutingHost } from './engine-secrets-and-routing.js';
33+
import type { SecurityResolversHost } from './engine-security-resolvers.js';
34+
import type { SummariesAndExpansionHost } from './engine-summaries-and-expansion.js';
35+
import type { TransactionsSectionHost } from './engine-transactions-section.js';
36+
37+
/** One facet's host for each engine: built on first use, kept for the engine's life. */
38+
export class FacetHost<H> {
39+
private readonly hosts = new WeakMap<ObjectQL, H>();
40+
private build: ((engine: ObjectQL) => H) | undefined;
41+
42+
constructor(private readonly facet: string) {}
43+
44+
/** Called once, from `ObjectQL`'s static block. */
45+
install(build: (engine: ObjectQL) => H): void {
46+
this.build = build;
47+
}
48+
49+
/** The host of `engine`, built on first use. */
50+
of(engine: ObjectQL): H {
51+
let host = this.hosts.get(engine);
52+
if (host === undefined) {
53+
if (this.build === undefined) {
54+
throw new Error(`${this.facet}: ObjectQL has not installed its host factory`);
55+
}
56+
host = this.build(engine);
57+
this.hosts.set(engine, host);
58+
}
59+
return host;
60+
}
61+
}
62+
63+
export const actionsHost = new FacetHost<ActionsHost>('ActionsFacet');
64+
export const cascadePlanningHost = new FacetHost<CascadePlanningHost>('CascadePlanningFacet');
65+
export const compatibilitySectionHost = new FacetHost<CompatibilitySectionHost>('CompatibilitySectionFacet');
66+
export const defaultsAndAutonumbersHost = new FacetHost<DefaultsAndAutonumbersHost>('DefaultsAndAutonumbersFacet');
67+
export const deleteAndAggregateHost = new FacetHost<DeleteAndAggregateHost>('DeleteAndAggregateFacet');
68+
export const findHost = new FacetHost<FindHost>('FindFacet');
69+
export const hooksAndFunctionsHost = new FacetHost<HooksAndFunctionsHost>('HooksAndFunctionsFacet');
70+
export const insertHost = new FacetHost<InsertHost>('InsertFacet');
71+
export const middlewareAndContextHost = new FacetHost<MiddlewareAndContextHost>('MiddlewareAndContextFacet');
72+
export const migrationStateHost = new FacetHost<MigrationStateHost>('MigrationStateFacet');
73+
export const referencesAndMasterDetailHost = new FacetHost<ReferencesAndMasterDetailHost>('ReferencesAndMasterDetailFacet');
74+
export const registrationHost = new FacetHost<RegistrationHost>('RegistrationFacet');
75+
export const secretsAndRoutingHost = new FacetHost<SecretsAndRoutingHost>('SecretsAndRoutingFacet');
76+
export const securityResolversHost = new FacetHost<SecurityResolversHost>('SecurityResolversFacet');
77+
export const summariesAndExpansionHost = new FacetHost<SummariesAndExpansionHost>('SummariesAndExpansionFacet');
78+
export const transactionsSectionHost = new FacetHost<TransactionsSectionHost>('TransactionsSectionFacet');

‎packages/objectql/src/engine-find.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* with its body. The state stays on `ObjectQL`.
1818
*
1919
* The bodies reach the class through {@link FindHost}: exactly the
20-
* `ObjectQL` members they read, private ones included. Each stub hands its
21-
* body one literal of the members that body reads, plus a `.call`: methods go
22-
* as closures that call them on the engine at call time, so a subclass
23-
* override or an instance spy is still the one reached; fields and accessors
24-
* go as GETTERS, read when the body reads them, as they were on the class,
25-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
20+
* `ObjectQL` members they read, private ones included. Every stub hands its
21+
* body, by a `.call`, the same host: `findHost` in `engine-facet-hosts.ts`, built
22+
* once per engine by the class's static block. Methods go as closures that
23+
* call them on the engine at call time, so a subclass override or an instance
24+
* spy is still the one reached; fields and accessors go as GETTERS, read when
25+
* the body reads them, as they were on the class, and a field a body assigns
26+
* goes with a SETTER that assigns it on the engine.
2627
*
2728
* The module imports `engine.ts` for types only, so the two modules form no
2829
* evaluation cycle. `index.ts` re-exports nothing from this module.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
* with its body. The state stays on `ObjectQL`.
2222
*
2323
* The bodies reach the class through {@link HooksAndFunctionsHost}: exactly the
24-
* `ObjectQL` members they read, private ones included. Each stub hands its
25-
* body one literal of the members that body reads, plus a `.call`: methods go
26-
* as closures that call them on the engine at call time, so a subclass
27-
* override or an instance spy is still the one reached; fields and accessors
28-
* go as GETTERS, read when the body reads them, as they were on the class,
29-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
24+
* `ObjectQL` members they read, private ones included. Every stub hands its
25+
* body, by a `.call`, the same host: `hooksAndFunctionsHost` in `engine-facet-hosts.ts`, built
26+
* once per engine by the class's static block. Methods go as closures that
27+
* call them on the engine at call time, so a subclass override or an instance
28+
* spy is still the one reached; fields and accessors go as GETTERS, read when
29+
* the body reads them, as they were on the class, and a field a body assigns
30+
* goes with a SETTER that assigns it on the engine.
3031
*
3132
* The module imports `engine.ts` for types only, so the two modules form no
3233
* evaluation cycle. `index.ts` re-exports nothing from this module.

‎packages/objectql/src/engine-insert.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
* with its body. The state stays on `ObjectQL`.
1717
*
1818
* The bodies reach the class through {@link InsertHost}: exactly the
19-
* `ObjectQL` members they read, private ones included. Each stub hands its
20-
* body one literal of the members that body reads, plus a `.call`: methods go
21-
* as closures that call them on the engine at call time, so a subclass
22-
* override or an instance spy is still the one reached; fields and accessors
23-
* go as GETTERS, read when the body reads them, as they were on the class,
24-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
19+
* `ObjectQL` members they read, private ones included. Every stub hands its
20+
* body, by a `.call`, the same host: `insertHost` in `engine-facet-hosts.ts`, built
21+
* once per engine by the class's static block. Methods go as closures that
22+
* call them on the engine at call time, so a subclass override or an instance
23+
* spy is still the one reached; fields and accessors go as GETTERS, read when
24+
* the body reads them, as they were on the class, and a field a body assigns
25+
* goes with a SETTER that assigns it on the engine.
2526
*
2627
* The module imports `engine.ts` for types only, so the two modules form no
2728
* evaluation cycle. `index.ts` re-exports nothing from this module.

‎packages/objectql/src/engine-middleware-and-context.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
* with its body. The state stays on `ObjectQL`.
2222
*
2323
* The bodies reach the class through {@link MiddlewareAndContextHost}: exactly the
24-
* `ObjectQL` members they read, private ones included. Each stub hands its
25-
* body one literal of the members that body reads, plus a `.call`: methods go
26-
* as closures that call them on the engine at call time, so a subclass
27-
* override or an instance spy is still the one reached; fields and accessors
28-
* go as GETTERS, read when the body reads them, as they were on the class,
29-
* and a field a body assigns goes with a SETTER that assigns it on the engine.
24+
* `ObjectQL` members they read, private ones included. Every stub hands its
25+
* body, by a `.call`, the same host: `middlewareAndContextHost` in `engine-facet-hosts.ts`, built
26+
* once per engine by the class's static block. Methods go as closures that
27+
* call them on the engine at call time, so a subclass override or an instance
28+
* spy is still the one reached; fields and accessors go as GETTERS, read when
29+
* the body reads them, as they were on the class, and a field a body assigns
30+
* goes with a SETTER that assigns it on the engine.
3031
*
3132
* The module imports `engine.ts` for types only, so the two modules form no
3233
* evaluation cycle. `index.ts` re-exports nothing from this module.

0 commit comments

Comments
 (0)