import { Graph } from '@teambit/graph.cleargraph'; import type { AspectLoaderMain, AspectDefinition } from '@teambit/aspect-loader'; import type { CLIMain } from '@teambit/cli'; import type { AspectData, ComponentMain, ResolveAspectsOptions, Component, ComponentFactory, Snap, State } from '@teambit/component'; import type { GraphqlMain } from '@teambit/graphql'; import type { Harmony, SlotRegistry } from '@teambit/harmony'; import type { IsolateComponentsOptions, IsolatorMain } from '@teambit/isolator'; import type { LoggerMain, Logger } from '@teambit/logger'; import type { ExpressMain } from '@teambit/express'; import type { UiMain } from '@teambit/ui'; import { ComponentIdList, ComponentID } from '@teambit/component-id'; import type { DependenciesGraph, DepEdge, ModelComponent, Lane, Version } from '@teambit/objects'; import { ObjectList } from '@teambit/objects'; import type { Scope as LegacyScope, Types } from '@teambit/legacy.scope'; import type { LegacyComponentLog as ComponentLog } from '@teambit/legacy-component-log'; import type { DependencyResolverMain, NodeLinker, VariantPolicy } from '@teambit/dependency-resolver'; import type { Remotes } from '@teambit/scope.remotes'; import type { CompIdGraph } from '@teambit/graph'; import type { WatchOptions } from 'chokidar'; import type { RequireableComponent } from '@teambit/harmony.modules.requireable-component'; import type { SnapsDistance } from '@teambit/component.snap-distance'; import type { AuthData } from '@teambit/scope.network'; import type { FETCH_OPTIONS } from '@teambit/legacy.scope-api'; import type { ConsumerComponent } from '@teambit/legacy.consumer-component'; import { BitId } from '@teambit/legacy-bit-id'; import type { ExtensionDataList } from '@teambit/legacy.extension-data'; import type { EnvsMain } from '@teambit/envs'; import { ScopeComponentLoader } from './scope-component-loader'; import { StagedConfig } from './staged-config'; import type { FilterByStateFunc } from './filter-ids-by-pattern'; import type { ScopeLoadAspectsOptions } from './scope-aspects-loader'; import { ScopeAspectsLoader } from './scope-aspects-loader'; import type { ConfigStoreMain, Store } from '@teambit/config-store'; type RemoteEventMetadata = { auth?: AuthData; headers?: {}; }; type RemoteEvent = (data: Data, metadata: RemoteEventMetadata, errors?: Array) => Promise; type OnPostPutData = { ids: ComponentID[]; lanes: Lane[]; }; type OnPostDeleteData = { ids: ComponentID[]; }; type OnPreFetchObjectData = { ids: string[]; fetchOptions: FETCH_OPTIONS; }; type OnPostPut = RemoteEvent; type OnPostExport = RemoteEvent; type OnPostDelete = RemoteEvent; type OnPostObjectsPersist = RemoteEvent; type OnPreFetchObjects = RemoteEvent; type OnCompAspectReCalc = (component: Component) => Promise; type OnPreObjectPersist = (content: Buffer) => Buffer; type OnPostObjectRead = (content: Buffer) => Buffer; export type OnPostPutSlot = SlotRegistry; export type OnPostDeleteSlot = SlotRegistry; export type OnPostExportSlot = SlotRegistry; export type OnPostObjectsPersistSlot = SlotRegistry; export type OnPreFetchObjectsSlot = SlotRegistry; export type OnCompAspectReCalcSlot = SlotRegistry; export type OnPreObjectPersistSlot = SlotRegistry; export type OnPostObjectReadSlot = SlotRegistry; export type LoadOptions = { /** * In case the component we are loading is app, whether to load it as app (in a scope aspects capsule) */ loadApps?: boolean; /** * In case the component we are loading is env, whether to load it as env (in a scope aspects capsule) */ loadEnvs?: boolean; /** * Should we load the components' aspects (this useful when you only want sometime to load the component itself * as aspect but not its aspects) */ loadCompAspects?: boolean; /** * Should we load the components' custom envs when loading from the scope * This is usually not required unless you load an aspect with custom env from the scope * usually when signing aspects */ loadCustomEnvs?: boolean; }; export type ScopeConfig = { httpTimeOut: number; description?: string; icon?: string; backgroundIconColor?: string; /** * Set a different package manager for the aspects capsules */ aspectsPackageManager?: string; /** * Set a different node linker for the aspects capsules */ aspectsNodeLinker?: NodeLinker; }; export declare class ScopeMain implements ComponentFactory { /** * private reference to the instance of Harmony. */ private harmony; /** * legacy scope */ readonly legacyScope: LegacyScope; /** * component extension. */ readonly componentExtension: ComponentMain; /** * slot registry for subscribing to build */ readonly config: ScopeConfig; private postPutSlot; private postDeleteSlot; private postExportSlot; private postObjectsPersist; preFetchObjects: OnPreFetchObjectsSlot; private OnCompAspectReCalcSlot; private preObjectPersistSlot; private postObjectReadSlot; private isolator; private aspectLoader; readonly logger: Logger; private envs; private dependencyResolver; private configStore; componentLoader: ScopeComponentLoader; constructor( /** * private reference to the instance of Harmony. */ harmony: Harmony, /** * legacy scope */ legacyScope: LegacyScope, /** * component extension. */ componentExtension: ComponentMain, /** * slot registry for subscribing to build */ config: ScopeConfig, postPutSlot: OnPostPutSlot, postDeleteSlot: OnPostDeleteSlot, postExportSlot: OnPostExportSlot, postObjectsPersist: OnPostObjectsPersistSlot, preFetchObjects: OnPreFetchObjectsSlot, OnCompAspectReCalcSlot: OnCompAspectReCalcSlot, preObjectPersistSlot: OnPreObjectPersistSlot, postObjectReadSlot: OnPostObjectReadSlot, isolator: IsolatorMain, aspectLoader: AspectLoaderMain, logger: Logger, envs: EnvsMain, dependencyResolver: DependencyResolverMain, configStore: ConfigStoreMain); priority?: boolean | undefined; localAspects: string[]; /** * Optional hook called immediately before an aspect is `require()`d from a * scope-aspects capsule. Throws to refuse the load. The workspace aspect * registers this to enforce the per-workspace scope-trust list. */ private aspectLoadGuard?; setAspectLoadGuard(guard: (componentId: ComponentID) => Promise): void; getAspectLoadGuard(): ((componentId: ComponentID) => Promise) | undefined; /** * name of the scope */ get name(): string; get icon(): string | undefined; get backgroundIconColor(): string | undefined; get description(): string | undefined; get path(): string; get isLegacy(): boolean; get isGlobalScope(): boolean; get aspectsPackageManager(): string | undefined; get aspectsNodeLinker(): NodeLinker | undefined; reloadAspectsWithNewVersion(components: ConsumerComponent[]): Promise; loadAspects(ids: string[], throwOnError?: boolean | undefined, neededFor?: string | undefined, lane?: Lane, opts?: ScopeLoadAspectsOptions): Promise; resolveAspects(runtimeName?: string | undefined, componentIds?: ComponentID[] | undefined, opts?: ResolveAspectsOptions | undefined): Promise; getResolvedAspects(components: Component[], opts?: { skipIfExists?: boolean; packageManagerConfigRootDir?: string; workspaceName?: string; }): Promise; /** * @param policy the dependencies policy of the component, when the caller already calculated it. */ executeOnCompAspectReCalcSlot(component: Component, policy?: VariantPolicy): Promise; getDependencies(component: Component): import("@teambit/dependency-resolver").DependencyList; componentPackageName(component: Component): string; private upsertExtensionData; private getDataEntry; getIsolateAspectsOpts(opts?: { skipIfExists?: boolean; packageManagerConfigRootDir?: string; workspaceName?: string; }): IsolateComponentsOptions; getAspectCapsulePath(): string; shouldUseHashForCapsules(): boolean; getManyByLegacy(components: ConsumerComponent[]): Promise; getScopeAspectsLoader(): ScopeAspectsLoader; clearCache(): Promise; /** * register to the post-export slot. */ onPostPut(postPutFn: OnPostPut): this; /** * register to the post-delete slot. */ onPostDelete(postDeleteFn: OnPostDelete): this; /** * register to the post-export slot. */ registerOnPostExport(postExportFn: OnPostExport): this; registerOnPreFetchObjects(preFetchObjectsFn: OnPreFetchObjects): this; registerOnCompAspectReCalc(compAspectReCalcSlotFn: OnCompAspectReCalc): void; registerOnPostObjectsPersist(postObjectsPersistFn: OnPostObjectsPersist): this; /** * register to the pre-object persist slot. */ registerOnPreObjectPersist(preObjectPersistFn: OnPreObjectPersist): this; /** * register to the post-object read slot. */ registerOnPostObjectRead(postObjectReadFn: OnPostObjectRead): this; /** * Will fetch a list of components into the current scope. * This will only fetch the object and won't write the files to the actual FS */ fetch(ids: ComponentIdList): void; delete({ ids, force, lanes }: { ids: string[]; force: boolean; lanes: boolean; }, headers?: Record): Promise; isExported(id: ComponentID): boolean; /** * for long-running processes, such as `bit start` or `bit watch`, it's important to keep the following data up to date: * 1. scope-index (.bit/index.json file). * 2. remote-refs (.bit/refs/*). * 3. global config. so for example if a user logs in or out it would be reflected. * it's possible that other commands (e.g. `bit import`) modified these files, while these processes are running. * Because these data are kept in memory, they're not up to date anymore. * * @param watchOptions - chokidar watch options (ignoreInitial is always enforced to true) * @param additionalPaths - extra paths to watch (e.g. IPC events dir, unmerged.json) * @param onAdditionalFileChange - callback invoked when a file in additionalPaths changes */ watchScopeInternalFiles(watchOptions?: WatchOptions, additionalPaths?: string[], onAdditionalFileChange?: (filePath: string) => Promise): Promise; toObjectList(types: Types): Promise; private toJs; getGraph(ids?: ComponentID[]): Promise>; getGraphIds(ids?: ComponentID[]): Promise; getFlattenedEdges(id: ComponentID): Promise; private getSavedGraphOfComponentIfExist; /** * import components into the scope. */ import(ids: ComponentID[], { useCache, reFetchUnBuiltVersion, preferDependencyGraph, includeUpdateDependents, lane, reason, }?: { /** * if the component exists locally, don't go to the server to search for updates. */ useCache?: boolean; /** * if the Version objects exists locally, but its `buildStatus` is Pending or Failed, reach the remote to find * whether the version was already built there. */ reFetchUnBuiltVersion?: boolean; /** * if the component is on a lane, provide the lane object. the component will be fetched from the lane-scope and * not from the component-scope. */ lane?: Lane; /** * if an external is missing and the remote has it with the dependency graph, don't fetch all its dependencies */ preferDependencyGraph?: boolean; /** * include the updateDependents components on a lane (generally, on a workspace, it's not needed) */ includeUpdateDependents?: boolean; /** * reason why this import is needed (to show in the terminal) */ reason?: string; }): Promise; get(id: ComponentID, useCache?: boolean, importIfMissing?: boolean): Promise; getFromConsumerComponent(consumerComponent: ConsumerComponent): Promise; /** * get a component from a remote without importing it * by default, when on a lane, it loads the component from the lane. unless `fromMain` is set to true. */ getRemoteComponent(id: ComponentID, fromMain?: boolean): Promise; /** * get a component from a remote without importing it */ getManyRemoteComponents(ids: ComponentID[]): Promise; /** * list all components in the scope. */ list(filter?: { offset: number; limit: number; namespaces?: string[]; }, includeCache?: boolean, includeFromLanes?: boolean, includeDeleted?: boolean): Promise; /** * for now, list of invalid components are mostly useful for the workspace. * in the future, this can return components that failed to load in the scope due to objects file * corruption or similar issues. */ listInvalid(): Promise; /** * get ids of all scope components. * @param includeCache whether or not include components that their scope-name is different than the current scope-name */ listIds(includeCache?: boolean, includeFromLanes?: boolean, patterns?: string[]): Promise; /** * Check if a specific id exist in the scope * @param componentId */ hasId(componentId: ComponentID, includeCache?: boolean): Promise; hasIdNested(componentId: ComponentID, includeCache?: boolean): Promise; /** * determine whether a component exists in the scope. */ exists(modelComponent: ModelComponent): boolean; getMany(ids: ComponentID[], throwIfNotExist?: boolean): Promise; /** * important! you probably want to use `getMany`, which returns the components from the scope. * this method loads all aspects of the loaded components. (which hurts performance) */ loadMany(ids: ComponentID[], lane?: Lane, opts?: LoadOptions): Promise; loadManyCompsAspects(components: Component[], lane?: Lane, opts?: LoadOptions): Promise; /** * get a component and throw an exception if not found. * @param id component id */ getOrThrow(id: ComponentID): Promise; /** * returns a specific state of a component. * @param id component ID. * @param hash state hash. */ getState(id: ComponentID, hash: string): Promise; getSnap(id: ComponentID, hash: string): Promise; /** * get component log sorted by the timestamp in ascending order (from the earliest to the latest) */ getLogs(id: ComponentID, shortHash?: boolean, startsFrom?: string, throwIfMissing?: boolean): Promise; getStagedConfig(): Promise; /** * whether a component is soft-removed. * the version is required as it can be removed on a lane. in which case, the version is the head in the lane. */ isComponentRemoved(id: ComponentID): Promise; /** * whether the id with the specified version exits in the local scope. */ isComponentInScope(id: ComponentID): Promise; /** * resolve a component ID. * @param id component ID. */ resolveComponentId(id: string | BitId | ComponentID): Promise; private resolveComponentIdFromBitId; resolveMultipleComponentIds(ids: Array): Promise; /** * @deprecated use `this.idsByPattern` instead for consistency, which supports also negation and list of patterns. */ byPattern(patterns: string[], scope?: string): Promise; /** * get component-ids matching the given pattern. a pattern can have multiple patterns separated by a comma. * it uses multimatch (https://www.npmjs.com/package/multimatch) package for the matching algorithm, which supports * (among others) negate character "!" to exclude ids. See the package page for more supported characters. */ idsByPattern(pattern: string, throwForNoMatch?: boolean): Promise; filterIdsFromPoolIdsByPattern(pattern: string, ids: ComponentID[], throwForNoMatch?: boolean, filterByStateFunc?: FilterByStateFunc): Promise; getSnapDistance(id: ComponentID, throws?: boolean, workspaceId?: ComponentID): Promise; /** * get the distance for a component between two lanes. for example, lane-b forked from lane-a and lane-b added some new snaps * @param componentId * @param sourceHead head on the source lane. leave empty if the source is main * @param targetHead head on the target lane. leave empty if the target is main * @returns */ getSnapsDistanceBetweenTwoSnaps(componentId: ComponentID, sourceHead?: string, targetHead?: string, throws?: boolean): Promise; getExactVersionBySemverRange(id: ComponentID, range: string): Promise; /** * @deprecated use `this.resolveComponentId` instead. */ resolveId(id: string): Promise; /** * @deprecated use `this.getRemoteScopes()` instead. */ _legacyRemotes(): Promise; getRemoteScopes(): Promise; /** * list all component ids from a remote-scope */ listRemoteScope(scopeName: string): Promise; /** * best-effort check whether a component-id already exists on its remote scope. * intended as an early-warning helper (e.g. during "bit add"/"bit create"), not as a source of * truth. it never throws: if the workspace is offline, the scope can't be resolved, the user has * no access, or the remote lacks the component, it resolves to `false` so callers can safely skip. * * pass a pre-resolved `remotes` when checking many ids to avoid reloading the global-remotes file * from disk on every call. */ isComponentExistsOnRemote(id: ComponentID, remotes?: Remotes): Promise; getLegacyMinimal(id: ComponentID): Promise; /** * ModelComponent is of type `BitObject` which gets saved into the local scope as an object file. * It has data about the tags and the component head. It doesn't have any data about the source-files/artifacts etc. */ getBitObjectModelComponent(id: ComponentID, throwIfNotExist?: boolean): Promise; /** * Version BitObject holds the data of the source files and build artifacts of a specific snap/tag. */ getBitObjectVersion(modelComponent: ModelComponent, version: string, throwIfNotExist?: boolean): Promise; getBitObjectVersionById(id: ComponentID, throwIfNotExist?: boolean): Promise; /** * get a component and load its aspect */ load(id: ComponentID, lane?: Lane, opts?: LoadOptions): Promise; loadCompAspects(component: Component, lane?: Lane, opts?: LoadOptions): Promise; loadComponentsAspect(component: Component): Promise; createAspectListFromExtensionDataList(extensionDataList: ExtensionDataList): Promise; private extensionDataEntryToAspectEntry; getLastMergedPath(): string; getConfigStore(): Store; isModified(): Promise; write(): Promise; hasObjects(hashes: string[]): Promise; /** * declare the slots of scope extension. */ static slots: (((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry))[]; static runtime: import("@teambit/harmony").RuntimeDefinition; static dependencies: import("@teambit/harmony").Aspect[]; static defaultConfig: ScopeConfig; static provider([componentExt, ui, graphql, cli, isolator, aspectLoader, express, loggerMain, envs, depsResolver, configStore]: [ ComponentMain, UiMain, GraphqlMain, CLIMain, IsolatorMain, AspectLoaderMain, ExpressMain, LoggerMain, EnvsMain, DependencyResolverMain, ConfigStoreMain ], config: ScopeConfig, [postPutSlot, postDeleteSlot, postExportSlot, postObjectsPersistSlot, preFetchObjectsSlot, OnCompAspectReCalcSlot, preObjectPersistSlot, postObjectReadSlot,]: [ OnPostPutSlot, OnPostDeleteSlot, OnPostExportSlot, OnPostObjectsPersistSlot, OnPreFetchObjectsSlot, OnCompAspectReCalcSlot, OnPreObjectPersistSlot, OnPostObjectReadSlot ], harmony: Harmony): Promise; getDependenciesGraphByComponentIds(componentIds: ComponentID[], options?: { ignoreFeatureToggle?: boolean; }): Promise; } export {};