import { ComponentID, ComponentIdList } from '@teambit/component-id'; import { LaneId } from '@teambit/lane-id'; import type { BuildStatus } from '@teambit/legacy.constants'; import type { ConsumerComponent } from '@teambit/legacy.consumer-component'; import { Dependencies, Dependency } from '@teambit/legacy.consumer-component'; import { SourceFile } from '@teambit/component.sources'; import type { ComponentOverridesData } from '@teambit/legacy.consumer-config'; import { ExtensionDataList } from '@teambit/legacy.extension-data'; import type { Doclet } from '@teambit/semantics.doc-parser'; import type { PathLinux } from '@teambit/legacy.utils'; import type { Repository } from '../objects'; import { BitObject, Ref } from '../objects'; import type { ObjectItem } from '../objects/object-list'; import Source from './source'; import { DependenciesGraph } from './dependencies-graph'; export type SourceFileModel = { name: string; relativePath: PathLinux; test: boolean; file: Ref; }; export type DistFileModel = SourceFileModel; export type ArtifactFileModel = { relativePath: PathLinux; file: Ref; }; export type Log = { message: string; date: string; username: string | undefined; email: string | undefined; }; export type DepEdgeType = 'prod' | 'dev' | 'peer' | 'ext'; export type DepEdge = { source: ComponentID; target: ComponentID; type: DepEdgeType; }; type ExternalHead = { head: Ref; laneId: LaneId; }; type SquashData = { previousParents: Ref[]; laneId: LaneId; }; type VersionOrigin = { id: { scope: string; name: string; }; lane?: { scope: string; name: string; hash: string; }; }; export type VersionProps = { mainFile: PathLinux; files: Array; log: Log; docs?: Doclet[]; dependencies?: Dependency[]; devDependencies?: Dependency[]; peerDependencies?: Dependency[]; flattenedDependencies?: ComponentIdList; _flattenedEdges?: DepEdge[]; flattenedEdges?: DepEdge[]; flattenedEdgesRef?: Ref; dependenciesGraphRef?: Ref; packageDependencies?: { [key: string]: string; }; devPackageDependencies?: { [key: string]: string; }; peerPackageDependencies?: { [key: string]: string; }; bindingPrefix: string; schema?: string; overrides: ComponentOverridesData; packageJsonChangedProps?: Record; hash?: string; parents?: Ref[]; squashed?: SquashData; unrelated?: ExternalHead; extensions?: ExtensionDataList; buildStatus?: BuildStatus; componentId?: ComponentID; bitVersion?: string; modified?: Log[]; origin?: VersionOrigin; hidden?: boolean; }; /** * Represent a version model in the scope */ export default class Version extends BitObject { mainFile: PathLinux; files: Array; log: Log; docs: Doclet[] | undefined; dependencies: Dependencies; devDependencies: Dependencies; peerDependencies: Dependencies; flattenedDependencies: ComponentIdList; dependenciesGraphRef?: Ref; _dependenciesGraph?: DependenciesGraph; flattenedEdgesRef?: Ref; _flattenedEdges?: DepEdge[]; /** * @deprecated * to get the flattenedEdges, please use `this.getFlattenedEdges()`. * this function handles the backward compatibility and provides the flattened edges regardless whether it was saved * the `flattenedEdgesRef` introduced or after. * * the reason this is left here is not for backward compatibility, but for forward compatibility. meaning, if a * Version object created by the new version is parsed by an old version that doesn't support the flattenedEdgesRef, * then, it'll be able to still get the flattenedEdges by this prop. * this is causing duplication currently. the data is kept in both, `this.flattenedEdges` and the file stored in `flattenedEdgesRef`. * so it'll be best to delete this prop as soon as all scopes are deployed with the new version. * (around August 2023 should be safe) */ private flattenedEdges; packageDependencies: { [key: string]: string; }; devPackageDependencies: { [key: string]: string; }; peerPackageDependencies: { [key: string]: string; }; bindingPrefix: string; schema: string | undefined; overrides: ComponentOverridesData; packageJsonChangedProps: Record; _hash: string; parents: Ref[]; squashed?: SquashData; unrelated?: ExternalHead; extensions: ExtensionDataList; buildStatus?: BuildStatus; componentId?: ComponentID; bitVersion?: string; modified: Log[]; origin?: VersionOrigin; hidden?: boolean; constructor(props: VersionProps); /** * use only this method to get the flattened edges (graph of flattened dependencies). * it's backward compatible with the previous way this was stored on the Version object itself. */ getFlattenedEdges(repo: Repository): Promise; loadDependenciesGraph(repo: Repository): Promise; validateVersion(): void; id(): string; calculateHash(): Ref; hash(): Ref; get extensionDependencies(): Dependencies; lastModified(): string; getAllFlattenedDependencies(): ComponentIdList; getAllDependencies(): Dependency[]; get depsIdsGroupedByType(): { dependencies: ComponentIdList; devDependencies: ComponentIdList; peerDependencies: ComponentIdList; extensionDependencies: ComponentIdList; }; getAllDependenciesCloned(): Dependencies; getAllDependenciesIds(): ComponentIdList; getDependenciesIdsExcludeExtensions(): ComponentIdList; updateFlattenedDependency(currentId: ComponentID, newId: ComponentID): void; refs(): Ref[]; refsWithOptions(includeParents?: boolean, includeArtifacts?: boolean): Ref[]; refsWithoutParents(): Ref[]; collectManyObjects(repo: Repository, refs: Ref[]): Promise; static depEdgeToObject(depEdge: DepEdge): Record; static depEdgeFromObject(depEdgeObj: Record): DepEdge; /** * until 1.9.86, we used depEdgeToObject. * this one makes this object much much smaller (for 604 edges, it's now 143KB, with the array format it's 6KB!) * this format has been supported (but not used) since v1.6.97. */ static depEdgeToArray(depEdge: DepEdge): Record; static depEdgeFromArray(depEdgeArr: string[]): DepEdge; static flattenedEdgeToSource(flattenedEdges?: DepEdge[]): Source | undefined; static dependenciesGraphToSource(dependenciesGraph?: DependenciesGraph): Source | undefined; toObject(): import("lodash").Dictionary | string[] | Record[] | Doclet[] | { file: any; relativePath: any; name: any; test: any; }[] | import("@teambit/component-id").ComponentIdObj[] | { extensionId: ComponentID | import("@teambit/component-id").ComponentIdObj | undefined; config: { [key: string]: any; }; data: { [key: string]: any; }; legacyId: string | undefined; name: string | undefined; newExtensionId: ComponentID | undefined; }[] | { [key: string]: string; } | { [key: string]: string; } | { [key: string]: string; } | ComponentOverridesData | Log[] | VersionOrigin | { message: string; date: string; username: string | undefined; email: string | undefined; previousParents?: undefined; laneId?: undefined; head?: undefined; } | { previousParents: string[]; laneId: { scope: string; name: string; }; message?: undefined; date?: undefined; username?: undefined; email?: undefined; head?: undefined; } | { head: string; laneId: { scope: string; name: string; }; message?: undefined; date?: undefined; username?: undefined; email?: undefined; previousParents?: undefined; } | null | undefined>; validateBeforePersisting(versionStr: string): void; toBuffer(pretty: boolean): Buffer; /** * used by the super class BitObject */ static parse(contents: string, hash: string): Version; /** * used by raw-object.toRealObject() */ static from(versionProps: VersionProps, hash: string): Version; /** * Create version model object from consumer component * @param {*} param0 */ static fromComponent({ component, files, flattenedEdges, dependenciesGraph, }: { component: ConsumerComponent; files: Array; flattenedEdges?: Source; dependenciesGraph?: Source; }): Version; setNewHash(): void; get ignoreSharedDir(): boolean; get isLegacy(): boolean; get originLaneId(): LaneId | undefined; get originId(): ComponentID | undefined; setDist(dist: Source | undefined): void; hasParent(ref: Ref): Ref | undefined; addParent(ref: Ref): void; setSquashed(squashData: SquashData, log: Log, replaceMessage?: string): void; setUnrelated(externalHead: ExternalHead): void; addModifiedLog(log: Log): void; addAsOnlyParent(ref: Ref): void; removeParent(ref: Ref): void; removeAllParents(): void; modelFilesToSourceFiles(repository: Repository): Promise; isRemoved(): boolean; shouldRemoveFromMain(): boolean; /** * Validate the version model properties, to make sure we are not inserting something * in the wrong format */ validate(): void; } export {};