Skip to content

Commit 13cd879

Browse files
committed
refactor(metadata-protocol): move the automation service's flow reads out of protocol.ts into protocol-automation-flow-reads.ts (#25467 cut 27)
Move-only, shape B. resolveFlowCanonicalizer, resolveFlowRegistrationReader and flowRegistrationsOf move, unedited, into one module. The getServicesRegistry field is handed over as a getter; flowRegistrationsOf's call to resolveFlowRegistrationReader is handed over as a closure, so it still reaches the class method. Claude-Session: https://claude.ai/code/session_016SP1spj613tyGCgxoD1An6 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 161e00e commit 13cd879

2 files changed

Lines changed: 123 additions & 28 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#25467 cut 27] The automation service's flow reads, from
5+
* `ObjectStackProtocolImplementation`, moved out of `protocol.ts` whole: the
6+
* three members through which this protocol asks the `automation` service —
7+
* the engine of THIS process — about flows.
8+
*
9+
* - `resolveFlowCanonicalizer` — the service's `canonicalizeStoredFlow`, bound,
10+
* for the doors that canonicalize a stored flow body; nothing when the
11+
* service offers none.
12+
* - `resolveFlowRegistrationReader` — the service's `getFlowRegistration`,
13+
* bound, for a `flow` type only (#23775).
14+
* - `flowRegistrationsOf` — the list's `registrations`: that reader's verdict
15+
* per listed, non-draft item (#23316).
16+
*
17+
* A MOVE, not a redesign. Each function below is the body of the
18+
* `ObjectStackProtocolImplementation` method of the same name as it stood,
19+
* re-indented one level and otherwise unedited.
20+
*
21+
* ## How the moved bodies reach the class
22+
*
23+
* The shape #23050 set for `rest-server.ts` (its `data-action-routes.ts`
24+
* header carries the full reasoning), as `protocol-batch-data.ts` applies it.
25+
* The class keeps each method — the published `dist/*.d.ts` lists its name,
26+
* docblock and declared signature — and its body is one literal of exactly
27+
* the {@link AutomationFlowReadsHost} members it reads, plus a `.call`. The
28+
* constructor-supplied `getServicesRegistry` field is handed over as a
29+
* getter, so each read finds the registry as it stands at call time;
30+
* `flowRegistrationsOf`'s call to `resolveFlowRegistrationReader` is handed
31+
* over as a closure, so it still reaches the class method. Every caller keeps
32+
* calling the class methods.
33+
*
34+
* What the bodies read from elsewhere, they import from where `protocol.ts`
35+
* imports it. Nothing re-exports this module, so the published surface does
36+
* not move.
37+
*/
38+
39+
import type { FlowRegistration } from '@objectstack/spec/api';
40+
import type { ObjectStackProtocolImplementation } from './protocol.js';
41+
import { canonicalMetaType } from './protocol.js';
42+
import type { StoredFlowCanonicalization } from './stored-migration.js';
43+
44+
/**
45+
* The `ObjectStackProtocolImplementation` members the functions below read —
46+
* every one of them, and no other; each function's `this` is the `Pick` of
47+
* the members it reads. Each is typed AS the class member (an indexed access
48+
* on the class), so a change to a member's signature on the class is a change
49+
* here too, and naming a member the class does not have is a compile error.
50+
*/
51+
export interface AutomationFlowReadsHost {
52+
readonly getServicesRegistry: ObjectStackProtocolImplementation['getServicesRegistry'];
53+
readonly resolveFlowRegistrationReader: ObjectStackProtocolImplementation['resolveFlowRegistrationReader'];
54+
}
55+
56+
/** The body of `ObjectStackProtocolImplementation#resolveFlowCanonicalizer`; the method's docblock there is its contract. */
57+
export function resolveFlowCanonicalizer(
58+
this: Pick<AutomationFlowReadsHost, 'getServicesRegistry'>,
59+
):
60+
((name: string, body: unknown, options?: { includeRetired?: boolean }) => StoredFlowCanonicalization) | undefined {
61+
const automation = this.getServicesRegistry?.().get('automation') as
62+
| {
63+
canonicalizeStoredFlow?: (
64+
name: string, definition: unknown, options?: { includeRetired?: boolean },
65+
) => StoredFlowCanonicalization;
66+
}
67+
| undefined;
68+
const canonicalize = automation?.canonicalizeStoredFlow;
69+
if (typeof canonicalize !== 'function') return undefined;
70+
return (name, body, options) => (options === undefined
71+
? canonicalize.call(automation, name, body)
72+
: canonicalize.call(automation, name, body, options));
73+
}
74+
75+
/** The body of `ObjectStackProtocolImplementation#resolveFlowRegistrationReader`; the method's docblock there is its contract. */
76+
export function resolveFlowRegistrationReader(
77+
this: Pick<AutomationFlowReadsHost, 'getServicesRegistry'>,
78+
type: string,
79+
): ((name: string) => FlowRegistration) | undefined {
80+
if (canonicalMetaType(type) !== 'flow') return undefined;
81+
const automation = this.getServicesRegistry?.().get('automation') as
82+
| { getFlowRegistration?: (name: string) => FlowRegistration }
83+
| undefined;
84+
const read = automation?.getFlowRegistration;
85+
if (typeof read !== 'function') return undefined;
86+
return (name) => read.call(automation, name);
87+
}
88+
89+
/** The body of `ObjectStackProtocolImplementation#flowRegistrationsOf`; the method's docblock there is its contract. */
90+
export function flowRegistrationsOf(
91+
this: Pick<AutomationFlowReadsHost, 'resolveFlowRegistrationReader'>,
92+
type: string,
93+
items: readonly unknown[],
94+
): { registrations?: Record<string, FlowRegistration> } {
95+
const read = this.resolveFlowRegistrationReader(type);
96+
if (!read) return {};
97+
const entries: Array<[string, FlowRegistration]> = [];
98+
for (const it of items) {
99+
const name = (it as { name?: unknown } | null | undefined)?.name;
100+
if (typeof name !== 'string' || (it as { _draft?: unknown })._draft === true) continue;
101+
entries.push([name, read(name)]);
102+
}
103+
return { registrations: Object.fromEntries(entries) };
104+
}

‎packages/metadata-protocol/src/protocol.ts‎

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ import { saveConflict } from './protocol-save-conflict.js';
413413
import { emitMetaItemPublished, notifyMutationListenersLocal, publishMetadataMutation, runMutationProjector } from './protocol-mutation-fan-out.js';
414414
// [#25467 cut 26] The runtime authoring gate's deployment-posture probes: org wall, tenancy, RLS keys, hierarchy.
415415
import { hierarchyResolverMounted, orgWallEnforced, rlsMembershipResolverKeys, tenancyPostureInForce } from './protocol-authoring-posture-probes.js';
416+
// [#25467 cut 27] The automation service's flow reads: the stored-flow canonicalizer and the engine's registrations.
417+
import { flowRegistrationsOf, resolveFlowCanonicalizer, resolveFlowRegistrationReader } from './protocol-automation-flow-reads.js';
416418

417419
/**
418420
* Canonical Zod schema per metadata type lives in
@@ -6584,18 +6586,12 @@ export class ObjectStackProtocolImplementation implements
65846586
*/
65856587
private resolveFlowCanonicalizer():
65866588
((name: string, body: unknown, options?: { includeRetired?: boolean }) => StoredFlowCanonicalization) | undefined {
6587-
const automation = this.getServicesRegistry?.().get('automation') as
6588-
| {
6589-
canonicalizeStoredFlow?: (
6590-
name: string, definition: unknown, options?: { includeRetired?: boolean },
6591-
) => StoredFlowCanonicalization;
6592-
}
6593-
| undefined;
6594-
const canonicalize = automation?.canonicalizeStoredFlow;
6595-
if (typeof canonicalize !== 'function') return undefined;
6596-
return (name, body, options) => (options === undefined
6597-
? canonicalize.call(automation, name, body)
6598-
: canonicalize.call(automation, name, body, options));
6589+
// [#25467 cut 27] The body moved to `protocol-automation-flow-reads.ts` (see `AutomationFlowReadsHost`).
6590+
const readGetServicesRegistry = () => this.getServicesRegistry;
6591+
const host: ThisParameterType<typeof resolveFlowCanonicalizer> = {
6592+
get getServicesRegistry() { return readGetServicesRegistry(); },
6593+
};
6594+
return resolveFlowCanonicalizer.call(host);
65996595
}
66006596

66016597
/**
@@ -6691,13 +6687,12 @@ export class ObjectStackProtocolImplementation implements
66916687
* cross-process store is read.
66926688
*/
66936689
private resolveFlowRegistrationReader(type: string): ((name: string) => FlowRegistration) | undefined {
6694-
if (canonicalMetaType(type) !== 'flow') return undefined;
6695-
const automation = this.getServicesRegistry?.().get('automation') as
6696-
| { getFlowRegistration?: (name: string) => FlowRegistration }
6697-
| undefined;
6698-
const read = automation?.getFlowRegistration;
6699-
if (typeof read !== 'function') return undefined;
6700-
return (name) => read.call(automation, name);
6690+
// [#25467 cut 27] The body moved to `protocol-automation-flow-reads.ts` (see `AutomationFlowReadsHost`).
6691+
const readGetServicesRegistry = () => this.getServicesRegistry;
6692+
const host: ThisParameterType<typeof resolveFlowRegistrationReader> = {
6693+
get getServicesRegistry() { return readGetServicesRegistry(); },
6694+
};
6695+
return resolveFlowRegistrationReader.call(host, type);
67016696
}
67026697

67036698
/**
@@ -6709,15 +6704,11 @@ export class ObjectStackProtocolImplementation implements
67096704
* `Object.fromEntries`, so a name is an own key whatever it spells.
67106705
*/
67116706
private flowRegistrationsOf(type: string, items: readonly unknown[]): { registrations?: Record<string, FlowRegistration> } {
6712-
const read = this.resolveFlowRegistrationReader(type);
6713-
if (!read) return {};
6714-
const entries: Array<[string, FlowRegistration]> = [];
6715-
for (const it of items) {
6716-
const name = (it as { name?: unknown } | null | undefined)?.name;
6717-
if (typeof name !== 'string' || (it as { _draft?: unknown })._draft === true) continue;
6718-
entries.push([name, read(name)]);
6719-
}
6720-
return { registrations: Object.fromEntries(entries) };
6707+
// [#25467 cut 27] The body moved to `protocol-automation-flow-reads.ts` (see `AutomationFlowReadsHost`).
6708+
const host: ThisParameterType<typeof flowRegistrationsOf> = {
6709+
resolveFlowRegistrationReader: (...a) => this.resolveFlowRegistrationReader(...a),
6710+
};
6711+
return flowRegistrationsOf.call(host, type, items);
67216712
}
67226713

67236714
/**

0 commit comments

Comments
 (0)