Skip to content

Commit 98200ca

Browse files
committed
refactor(metadata-protocol): move the authoring gate's deployment-posture probes out of protocol.ts into protocol-authoring-posture-probes.ts (#25467 cut 26)
Move-only, shape B. orgWallEnforced, tenancyPostureInForce, rlsMembershipResolverKeys and hierarchyResolverMounted move, unedited, into one module. orgWallEnforced reads no member, so its stub calls the plain function; the other three get the getServicesRegistry field as a getter. postureEnforcesWall, anonymousFormIntakePosture, RLS_MEMBERSHIP_RESOLVER_SERVICE and HIERARCHY_SCOPE_RESOLVER_SERVICE lose their last reader in protocol.ts and leave its imports, with the comments that explained them. Claude-Session: https://claude.ai/code/session_016SP1spj613tyGCgxoD1An6 Co-authored-by: Claude <noreply@anthropic.com>
1 parent aeb9cf0 commit 98200ca

2 files changed

Lines changed: 138 additions & 41 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#25467 cut 26] The runtime authoring gate's deployment-posture probes, from
5+
* `ObjectStackProtocolImplementation`, moved out of `protocol.ts` whole: the
6+
* four reads of THIS deployment that `assertRuntimeAuthoringRules` hands the
7+
* gate on every write.
8+
*
9+
* - `orgWallEnforced` — does the configured tenancy posture wall
10+
* organizations (#6285)? Unreadable reads as walled.
11+
* - `tenancyPostureInForce` — the posture the `tenancy` service reports in
12+
* force, for the public-form intake advisory (#21476).
13+
* - `rlsMembershipResolverKeys` — the membership keys the mounted RLS
14+
* resolver declares.
15+
* - `hierarchyResolverMounted` — is a hierarchy resolver mounted (#26188)?
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: the same service keys, the
20+
* same `try`s and the same answers when a read throws.
21+
*
22+
* ## How the moved bodies reach the class
23+
*
24+
* The shape #23050 set for `rest-server.ts` (its `data-action-routes.ts`
25+
* header carries the full reasoning), as `protocol-batch-data.ts` applies it.
26+
* The class keeps each method — the published `dist/*.d.ts` lists its name,
27+
* docblock and declared signature — and its body delegates here. Three read
28+
* the constructor-supplied `getServicesRegistry` field, handed over as a
29+
* getter ({@link AuthoringPostureProbesHost}), as
30+
* `protocol-metadata-service-read.ts` hands that field over, so each reads the
31+
* registry at call time — a resolver registered after this protocol is
32+
* assembled is seen by the next write. `orgWallEnforced` reads no member, so
33+
* its stub calls the plain function. The callers — the closures in
34+
* `assertRuntimeAuthoringRules`'s stub — keep calling the class methods.
35+
*
36+
* What the bodies read from elsewhere, they import from where `protocol.ts`
37+
* imported it; four of those names had no other reader there and left its
38+
* imports, with the comments that explained them. Nothing re-exports this
39+
* module, so the published surface does not move.
40+
*/
41+
42+
import type { TenancyPosture } from '@objectstack/spec/security';
43+
// [#6285] ADR-0105 D1's authority on "does this deployment wall organizations?".
44+
// `resolveMultiOrgEnabled()` is DEMOTED and its own doc comment says answering
45+
// this question with it is a bug (cloud#1020, #5233) — so the posture, and only
46+
// the posture, is what the runtime authoring gate is told.
47+
import { postureEnforcesWall } from '@objectstack/spec/security';
48+
import { resolveTenancyPosture } from '@objectstack/types';
49+
import {
50+
// [#21476] The posture IN FORCE, read off the `tenancy` service the one way
51+
// the anonymous form doors read it — the runtime authoring gate's input for
52+
// its public-form intake advisory (see `tenancyPostureInForce()`).
53+
anonymousFormIntakePosture,
54+
} from '@objectstack/metadata-core';
55+
import { RLS_MEMBERSHIP_RESOLVER_SERVICE } from '@objectstack/spec/contracts';
56+
import { HIERARCHY_SCOPE_RESOLVER_SERVICE } from './runtime-authoring-gate.js';
57+
import type { ObjectStackProtocolImplementation } from './protocol.js';
58+
59+
/**
60+
* The `ObjectStackProtocolImplementation` members the functions below read —
61+
* every one of them, and no other; each function's `this` is the `Pick` of
62+
* the members it reads. Each is typed AS the class member (an indexed access
63+
* on the class), so a change to a member's type on the class is a change
64+
* here too, and naming a member the class does not have is a compile error.
65+
*/
66+
export interface AuthoringPostureProbesHost {
67+
readonly getServicesRegistry: ObjectStackProtocolImplementation['getServicesRegistry'];
68+
}
69+
70+
/** The body of `ObjectStackProtocolImplementation#orgWallEnforced`; the method's docblock there is its contract. */
71+
export function orgWallEnforced(): boolean {
72+
try {
73+
return postureEnforcesWall(resolveTenancyPosture());
74+
} catch {
75+
return true;
76+
}
77+
}
78+
79+
/** The body of `ObjectStackProtocolImplementation#tenancyPostureInForce`; the method's docblock there is its contract. */
80+
export function tenancyPostureInForce(this: Pick<AuthoringPostureProbesHost, 'getServicesRegistry'>): TenancyPosture | undefined {
81+
try {
82+
return anonymousFormIntakePosture(this.getServicesRegistry?.().get('tenancy'));
83+
} catch {
84+
return undefined;
85+
}
86+
}
87+
88+
/** The body of `ObjectStackProtocolImplementation#rlsMembershipResolverKeys`; the method's docblock there is its contract. */
89+
export function rlsMembershipResolverKeys(this: Pick<AuthoringPostureProbesHost, 'getServicesRegistry'>): readonly string[] | undefined {
90+
const registry = this.getServicesRegistry?.();
91+
if (!registry) return undefined;
92+
let resolver: unknown;
93+
try {
94+
resolver = registry.get(RLS_MEMBERSHIP_RESOLVER_SERVICE);
95+
} catch {
96+
return undefined;
97+
}
98+
if (resolver === undefined || resolver === null) return [];
99+
const keys = (resolver as { keys?: unknown }).keys;
100+
if (!Array.isArray(keys) || !keys.every((k) => typeof k === 'string')) return undefined;
101+
return keys as readonly string[];
102+
}
103+
104+
/** The body of `ObjectStackProtocolImplementation#hierarchyResolverMounted`; the method's docblock there is its contract. */
105+
export function hierarchyResolverMounted(this: Pick<AuthoringPostureProbesHost, 'getServicesRegistry'>): boolean | undefined {
106+
const registry = this.getServicesRegistry?.();
107+
if (!registry) return undefined;
108+
try {
109+
const resolver = registry.get(HIERARCHY_SCOPE_RESOLVER_SERVICE);
110+
return resolver !== undefined && resolver !== null;
111+
} catch {
112+
return undefined;
113+
}
114+
}

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

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import type {
55
} from '@objectstack/spec/api';
66
import { IDataEngine, engineCanRollBack, recordNotFoundError } from '@objectstack/core';
77
import { declaredHttpStatus, declaredUserMessage, isSandboxOrigin, resolveTenancyPosture, resolveThrownHttpError, sandboxBusinessMessage } from '@objectstack/types';
8-
// [#6285] ADR-0105 D1's authority on "does this deployment wall organizations?".
9-
// `resolveMultiOrgEnabled()` is DEMOTED and its own doc comment says answering
10-
// this question with it is a bug (cloud#1020, #5233) — so the posture, and only
11-
// the posture, is what the runtime authoring gate is told.
12-
import { judgePermissionSetOwnerBinding, postureEnforcesWall, type TenancyPosture } from '@objectstack/spec/security';
8+
import { judgePermissionSetOwnerBinding, type TenancyPosture } from '@objectstack/spec/security';
139
// [commit 376c70f98] The derived `version` this file's `getDiscovery()` serves as the
1410
// `DiscoverySchema` "System Identity" field — never a literal again.
1511
import { resolveDiscoveryVersion } from './discovery-version.js';
@@ -27,7 +23,6 @@ import { stripUnauthorableProperties } from './unauthorable-nodes.js';
2723
// admits anything. See the module header for the predicate and its controls.
2824
import { markErasedAuthoringInput } from './erased-authoring-mark.js';
2925
import {
30-
HIERARCHY_SCOPE_RESOLVER_SERVICE,
3126
SDUI_MANIFEST_SERVICE,
3227
isUsableSduiManifest,
3328
stampHtmlPageRequires,
@@ -105,10 +100,6 @@ import {
105100
// {@link ObjectStackProtocolImplementation.getMetaItemLayered}'s code-layer
106101
// fallback so a hydrated row is never answered as the code layer.
107102
isTenantAuthored,
108-
// [#21476] The posture IN FORCE, read off the `tenancy` service the one way
109-
// the anonymous form doors read it — the runtime authoring gate's input for
110-
// its public-form intake advisory (see `tenancyPostureInForce()`).
111-
anonymousFormIntakePosture,
112103
// [ADR-0131 D6/D7] A legacy organization's rows, off the physical column,
113104
// on a database the ceremony has not migrated — see migrateStoredMetadata.
114105
readLegacyOrganizationRows,
@@ -166,7 +157,7 @@ import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL, canonicalMetaUrlType, metaUrlSp
166157
// depends on `@objectstack/service-cluster`; a bridge plugin there hands the
167158
// live transport in through `attachMetadataMutationPubSub`.
168159
import type { IFieldFileService, IPubSub } from '@objectstack/spec/contracts';
169-
import { FIELD_FILE_SERVICE, RLS_MEMBERSHIP_RESOLVER_SERVICE } from '@objectstack/spec/contracts';
160+
import { FIELD_FILE_SERVICE } from '@objectstack/spec/contracts';
170161
import { applyConversionsToFlow, type ConversionNotice, type ConversionTodoNotice } from '@objectstack/spec';
171162
import { type FormView, type I18nLabel, isAggregatedViewContainer, expandViewContainer } from '@objectstack/spec/ui';
172163
// [commit ece4dad31] Emitted-specifier pin. This module's inferred public declarations
@@ -419,6 +410,8 @@ import { listLiveMetadataTypes } from './protocol-live-metadata-types.js';
419410
import { saveConflict } from './protocol-save-conflict.js';
420411
// [#25467 cut 25] The post-persistence mutation fan-out: projector, local listeners, cluster publish, publish listeners.
421412
import { emitMetaItemPublished, notifyMutationListenersLocal, publishMetadataMutation, runMutationProjector } from './protocol-mutation-fan-out.js';
413+
// [#25467 cut 26] The runtime authoring gate's deployment-posture probes: org wall, tenancy, RLS keys, hierarchy.
414+
import { hierarchyResolverMounted, orgWallEnforced, rlsMembershipResolverKeys, tenancyPostureInForce } from './protocol-authoring-posture-probes.js';
422415

423416
/**
424417
* Canonical Zod schema per metadata type lives in
@@ -7392,11 +7385,8 @@ export class ObjectStackProtocolImplementation implements
73927385
* refusal combination to be turned away.
73937386
*/
73947387
private orgWallEnforced(): boolean {
7395-
try {
7396-
return postureEnforcesWall(resolveTenancyPosture());
7397-
} catch {
7398-
return true;
7399-
}
7388+
// [#25467 cut 26] The body moved to `protocol-authoring-posture-probes.ts`; it reads no member.
7389+
return orgWallEnforced();
74007390
}
74017391

74027392
/**
@@ -7426,11 +7416,12 @@ export class ObjectStackProtocolImplementation implements
74267416
* reports none, and the advisory is simply not raised.
74277417
*/
74287418
private tenancyPostureInForce(): TenancyPosture | undefined {
7429-
try {
7430-
return anonymousFormIntakePosture(this.getServicesRegistry?.().get('tenancy'));
7431-
} catch {
7432-
return undefined;
7433-
}
7419+
// [#25467 cut 26] The body moved to `protocol-authoring-posture-probes.ts` (see `AuthoringPostureProbesHost`).
7420+
const readGetServicesRegistry = () => this.getServicesRegistry;
7421+
const host: ThisParameterType<typeof tenancyPostureInForce> = {
7422+
get getServicesRegistry() { return readGetServicesRegistry(); },
7423+
};
7424+
return tenancyPostureInForce.call(host);
74347425
}
74357426

74367427
/**
@@ -7448,18 +7439,12 @@ export class ObjectStackProtocolImplementation implements
74487439
* wrong ones.
74497440
*/
74507441
private rlsMembershipResolverKeys(): readonly string[] | undefined {
7451-
const registry = this.getServicesRegistry?.();
7452-
if (!registry) return undefined;
7453-
let resolver: unknown;
7454-
try {
7455-
resolver = registry.get(RLS_MEMBERSHIP_RESOLVER_SERVICE);
7456-
} catch {
7457-
return undefined;
7458-
}
7459-
if (resolver === undefined || resolver === null) return [];
7460-
const keys = (resolver as { keys?: unknown }).keys;
7461-
if (!Array.isArray(keys) || !keys.every((k) => typeof k === 'string')) return undefined;
7462-
return keys as readonly string[];
7442+
// [#25467 cut 26] The body moved to `protocol-authoring-posture-probes.ts` (see `AuthoringPostureProbesHost`).
7443+
const readGetServicesRegistry = () => this.getServicesRegistry;
7444+
const host: ThisParameterType<typeof rlsMembershipResolverKeys> = {
7445+
get getServicesRegistry() { return readGetServicesRegistry(); },
7446+
};
7447+
return rlsMembershipResolverKeys.call(host);
74637448
}
74647449

74657450
/**
@@ -7476,14 +7461,12 @@ export class ObjectStackProtocolImplementation implements
74767461
* throws.
74777462
*/
74787463
private hierarchyResolverMounted(): boolean | undefined {
7479-
const registry = this.getServicesRegistry?.();
7480-
if (!registry) return undefined;
7481-
try {
7482-
const resolver = registry.get(HIERARCHY_SCOPE_RESOLVER_SERVICE);
7483-
return resolver !== undefined && resolver !== null;
7484-
} catch {
7485-
return undefined;
7486-
}
7464+
// [#25467 cut 26] The body moved to `protocol-authoring-posture-probes.ts` (see `AuthoringPostureProbesHost`).
7465+
const readGetServicesRegistry = () => this.getServicesRegistry;
7466+
const host: ThisParameterType<typeof hierarchyResolverMounted> = {
7467+
get getServicesRegistry() { return readGetServicesRegistry(); },
7468+
};
7469+
return hierarchyResolverMounted.call(host);
74877470
}
74887471

74897472
/**

0 commit comments

Comments
 (0)