/** * @module item-helper * * B2tFS Item Helper functions: graph diff generation, filesystem projection materialization, * and two-pass transform application. */ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs'; import { TransformResult, IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs'; import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs'; import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs'; import { B2tFSItemIbGib_V1, B2tFSItemData_V1, B2tFSItemRel8ns_V1, B2tFSItemDiffInfo, BranchAndRootItemInfosAndIbGibsAndSpace } from './item-types.mjs'; import { B2tFSBranchIbGib_V1 } from '../branch/branch-types.mjs'; import { B2tFSGalaxyIbGib_V1 } from '../b2tfs-galaxy/b2tfs-galaxy-types.mjs'; import { CommentIbGib_V1 } from '../../../common/comment/comment-types.mjs'; export declare function isB2tFSItemIbGib(x: any): x is B2tFSItemIbGib_V1; export interface CreateB2tFSItemIbGibOpts { fsType: 'file' | 'folder'; name: string; data?: Partial; rel8ns?: Partial; } export interface EvolveB2tFSItemIbGibOpts { existingItem: B2tFSItemIbGib_V1; dataToUpdate?: Partial; rel8nsToUpdate?: Partial; rel8nsToRemove?: Partial; } /** * Creates a brand-new B2tFSItemIbGib_V1 node using Factory_V1.firstGen with TJP, DNA, and nCounter. * Used ONLY for brand-new files or folders. */ export declare function createB2tFSItemIbGib({ fsType, name, data, rel8ns, }: CreateB2tFSItemIbGibOpts): Promise>; /** * Evolves an existing B2tFSItemIbGib_V1 node using mut8 (for data/hash updates) * and rel8 (for binary/child link updates) with DNA, nCounter, and timeline tracking. * Populates rel8ns.past and rel8ns.ancestor, preserving the item's TJP to generate * composite two-part timeline gib addresses (^). */ export declare function evolveB2tFSItemIbGib({ existingItem, dataToUpdate, rel8nsToUpdate, rel8nsToRemove, }: EvolveB2tFSItemIbGibOpts): Promise>; /** * Projects a B2tFS item graph back onto the workspace using a WorkspaceProjectionSpace. */ export declare function writeB2tFSItemToWorkspace({ item, workspaceSpace, }: { item: B2tFSItemIbGib_V1; workspaceSpace: IbGibSpaceAny; }): Promise; /** * Projects a B2tFS item graph onto a workspace projection space. * Retained with backward-compatible signature for existing calls. */ export declare function writeB2tFSItemToFS({ item, workspaceSpace, space, }: { item: B2tFSItemIbGib_V1; workspaceSpace?: IbGibSpaceAny; destPath?: string; space?: IbGibSpaceAny; metaspace?: MetaspaceService; }): Promise; /** * Executes two-pass application of diff transform results: * 1. Persists all child and parent transform results to space. * 2. Registers new IbGib pointers with metaspace to advance timeline tips. */ export declare function applyB2tFSItemDiff({ diff, space, metaspace, }: { diff: B2tFSItemDiffInfo; space: IbGibSpaceAny; metaspace: MetaspaceService; }): Promise; export interface ReifyB2tFSHierarchyOpts { /** Root B2tFS item (folder or file). Either rootItem or rootItemAddr required. */ rootItem?: B2tFSItemIbGib_V1; /** Address of root B2tFS item. Either rootItem or rootItemAddr required. */ rootItemAddr?: IbGibAddr; /** Space containing the branch items and updated timeline tips. */ space: IbGibSpaceAny; /** Metaspace service instance for lookups and registrations. */ metaspace: MetaspaceService; } export interface ReifyB2tFSHierarchyResult { /** The reified root B2tFS item (evolved if any descendants changed, or unchanged if no descendants changed). */ reifiedRootItem: B2tFSItemIbGib_V1; /** True if one or more folder/file nodes in the hierarchy evolved to new tips. */ hasChanges: boolean; /** Map of old address -> new address for every node that evolved in this reification run. */ reifiedAddrsMap: { [oldAddr: string]: string; }; /** All newly evolved and persisted intermediate/root folder items created during reification. */ evolvedItems: B2tFSItemIbGib_V1[]; } /** * Reifies a B2tFS filesystem item hierarchy (folders and files) bottom-up. * * Traverses `b2tfs_child` relationship edges. If any child timeline advanced * in `space` (e.g. during a 3-way merge or parallel commit), the parent folders * are evolved in-place using `rel8` with the updated child tip addresses. */ export declare function reifyB2tFSHierarchy({ rootItem, rootItemAddr, space, metaspace, }: ReifyB2tFSHierarchyOpts): Promise; /** * gets the root item addr for the branch ({@link B2tFSBranchRel8ns_V1.b2tfs_item}). * * if {@link addrOnly}, gets the ibGib as well from {@link branchSpace} */ export declare function getRootItemFromBranchIbGib({ branchIbGib, addrOnly, branchSpace, }: { /** * branch ibgib whose root item we are getting. */ branchIbGib: B2tFSBranchIbGib_V1; /** * if true, only will get the root item's addr from {@link branchIbGib}, * else will get the full {@link B2tFSItemIbGib_V1} ibgib. */ addrOnly: boolean; /** * if {@link addrOnly} is false, this is required and used for getting the * full {@link B2tFSItemIbGib_V1} ibgib. */ branchSpace?: IbGibSpaceAny; }): Promise<{ rootItemAddr: IbGibAddr; rootItemIbGib?: B2tFSItemIbGib_V1; }>; /** * Goes from a galaxy ibgib all the way down to the latest root item ibgib. * * ## notes * * I usually don't do these long methods like this, but there are just so many * places where we want to get all of these things and we want to get the * latest, and this just DRYs up the code. * * @returns The Works: branch stuff, root stuff, ibgibs, and the branch space * @see {@link BranchAndRootItemInfosAndIbGibsAndSpace} */ export declare function getBranchAndRootItemInfosAndIbGibsAndSpaceFromGalaxyIbGib({ galaxyIbGib, branchName, metaspace, }: { galaxyIbGib: B2tFSGalaxyIbGib_V1; branchName: string; metaspace: MetaspaceService; }): Promise; /** * Creates a virtual/non-CAS B2tFS item IbGib whose content is inlined directly * in `virtualFileContents`. * * Used primarily for scaffolding workspace artifacts (such as companion markdown * notes `.ib..md` or template files) that need to be projected onto * a workspace without creating or linking underlying CAS BinIbGibs. */ export declare function createVirtualItemIbGib({ name, content, }: { /** * File path or file name relative to the workspace projection target (e.g. `src/.ib.auth.ts.md`). */ name: string; /** * Direct string contents to be written to the workspace file. */ content: string; }): Promise; /** * Retrieves the text content of a B2tFS file item by inspecting its binary stone or virtual payload. */ export declare function getFileContent({ branchSpace, fileItem, }: { branchSpace: IbGibSpaceAny; fileItem: B2tFSItemIbGib_V1; }): Promise; /** * Recursively resolves a file or folder item by relative path (e.g. 'welcome.ts' or 'src/index.ts'). */ export declare function getFileItemFromPath({ branchSpace, rootItem, filePath, }: { branchSpace: IbGibSpaceAny; rootItem: B2tFSItemIbGib_V1; filePath: string; }): Promise; /** * Lists all direct children of a folder item from the branch space using batch get. */ export declare function getFolderChildren({ branchSpace, folderItem, }: { branchSpace: IbGibSpaceAny; folderItem: B2tFSItemIbGib_V1; }): Promise; export interface CreateFileInGalaxyBranchOpts { metaspace: MetaspaceService; branchSpace: IbGibSpaceAny; branchIbGib: B2tFSBranchIbGib_V1; parentFolderItem: B2tFSItemIbGib_V1; fileName: string; content: string; } export interface CreateFileInGalaxyBranchResult { fileItem: B2tFSItemIbGib_V1; evolvedFolder: B2tFSItemIbGib_V1; evolvedBranch: B2tFSBranchIbGib_V1; } /** * Creates a file in a B2tFS branch space, attaches it to the parent folder, * and evolves the branch pointer (a real commit). */ export declare function createFileInGalaxyBranch({ metaspace, branchSpace, branchIbGib, parentFolderItem, fileName, content, }: CreateFileInGalaxyBranchOpts): Promise; export interface ChangedFileInfo { path: string; status: 'untracked' | 'modified' | 'deleted'; content?: string; } export interface CommitChangesToGalaxyBranchOpts { metaspace: MetaspaceService; branchSpace: IbGibSpaceAny; branchIbGib: B2tFSBranchIbGib_V1; rootFolderItem: B2tFSItemIbGib_V1; changes: ChangedFileInfo[]; message: string; author?: string; galaxyIbGib?: B2tFSGalaxyIbGib_V1; localSpace?: IbGibSpaceAny; } export interface CommitChangesToGalaxyBranchResult { evolvedBranch: B2tFSBranchIbGib_V1; evolvedRootFolder: B2tFSItemIbGib_V1; newTipAddr: string; committedCount: number; updatedGalaxy?: B2tFSGalaxyIbGib_V1; commitCommentAddr?: string; commitCommentIbGib?: CommentIbGib_V1; } /** * Commits a batch of working tree changes (new, modified, and deleted files) * directly to a B2tFS branch space, evolving intermediate/root folder items, * and evolving the branch pointer to advance the Merkle timeline. */ export declare function commitChangesToGalaxyBranch({ metaspace, branchSpace, branchIbGib, rootFolderItem, changes, message, author, galaxyIbGib, localSpace, }: CommitChangesToGalaxyBranchOpts): Promise; /** * Resolves the concrete filesystem or virtual substrate filename for an item. * For Package items, this returns the concrete versioned package filename (e.g. 'core-gib-0.1.96.tgz'). * For standard items, this returns the item's raw name (e.g. 'index.mts'). */ export declare function getProjectedItemFilename(item: B2tFSItemIbGib_V1): string; //# sourceMappingURL=item-helpers.d.mts.map