Skip to content

Commit bba9d24

Browse files
committed
refactor(metadata-protocol): generate the protocol.ts split in facade form
Lift the codemod's output into the facade form of ruling 6624345766: each section module becomes one stateless facet class whose static methods take the host, every moved member on ObjectStackProtocolImplementation delegates to its facet in one line, a private member's docblock moves with its body, and pure private statics move too. The pilot's no-yield rule is dropped (the facade keeps delegations only). verify unlifts the head back to the module form and proves it against the base as before. The by-path readers and the durability census follow the facet form. Claude-Session: https://claude.ai/code/session_01WGufzgddMBbTQd9yVo4Yuz Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 833a69e commit bba9d24

19 files changed

Lines changed: 10984 additions & 10167 deletions

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

Lines changed: 400 additions & 227 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#29985 codemod] The "Data CRUD" facet of
5+
* `ObjectStackProtocolImplementation`: the bodies of `probeRecord` moved out of
6+
* `protocol.ts` whole by `scripts/codemod-split-protocol.mjs`.
7+
*
8+
* A MOVE, not a redesign. `ProtocolDataCrudFacet` is a stateless facet over the host
9+
* (ruling 6624345766): each static method below is the body of the class
10+
* member of the same name as `packages/metadata-protocol/scripts/host-split.mjs`
11+
* moves one (ruling E, item E1), with `this.<member>` read as `host.<member>`
12+
* and nothing else changed. The facet holds no state: the fields stay on the
13+
* class, and a body reaches them through the host (`protocol-host.ts`).
14+
*
15+
* The class keeps every member as a one-line delegation. A public member
16+
* keeps its docblock there, which the published `.d.ts` prints; a private
17+
* member's docblock moved here with its body (docblock ownership).
18+
*
19+
* What a body reads from elsewhere, it imports from where `protocol.ts`
20+
* imports it. Nothing re-exports this module, so the published surface does
21+
* not move.
22+
*/
23+
24+
import type { ProtocolHost } from './protocol-host.js';
25+
26+
export class ProtocolDataCrudFacet {
27+
/**
28+
* [#4435] Does this row EXIST? A fact about the database — deliberately
29+
* NOT "may this caller see it".
30+
*
31+
* Read with a system context so no row-level policy narrows it. That is
32+
* load-bearing, and the first version of this fix got it wrong: probing
33+
* with the CALLER's context turns the existence gate into an authorization
34+
* gate, because a row the caller cannot read comes back `null` and the
35+
* PATCH answers 404. Two things break when it does.
36+
*
37+
* 1. It silently changes RLS semantics. Whether an unreadable row may be
38+
* written by id is the #1994 pre-image check's decision, made inside
39+
* `engine.update` where the write policy lives. A probe in front of it
40+
* quietly adds a second, different rule — scope creep into the security
41+
* model, from a bug fix about missing records.
42+
*
43+
* 2. It disarms a revert-provable security proof. `@proof: rls-by-id-write`
44+
* (`packages/qa/dogfood/test/rls-fixture.dogfood.test.ts`, referenced by
45+
* the `permission.rowLevelSecurity.using` liveness ledger entry) boots a
46+
* fixture whose member can read nothing but has no write policy, and
47+
* asserts the runner reports `rls-hole`. A caller-scoped probe 404s that
48+
* PATCH, so the RED half goes green — and the gate can no longer prove
49+
* it is able to go red. If the #1994 fix were ever reverted, this probe
50+
* would MASK it. Accidentally hardening one path is not worth
51+
* permanently blinding the gate that watches the whole class.
52+
*
53+
* So the probe answers existence only, and authorization stays exactly
54+
* where it was. The one behaviour this adds is the 404 the issue asked for:
55+
* an id that names no row at all.
56+
*
57+
* ⛔ And what it finds never answers IN FRONT of the write's
58+
* authorization. Its readers are OCC's `updated_at` comparison, asked only
59+
* when the caller sent a token ({@link assertVersionMatch}) and answering
60+
* only for a row the caller's own read returns ({@link assertVersionOf}),
61+
* and the by-id update's existence check, asked only after `engine.update`
62+
* has judged and resolved the write (`updateData`, and the bulk faces
63+
* through {@link assertRecordExists}) — so an update by id answers the same
64+
* refusal whether or not the id exists, as delete does. With a mismatched
65+
* token, a caller whose read of the row is refused gets that read refusal.
66+
*/
67+
static async probeRecord(host: Pick<ProtocolHost, 'engine'>, object: string, id: string): Promise<any> {
68+
return host.engine.findOne(object, { where: { id }, context: { isSystem: true } });
69+
}
70+
}

‎packages/metadata-protocol/src/protocol-diff-delete-load.ts‎

Lines changed: 1521 additions & 1516 deletions
Large diffs are not rendered by default.

‎packages/metadata-protocol/src/protocol-discovery-and-bases.ts‎

Lines changed: 354 additions & 258 deletions
Large diffs are not rendered by default.

‎packages/metadata-protocol/src/protocol-history-and-publish.ts‎

Lines changed: 1143 additions & 1095 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface ProtocolHost {
6868
readonly assertVersionMatch: ObjectStackProtocolImplementation['assertVersionMatch'];
6969
readonly authoredLockFamily: ObjectStackProtocolImplementation['authoredLockFamily'];
7070
readonly authoringChannel: ObjectStackProtocolImplementation['authoringChannel'];
71+
readonly authoringGates: ObjectStackProtocolImplementation['authoringGates'];
7172
readonly baseServesBundleMember: ObjectStackProtocolImplementation['baseServesBundleMember'];
7273
readonly carryForwardRedactedCredentials: ObjectStackProtocolImplementation['carryForwardRedactedCredentials'];
7374
readonly classifyObjectContribution: ObjectStackProtocolImplementation['classifyObjectContribution'];
@@ -80,6 +81,7 @@ export interface ProtocolHost {
8081
readonly convertStoredItemDetailed: ObjectStackProtocolImplementation['convertStoredItemDetailed'];
8182
readonly copiesOwnShippedViewContainer: ObjectStackProtocolImplementation['copiesOwnShippedViewContainer'];
8283
readonly credentialChannelFor: ObjectStackProtocolImplementation['credentialChannelFor'];
84+
readonly credentialChannels: ObjectStackProtocolImplementation['credentialChannels'];
8385
readonly declinesStoredRow: ObjectStackProtocolImplementation['declinesStoredRow'];
8486
readonly defaultRecordPageSaveRefusal: ObjectStackProtocolImplementation['defaultRecordPageSaveRefusal'];
8587
readonly detachMetadataMutationPubSub: ObjectStackProtocolImplementation['detachMetadataMutationPubSub'];
@@ -140,6 +142,7 @@ export interface ProtocolHost {
140142
readonly metaItemPublishedListeners: ObjectStackProtocolImplementation['metaItemPublishedListeners'];
141143
readonly metadataConflictRefusal: ObjectStackProtocolImplementation['metadataConflictRefusal'];
142144
readonly metadataMutationListeners: ObjectStackProtocolImplementation['metadataMutationListeners'];
145+
readonly mutationProjectors: ObjectStackProtocolImplementation['mutationProjectors'];
143146
readonly namedBaseOverlayWriteRefusal: ObjectStackProtocolImplementation['namedBaseOverlayWriteRefusal'];
144147
readonly namesWithOwnStoredRow: ObjectStackProtocolImplementation['namesWithOwnStoredRow'];
145148
readonly notifyMutationListenersLocal: ObjectStackProtocolImplementation['notifyMutationListenersLocal'];
@@ -154,6 +157,7 @@ export interface ProtocolHost {
154157
readonly overlayPackageMismatchError: (typeof ObjectStackProtocolImplementation)['overlayPackageMismatchError'];
155158
readonly overlayRepos: ObjectStackProtocolImplementation['overlayRepos'];
156159
readonly overrideWriteVerdict: ObjectStackProtocolImplementation['overrideWriteVerdict'];
160+
readonly packagedArtifactBase: ObjectStackProtocolImplementation['packagedArtifactBase'];
157161
readonly packagedArtifactOwner: ObjectStackProtocolImplementation['packagedArtifactOwner'];
158162
readonly packagedBaseRefusal: ObjectStackProtocolImplementation['packagedBaseRefusal'];
159163
readonly packagelessAddress: ObjectStackProtocolImplementation['packagelessAddress'];
@@ -166,6 +170,7 @@ export interface ProtocolHost {
166170
readonly probeRecord: ObjectStackProtocolImplementation['probeRecord'];
167171
readonly promoteDraftForPublish: ObjectStackProtocolImplementation['promoteDraftForPublish'];
168172
readonly publishMaterializers: ObjectStackProtocolImplementation['publishMaterializers'];
173+
readonly publishMetadataMutation: ObjectStackProtocolImplementation['publishMetadataMutation'];
169174
readonly readActiveOverlayRows: ObjectStackProtocolImplementation['readActiveOverlayRows'];
170175
readonly readFlattenedMetaItems: ObjectStackProtocolImplementation['readFlattenedMetaItems'];
171176
readonly readItemActiveRows: ObjectStackProtocolImplementation['readItemActiveRows'];

0 commit comments

Comments
 (0)