import type { CLIMain } from '@teambit/cli'; import type { Component, ComponentMain } from '@teambit/component'; import type { SlotRegistry } from '@teambit/harmony'; import type { GraphqlMain } from '@teambit/graphql'; import type { EnvsMain } from '@teambit/envs'; import type { Logger, LoggerMain } from '@teambit/logger'; import type { Export, SchemaNodeConstructor } from '@teambit/semantics.entities.semantic-schema'; import { APISchema } from '@teambit/semantics.entities.semantic-schema'; import type { BuilderMain } from '@teambit/builder'; import type { Workspace } from '@teambit/workspace'; import type { ScopeMain } from '@teambit/scope'; import type { ImpactRule, APIDiffResult, SchemaAvailability } from '@teambit/semantics.entities.semantic-schema-diff'; import { ImpactAssessor } from '@teambit/semantics.entities.semantic-schema-diff'; import type { Parser } from './parser'; import type { SchemaExtractor } from './schema-extractor'; export type ParserSlot = SlotRegistry; export type ImpactRuleSlot = SlotRegistry; export type SchemaConfig = { /** * default parser */ defaultParser: string; /** * disable extracting schema */ disabled?: boolean; }; /** * extension for extracting component schemas. */ export declare class SchemaMain { /** * parsers slot. */ private parserSlot; /** * impact rules slot — other aspects register custom rules via registerImpactRules(). */ private impactRuleSlot; private envs; private config; private builder; private workspace; private logger; private impactAssessor; constructor( /** * parsers slot. */ parserSlot: ParserSlot, /** * impact rules slot — other aspects register custom rules via registerImpactRules(). */ impactRuleSlot: ImpactRuleSlot, envs: EnvsMain, config: SchemaConfig, builder: BuilderMain, workspace: Workspace, logger: Logger, impactAssessor: ImpactAssessor); /** * get the default parser. */ getDefaultParser(): Parser; /** * @deprecated use registerSchemaClasses instead * registerSchemaClasses is better for performance as it lazy-loads the schemas. */ registerSchemaClass(schema: SchemaNodeConstructor): void; registerSchemaClasses(getSchemas: () => SchemaNodeConstructor[]): void; /** * parse a module into a component schema. */ parseModule(path: string, content?: string): Export[]; getSchemaExtractor(component: Component, tsserverPath?: string, contextPath?: string): SchemaExtractor; /** * get a schema of a component. * @param component target component. * @param shouldDisposeResourcesOnceDone for long-running processes, such as bit-start/bit-watch, this is not * relevant. for calling the API only to get a schema for one component, this is needed to ensure the ts-server is * not kept alive. otherwise, the process will never end. * */ getSchema(component: Component, shouldDisposeResourcesOnceDone?: boolean, alwaysRunExtractor?: boolean, tsserverPath?: string, contextPath?: string, skipInternals?: boolean, /** @deprecated not used by the core envs. forwarded as is to the env's legacy `getSchemaExtractor()`. */ schemaTransformers?: unknown[], /** @deprecated not used by the core envs. forwarded as is to the env's legacy `getSchemaExtractor()`. */ apiTransformers?: unknown[], includeFiles?: string[]): Promise; /** * like getSchema, but reports whether a real schema was obtained. an empty schema * with `available: false` means "no schema data exists for this version" — callers * (e.g. API diff) must not treat it as an empty API surface. */ getSchemaWithAvailability(component: Component, shouldDisposeResourcesOnceDone?: boolean, alwaysRunExtractor?: boolean, tsserverPath?: string, contextPath?: string, skipInternals?: boolean, /** @deprecated not used by the core envs. forwarded as is to the env's legacy `getSchemaExtractor()`. */ schemaTransformers?: unknown[], /** @deprecated not used by the core envs. forwarded as is to the env's legacy `getSchemaExtractor()`. */ apiTransformers?: unknown[], includeFiles?: string[]): Promise<{ schema: APISchema; availability: SchemaAvailability; }>; /** * read the schema.json artifact the schema build task produced for this exact version. * returns null when the version has no such artifact (never built, or built before API * extraction existed). throws on a corrupt artifact. */ private readSchemaFromArtifact; getSchemaFromObject(obj: Record): APISchema; getSchemaFromRemote(id: string): Promise; /** * register a new parser. */ registerParser(parser: Parser): SchemaMain; calcSchemaData(): Promise<{ disabled?: boolean; }>; getSchemaData(component: Component): { [key: string]: any; } | undefined; /** * Register custom impact rules for API diff assessment. * Custom rules take priority over default rules. * This allows environments to customize what constitutes a breaking change. */ registerImpactRules(rules: ImpactRule[]): void; /** * Get the ImpactAssessor with default + all registered custom rules from the slot. */ getImpactAssessor(): ImpactAssessor; /** * Compute the semantic API diff between two component versions. */ /** * in-memory memo + single-flight for computed diffs. several consumers hit this for the * same immutable version pair (lane-diff status via component-compare, the compare UI's * apiDiff GraphQL field) — without this, a cold page load runs schema extraction twice * per pair. transient failures (FAILED availability / null) are never memoized. */ private apiDiffMemo; private apiDiffInflight; private static API_DIFF_MEMO_MAX; computeAPIDiff(baseComp: Component, compareComp: Component): Promise; /** * is this component the version currently checked out in the workspace, with local modifications * on top? that's the one case where the live source — not the version's built artifact — is the * authoritative API surface for a diff side. errs toward true when modification state can't be * determined, so local changes are never masked by a stale artifact. */ private isModifiedCheckoutOf; private doComputeAPIDiff; isSchemaTaskDisabled(component: Component): any; static runtime: import("@teambit/harmony").RuntimeDefinition; static dependencies: import("@teambit/harmony").Aspect[]; static slots: (((registerFn: () => string) => SlotRegistry) | ((registerFn: () => string) => SlotRegistry))[]; static defaultConfig: { defaultParser: string; disabled: boolean; }; static provider([envs, cli, component, graphql, loggerMain, builder, workspace, scope]: [ EnvsMain, CLIMain, ComponentMain, GraphqlMain, LoggerMain, BuilderMain, Workspace, ScopeMain ], config: SchemaConfig, [parserSlot, impactRuleSlot]: [ParserSlot, ImpactRuleSlot]): Promise; } export default SchemaMain;