import { Mutex } from 'async-mutex'; import type { ComponentID } from '@teambit/component-id'; import type { PathOsBasedAbsolute } from '@teambit/legacy.utils'; import type { Types, ScopeJson } from '@teambit/legacy.scope'; import { UnmergedComponents, RemoteLanes } from '@teambit/legacy.scope'; import type { IndexType } from './scope-index'; import { ScopeIndex } from './scope-index'; import BitObject from './object'; import type { ObjectItem } from './object-list'; import { ObjectList } from './object-list'; import BitRawObject from './raw-object'; import Ref from './ref'; import type { InMemoryCache } from '@teambit/harmony.modules.in-memory-cache'; type ContentTransformer = (content: Buffer) => Buffer; export default class Repository { objects: { [key: string]: BitObject; }; objectsToRemove: Ref[]; scopeJson: ScopeJson; onRead: ContentTransformer; onPersist: ContentTransformer; scopePath: string; scopeIndex: ScopeIndex; protected cache: InMemoryCache; remoteLanes: RemoteLanes; unmergedComponents: UnmergedComponents; _persistMutex?: Mutex; constructor(scopePath: string, scopeJson: ScopeJson); get persistMutex(): Mutex; static load({ scopePath, scopeJson }: { scopePath: string; scopeJson: ScopeJson; }): Promise; init(): Promise; static create({ scopePath, scopeJson }: { scopePath: string; scopeJson: ScopeJson; }): Promise; static reset(scopePath: string): Promise; static getPathByScopePath(scopePath: string): string; static onPostObjectsPersist: () => Promise; /** * Hook for transforming content before objects are persisted to the filesystem. * Note: This function cannot be async because it's used by the synchronous `loadSync` method * which needs to maintain sync behavior for compatibility with existing code. */ static onPreObjectPersist: (content: Buffer) => Buffer; /** * Hook for transforming content after objects are read from the filesystem. * Note: This function cannot be async because it's used by the synchronous `loadSync` method * which needs to maintain sync behavior for compatibility with existing code. */ static onPostObjectRead: (content: Buffer) => Buffer; reLoadScopeIndex(): Promise; /** * current scope index difference with /index.json content, reload it * @deprecated use Scope aspect `watchSystemFiles` instead, it's way more efficient. */ reloadScopeIndexIfNeed(force?: boolean): Promise; ensureDir(): Promise; getPath(): string; getBackupPath(dirName?: string): string; getTrashDir(): string; getLicense(): Promise; getScopeMetaObject(): Promise; objectPath(ref: Ref): string; has(ref: Ref): Promise; hasMultiple(refs: Ref[]): Promise; load(ref: Ref, throws?: boolean): Promise; /** * this is restricted to provide objects according to the given types. Otherwise, big scopes (>1GB) could crush. * example usage: `this.list([ModelComponent, Symlink, Lane])` */ list(types: Types): Promise; loadRefDeleteIfInvalid(ref: Ref): Promise; loadRefOnlyIfType(ref: Ref, types: Types): Promise; listRefs(cwd?: string): Promise>; listRefsStartWith(shortHash: Ref): Promise>; listRawObjects(): Promise; listObjectsFromIndex(indexType: IndexType, filter?: Function): Promise; getHashFromIndex(indexType: IndexType, filter: Function): string | null; _getBitObjectsByHashes(hashes: string[]): Promise; loadOptionallyCreateScopeIndex(): Promise; loadRaw(ref: Ref): Promise; getFullRefFromShortHash(ref: Ref): Promise; loadManyRaw(refs: Ref[]): Promise; loadManyRawIgnoreMissing(refs: Ref[]): Promise; loadRawObject(ref: Ref): Promise; /** * prefer using `this.load()` for an async version, which also writes to the cache */ loadSync(ref: Ref, throws?: boolean): BitObject; setCache(object: BitObject): this; getCache(ref: Ref): BitObject | undefined; removeFromCache(ref: Ref): void; clearCache(): Promise; clearObjectsFromCache(): void; backup(dirName?: string): void; add(object: BitObject | null | undefined): Repository; addMany(objects: BitObject[]): Repository; removeObject(ref: Ref): void; removeManyObjects(refs: Ref[]): void; findMany(refs: Ref[]): Promise; /** * important! use this method only for commands that are non running on an http server. * * it's better to remove/delete objects directly and not using the `objects` member. * it helps to avoid multiple processes running concurrently on an http server. * * persist objects changes (added and removed) into the filesystem * do not call this function multiple times in parallel, otherwise, it'll damage the index.json file. * call this function only once after you added and removed all applicable objects. */ persist(validate?: boolean): Promise; writeRemoteLanes(): Promise; /** * this is especially critical for http server, where one process lives long and serves multiple * exports. without this, the objects get accumulated over time and being rewritten over and over * again. */ private clearObjects; /** * normally, the validation step takes place just before the acutal writing of the file. * however, this can be an issue where a component has an invalid version. the component could * be saved before validating the version (see #1727). that's why we validate here before writing * anything to the filesystem. * the open question here is whether should we validate again before the actual writing or it * should be enough to validate here? * for now, it does validate again before saving, only to be 100% sure nothing happens in a few * lines of code until the actual writing. however, if the performance penalty is noticeable, we * can easily revert it by changing `bitObject.validateBeforePersist = false` line run regardless * the `validate` argument. */ validateObjects(validate: boolean, objects: BitObject[]): void; deleteObjectsFromFS(refs: Ref[]): Promise; moveObjectsToDir(refs: Ref[], dir: string): Promise; moveObjectsToTrash(refs: Ref[]): Promise; listTrash(): Promise; getFromTrash(refs: Ref[]): Promise; restoreFromTrash(refs: Ref[]): Promise; restoreFromDir(dir: string, overwrite?: boolean): Promise; private moveOneObjectToDir; private moveOneObjectToTrash; deleteRecordsFromUnmergedComponents(compIds: ComponentID[]): Promise; /** * write all objects to the FS and index the components/lanes/symlink objects */ writeObjectsToTheFS(objects: BitObject[]): Promise; /** * do not call this method directly. always call this.removeObject() and once done with all objects, * call this.persist() */ _deleteOne(ref: Ref): Promise; /** * always prefer this.persist() or this.writeObjectsToTheFS() * this method doesn't write to scopeIndex. so using this method for ModelComponent or * Symlink makes the index outdated. */ _writeOne(object: BitObject): Promise; writeObjectsToPendingDir(objectList: ObjectList, pendingDir: PathOsBasedAbsolute): Promise; readObjectsFromPendingDir(pendingDir: PathOsBasedAbsolute): Promise; private hashPath; } export {};