/** * @module branch-helper * * B2tFS Branch Helper functions: dedicated branch spaces (`b2s~...`), branch creation, * and branch timeline tracking. */ import { Ib } 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 { B2tFSBranchIbGib_V1, B2tFSBranchIb_V1, BranchInfo, CompositeBranchNode } from './branch-types.mjs'; import { B2tFSItemIbGib_V1 } from '../item/item-types.mjs'; import { B2tFSGalaxyIbGib_V1 } from '../b2tfs-galaxy/b2tfs-galaxy-types.mjs'; import { GalaxyIbGib_V1 } from '../../galaxy/galaxy-types.mjs'; import { SpaceQualifiedIbGibAddr } from '../../../common/other/ibgib-types.mjs'; /** * Regular expression validating allowed branch names. * Allows letters, numbers, hyphens, underscores, and dots. * Must start and end with an alphanumeric character. */ export declare const BRANCH_NAME_REGEXP: RegExp; /** * Validates a proposed branch name. * - Non-empty, max 64 chars * - Allowed chars: alphanumerics, hyphens (-), underscores (_), and dots (.) * - Must start and end with an alphanumeric char * - Cannot contain tildes (~), spaces, or consecutive dots (..) */ export declare function validateBranchName(name?: string): { isValid: boolean; error?: string; }; export declare function isValidBranchName(name?: string): boolean; /** * Generates a dedicated branch space name. * Follows the cosmology delimiter convention: * Example: ('main', 'code-1') -> 'b2s~code-1~main' * Example: ('main', 'code-1', 'cosmos-1') -> 'b2s~cosmos-1~code-1~main' */ export declare function getB2tFSBranchSpaceName(branchName: string, galaxyName?: string, cosmosName?: string): string; export declare function getBranchIb({ branchName, uuid }: { branchName: string; uuid: string; }): Ib; export declare function parseBranchIb({ ib }: { ib: Ib; }): B2tFSBranchIb_V1; /** * Creates a new B2tFSBranchIbGib pointing to a root folder item. */ export declare function createB2tFSBranchIbGib(opts: { branchName: string; rootItem: B2tFSItemIbGib_V1; space: IbGibSpaceAny; metaspace: MetaspaceService; parentBranchSqAddr?: SpaceQualifiedIbGibAddr; parentBranchName?: string; scopedItemPath?: string; uuid?: string; }): Promise; /** * Evolves a B2tFSBranchIbGib pointing to a new root item. */ export declare function evolveB2tFSBranchIbGib(opts: { existingBranch: B2tFSBranchIbGib_V1; rootItem: B2tFSItemIbGib_V1; space: IbGibSpaceAny; metaspace: MetaspaceService; commentAddr?: string; }): Promise; /** * Registers a new child sub-branch on an existing parent branch stone by evolving * the parent branch to append the child's space-qualified address to its `$@branch` list. */ export declare function registerSubBranchOnParent({ parentBranchIbGib, childBranchSqAddr, space, metaspace, }: { parentBranchIbGib: B2tFSBranchIbGib_V1; childBranchSqAddr: SpaceQualifiedIbGibAddr; space: IbGibSpaceAny; metaspace: MetaspaceService; }): Promise; /** * Resolves the contextual branch name given the target directory and repository root. * If targetDir is physically located inside a secondary branch worktree (`b2tfsGalaxyRoot/b/`), * that worktree's branchName is returned. Otherwise, the galaxy's activeBranch (defaulting to 'main') is returned. */ export declare function resolveContextualBranchName({ targetDir, b2tfsGalaxyRoot, galaxyIbGib, }: { targetDir?: string; b2tfsGalaxyRoot?: string; galaxyIbGib: B2tFSGalaxyIbGib_V1; }): string; export interface GetOrCreateBranchSpaceOpts { metaspace: MetaspaceService; branchName: string; galaxyName?: string; cosmosName?: string; spaceId?: string; } export interface GetOrCreateBranchSpaceResult { space: IbGibSpaceAny; spaceId: string; spaceName: string; } /** * Gets an existing branch space or creates and registers a new dedicated NodeFilesystemSpace_V1 in metaspace. */ export declare function getOrCreateBranchSpace({ metaspace, branchName, galaxyName, cosmosName, spaceId, }: GetOrCreateBranchSpaceOpts): Promise; export interface InitBranchSpaceOpts { metaspace: MetaspaceService; branchName: string; galaxyName?: string; cosmosName?: string; spaceId?: string; } export interface EnsureBranchSpaceOpts { metaspace: MetaspaceService; branchName: string; galaxyName?: string; cosmosName?: string; spaceId?: string; } /** * Initializes a new dedicated branch space in metaspace. * Fails fast (throws) if the branch space already exists. */ export declare function initBranchSpace(opts: InitBranchSpaceOpts): Promise; /** * Ensures an existing dedicated branch space in metaspace. * Fails fast (throws) if the branch space does not exist. Never creates. */ export declare function ensureBranchSpace(opts: EnsureBranchSpaceOpts): Promise; /** * Helper to recursively search a CompositeBranchNode tree for a specific branchName. */ export declare function findNodeInTree(node: CompositeBranchNode, branchName: string): CompositeBranchNode | undefined; /** * Helper to prune a CompositeBranchNode tree to a maximum depth. */ export declare function pruneTreeDepth(node: CompositeBranchNode, maxDepth: number, currentDepth?: number): CompositeBranchNode; /** * Flattens all CompositeBranchNode nodes into a flat array of BranchInfo[]. */ export declare function flattenCompositeBranchTree(rootNode: CompositeBranchNode): BranchInfo[]; export interface GetCompositeBranchTreeFromBranchOpts { branchIbGib?: B2tFSBranchIbGib_V1; branchSqAddr?: SpaceQualifiedIbGibAddr; branchSpace?: IbGibSpaceAny; metaspace: MetaspaceService; /** * Maximum depth to traverse. * 0 = current branch only (no children). * 1 = current branch + immediate children. * undefined = full recursion. */ depth?: number; currentDepth?: number; } /** * Recursively traverses the composite tree of branches starting from a specific branch stone. */ export declare function getCompositeBranchTreeFromBranch(opts: GetCompositeBranchTreeFromBranchOpts): Promise; export interface GetCompositeBranchTreeFromGalaxyOpts { galaxyIbGib: B2tFSGalaxyIbGib_V1 | GalaxyIbGib_V1; metaspace: MetaspaceService; startBranchName?: string; depth?: number; } /** * Retrieves the composite branch tree for a galaxy starting from the canonical trunk ('main') * or a specified starting branch name. */ export declare function getCompositeBranchTreeFromGalaxy(opts: GetCompositeBranchTreeFromGalaxyOpts): Promise; /** * Retrieves all BranchInfo instances across the galaxy's composite branch hierarchy. */ export declare function getAllBranchInfosFromGalaxy({ galaxyIbGib, metaspace, depth, }: { galaxyIbGib: B2tFSGalaxyIbGib_V1 | GalaxyIbGib_V1; metaspace?: MetaspaceService; depth?: number; }): Promise; export declare function getBranchInfoFromGalaxy({ galaxyIbGib, branchName, metaspace, }: { galaxyIbGib: B2tFSGalaxyIbGib_V1 | GalaxyIbGib_V1; branchName: string; metaspace?: MetaspaceService; }): Promise; /** * Retrieves all registered B2tFSBranchIbGib_V1 instances across the galaxy's composite branch hierarchy. */ export declare function getAllBranchIbGibsFromGalaxy({ galaxyIbGib, metaspace, }: { galaxyIbGib: B2tFSGalaxyIbGib_V1 | GalaxyIbGib_V1; metaspace: MetaspaceService; }): Promise; //# sourceMappingURL=branch-helpers.d.mts.map