Skip to content

Commit dda5102

Browse files
committed
refactor(metadata-protocol): move parseCommitItems out of protocol.ts into protocol-commit-items.ts
Move-only cut 32 of the protocol.ts split. The body of the private parseCommitItems member moves unedited into a new module as a plain function; it reads no class member, so the class method's body calls it directly. CommitPlanItem gains `export` in place so the new module can import it as a type; index.ts does not re-export it. Claude-Session: https://claude.ai/code/session_01L6bhgVaAsaDVwT6XfwB5yk Co-authored-by: Claude <noreply@anthropic.com>
1 parent c4c515a commit dda5102

2 files changed

Lines changed: 49 additions & 11 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#25467 cut 32] A stored commit row's `items` column read back as its revert
5+
* plan, from `ObjectStackProtocolImplementation`, moved out of `protocol.ts`
6+
* whole: `parseCommitItems`, which `listPackageCommits` and `revertCommit`
7+
* call. An array is the plan as stored; a string is parsed as JSON; anything
8+
* else, or a string that is not a JSON array, reads as no items.
9+
*
10+
* A MOVE, not a redesign. The function below is the body of the
11+
* `ObjectStackProtocolImplementation` method of the same name as it stood,
12+
* re-indented one level and otherwise unedited.
13+
*
14+
* ## How the moved body reaches the class
15+
*
16+
* The shape #23050 set for `rest-server.ts` (its `data-action-routes.ts`
17+
* header carries the full reasoning), as `protocol-batch-data.ts` applies it.
18+
* The class keeps the method — the published `dist/*.d.ts` lists its name
19+
* and declared signature. The body reads no class member, so the method's
20+
* body calls the plain function, with no host. Every caller keeps calling the
21+
* class method.
22+
*
23+
* The plan item type is `protocol.ts`'s own, and is imported from there as a
24+
* type. Nothing re-exports this module, so the published surface does not
25+
* move.
26+
*/
27+
28+
import type { CommitPlanItem } from './protocol.js';
29+
30+
/** The body of `ObjectStackProtocolImplementation#parseCommitItems`. */
31+
export function parseCommitItems(
32+
raw: unknown,
33+
): CommitPlanItem[] {
34+
if (Array.isArray(raw)) return raw as CommitPlanItem[];
35+
if (typeof raw === 'string') {
36+
try {
37+
const p = JSON.parse(raw);
38+
return Array.isArray(p) ? p : [];
39+
} catch {
40+
return [];
41+
}
42+
}
43+
return [];
44+
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ import { legacyOrganizationRowsOf, withoutLegacyOrganizationRows } from './proto
427427
import { foldObjectExtendersFromRegistry } from './protocol-object-extender-fold.js';
428428
// [#25467 cut 31] The disabled-package face of the by-name item read.
429429
import { readMetaItemFace } from './protocol-meta-item-face.js';
430+
// [#25467 cut 32] A stored commit row's `items` column read back as its revert plan.
431+
import { parseCommitItems } from './protocol-commit-items.js';
430432

431433
/**
432434
* Canonical Zod schema per metadata type lives in
@@ -2748,7 +2750,7 @@ function mutationEventMember(type: string, member: string | null | undefined): {
27482750
* timeline serves it on every item of a bundled type, the canonical member
27492751
* spelled out ({@link ObjectStackProtocolImplementation.listCommits}).
27502752
*/
2751-
type CommitPlanItem = { type: string; name: string; existedBefore: boolean; prevVersion: number | null; member?: string };
2753+
export type CommitPlanItem = { type: string; name: string; existedBefore: boolean; prevVersion: number | null; member?: string };
27522754

27532755
/** [#22877] The identity of a plan item or a draft within one batch: two members of one name are two. */
27542756
function commitPlanKey(item: { type: string; name: string; member?: string }): string {
@@ -26479,16 +26481,8 @@ export class ObjectStackProtocolImplementation implements
2647926481
private parseCommitItems(
2648026482
raw: unknown,
2648126483
): CommitPlanItem[] {
26482-
if (Array.isArray(raw)) return raw as CommitPlanItem[];
26483-
if (typeof raw === 'string') {
26484-
try {
26485-
const p = JSON.parse(raw);
26486-
return Array.isArray(p) ? p : [];
26487-
} catch {
26488-
return [];
26489-
}
26490-
}
26491-
return [];
26484+
// [#25467 cut 32] The body moved to `protocol-commit-items.ts`; it reads no member.
26485+
return parseCommitItems(raw);
2649226486
}
2649326487

2649426488
/**

0 commit comments

Comments
 (0)