import type { Hash, Integrity } from './recipe/integrity.js'; import type { ResolutionCanonical } from './recipe/resolution.js'; import type { WorkspaceRange } from './recipe/workspace.js'; export type { HashOrigin, Integrity, } from './recipe/integrity.js'; export type { HostingProvider } from './recipe/resolution.js'; export type { WorkspaceRange } from './recipe/workspace.js'; export type IntegrityHash = Hash; export type NodeId = string; export type TarballKey = string; export type Patch = string; export type SourceDiscriminator = string; export interface TarballKeyInput { name: string; version: string; patch?: Patch; source?: SourceDiscriminator; } export type EdgeKind = 'dep' | 'dev' | 'optional' | 'peer' | 'bundled'; export interface Node { id: NodeId; name: string; version: string; peerContext: NodeId[]; patch?: Patch; source?: SourceDiscriminator; workspacePath?: string; } export interface TarballPayload { integrity?: Integrity; berryChecksumCacheKey?: string; engines?: Record; funding?: unknown; license?: string; bin?: string | Record; deprecated?: string; cpu?: string[]; os?: string[]; libc?: string[]; hasInstallScript?: boolean; bundledDependencies?: string[]; peerDependencies?: Record; peerDependenciesMeta?: Record; resolution?: ResolutionCanonical; nativeResolution?: string; } export type PackageMetadataField = 'engines' | 'funding' | 'license' | 'bin' | 'deprecated' | 'cpu' | 'os' | 'libc' | 'hasInstallScript' | 'bundledDependencies' | 'peerDependencies' | 'peerDependenciesMeta'; export interface EdgeAttributes { range?: string; overrideRange?: string; optional?: boolean; workspace?: boolean; alias?: string; workspaceRange?: WorkspaceRange; } export interface Edge { src: NodeId; dst: NodeId; kind: EdgeKind; attrs?: EdgeAttributes; } export type EdgeTriple = { src: NodeId; dst: NodeId; kind: EdgeKind; }; export interface Diagnostic { code: string; subject?: NodeId | EdgeTriple; severity: 'info' | 'warning' | 'error'; message: string; data?: Record; } export interface LayoutHints { strategy?: 'isolated' | 'hoisted' | 'pnp' | 'nm-linked'; } export interface OverrideConstraint { package: string; parentPath?: string[]; versionCondition?: string; to: string; selfRef?: boolean; origin?: OverrideManager; captureIndex?: number; } export type OverrideManager = 'npm' | 'yarn' | 'pnpm'; export interface Manifest { name?: string; version?: string; dependencies?: Record; devDependencies?: Record; optionalDependencies?: Record; peerDependencies?: Record; workspaces?: string[]; overrides?: OverrideConstraint[]; native?: { npmOverrides?: unknown; yarnResolutions?: Record; pnpmOverrides?: Record; }; } export interface GraphWalkOptions { direction?: 'out' | 'in'; kinds?: readonly EdgeKind[]; maxDepth?: number; } export type GraphChange = { kind: 'node-added'; subject: NodeId; } | { kind: 'node-removed'; subject: NodeId; } | { kind: 'node-replaced'; subject: NodeId; previous?: NodeId; } | { kind: 'edge-added'; subject: EdgeTriple; } | { kind: 'edge-removed'; subject: EdgeTriple; } | { kind: 'peer-context-replaced'; subject: NodeId; previous?: NodeId; } | { kind: 'tarball-set'; subject: TarballKey; } | { kind: 'tarball-removed'; subject: TarballKey; }; export interface GraphDiff { addedNodes: NodeId[]; removedNodes: NodeId[]; changedNodes: NodeId[]; addedEdges: EdgeTriple[]; removedEdges: EdgeTriple[]; } export interface GraphMutationResult extends GraphResult { readonly applied: readonly GraphChange[]; } export interface GraphResult { readonly graph: Graph; readonly diagnostics: readonly Diagnostic[]; } export type DependencyManifest = Pick; export interface GraphMutation { replaceNode(id: NodeId, newNode: Node): void; addNode(node: Node): void; removeNode(id: NodeId): void; addEdge(src: NodeId, dst: NodeId, kind: EdgeKind, attrs?: EdgeAttributes): void; removeEdge(src: NodeId, dst: NodeId, kind: EdgeKind): void; replacePeerContext(id: NodeId, peers: NodeId[]): void; setTarball(inputs: TarballKeyInput, payload: TarballPayload): void; removeTarball(inputs: TarballKeyInput): void; addDiagnostic(diagnostic: Diagnostic): void; } export interface Graph { getNode(id: NodeId): Node | undefined; nodes(): IterableIterator; byName(name: string): readonly NodeId[]; roots(): ReadonlySet; out(id: NodeId, kind?: EdgeKind): readonly Edge[]; in(id: NodeId, kind?: EdgeKind): readonly Edge[]; walk(seeds: NodeId | readonly NodeId[], opts?: GraphWalkOptions): IterableIterator; topoSort(): readonly (readonly NodeId[])[]; subgraph(seeds: NodeId | readonly NodeId[], opts?: GraphWalkOptions): Graph; diff(other: Graph): GraphDiff; tarball(inputs: TarballKeyInput): TarballPayload | undefined; tarballOf(nodeId: NodeId): TarballPayload | undefined; tarballs(): IterableIterator<[TarballKey, TarballPayload]>; overrides(): readonly OverrideConstraint[]; governingOverride(name: string, consumerPath: readonly string[], declaredRange?: string): OverrideConstraint | undefined; registryPackages(): Readonly>; diagnostics(): readonly Diagnostic[]; layoutHints(): LayoutHints | undefined; mutate(transaction: (mutation: GraphMutation) => void): GraphMutationResult; } export interface Builder { addNode(node: Node): void; addEdge(src: NodeId, dst: NodeId, kind: EdgeKind, attrs?: EdgeAttributes): void; setTarball(inputs: TarballKeyInput, payload: TarballPayload): void; diagnostic(d: Diagnostic): void; layoutHints(h: LayoutHints): void; seal(): Graph; } export declare class GraphError extends Error { readonly code: 'INVARIANT_VIOLATION' | 'PATCH_REJECTED'; constructor(code: 'INVARIANT_VIOLATION' | 'PATCH_REJECTED', message: string); } export declare function newBuilder(): Builder; export declare function nameOf(id: NodeId): string; export declare function serializeNodeId(name: string, version: string, peerContext: readonly NodeId[], patch?: Patch, source?: SourceDiscriminator): NodeId; export declare function stripPeerContextFromNodeId(id: NodeId): TarballKey; export declare function validatePatchToken(patch: string): void; export declare function validateSourceToken(source: string): void; export declare function toTarballKey(inputs: TarballKeyInput): TarballKey;