import { type PathBuilderLike } from "path-ts"; import { type CorpusSourceInput, type CorpusSourceInputs } from "#source-register/corpus-inputs"; /** * The suffix of a parquet file's record path: `data.parquet` is described by `data.RECORD.json`. */ export declare const RECORD_FILE_SUFFIX = ".RECORD.json"; /** * The four inputs a file's derivation hash is computed over. */ export interface DerivationInputs { /** * A digest of the data the rows were read from. */ extractHash: string; /** * A digest of the modules the file's producer reaches, from `moduleGraphHash` in `#build/code-hash`. */ codeHash: string; /** * Every option that changes the file's bytes, including its source, split and part. * * It is serialized by {@linkcode canonicalJSON}, so key order doesn't change the hash. */ config: unknown; /** * The `@mailwoman/corpus` version that wrote the file. */ builderVersion: string; /** * The HEAD commit of each git checkout the input directory holds, keyed by its path relative to the input. * * `extractHash` already changes with any input file, so the derivation hash leaves these out. * They tell a reader which commits the rows were built from. */ inputRevisions?: Record; /** * The `git status --porcelain` line count of each checkout in {@linkcode inputRevisions}: * the files whose state at build time no commit records. */ inputUncommittedFiles?: Record; } /** * The inputs a caller supplies. * The writer adds the builder version. */ export interface FileDerivation { extractHash: string; /** * The digest of the modules the file's producer reaches, from `moduleGraphHash` in `#build/code-hash`. */ codeHash: string; config: Record; /** * See {@linkcode DerivationInputs.inputRevisions}. */ inputRevisions?: Record; /** * See {@linkcode DerivationInputs.inputUncommittedFiles}. */ inputUncommittedFiles?: Record; } /** * Rows per license label, within one source. */ export type LicenseTally = Record; /** * This record is written beside one parquet file. */ export interface ParquetFileRecord { source: string; derivationHash: string; /** * The inputs {@linkcode derivationHash} was computed over, so a reader can recompute it. */ derivation: DerivationInputs; sha256: string; rows: number; /** * Each license label assigned to rows in the file, with a row count for each label. * * A file written since #2741 records one label, the SPDX or `LicenseRef-*` * id of its source's register inputs. */ licenseValues: LicenseTally; /** * The producers' own statements of the rows' terms, with a row count for each statement. * The `license` column doesn't retain these statements. * * Absent from a record written before #2741. */ licenseStatements?: LicenseTally; /** * The register sources `corpus-source-inputs.json` maps {@linkcode source} to when the file was written. */ registerInputs: readonly CorpusSourceInput[]; builtAt: string; } /** * The sha256 of the canonical JSON of a file's four derivation inputs. */ export declare function derivationHash(inputs: DerivationInputs): string; /** * This package's `version`. */ export declare function corpusBuilderVersion(): Promise; /** * Complete a caller's derivation with the builder version. */ export declare function resolveDerivation(derivation: FileDerivation): Promise; /** * A digest of an extract on disk. * * A file is hashed whole. * A git checkout in the directory is described by its relative path, its HEAD commit * and its `git status --porcelain` lines. * * Those lines change when a commit, edit, new file or deletion changes the checkout. * * Every other file is described by a `relative path, size, mtime` line. * That line changes when the file is added, removed, resized or rewritten. * * The reader skips content hashing because it would add hours to a build: * Who's On First's 273 checkouts hold over 100 GB, and listing and stat'ing their * files took over 28 minutes before running out of a 4 GB heap. * A directory with no checkout gives the same digest as a listing read file by file. * * A process computes each path's digest once: the WOF record cache * and the build's extract hash both read it. */ export declare function extractFingerprint(path: PathBuilderLike): Promise; /** * One git checkout's state: its path relative to the input, its HEAD commit * and its `git status --porcelain` lines. */ export interface CheckoutState { checkout: string; head: string; status: string[]; } /** * The state of each git checkout in `path` and its immediate subdirectories, sorted by relative path. * * A process reads each path once, so the fingerprint and the record's {@linkcode inputCheckouts} agree. */ export declare function inputCheckoutStates(path: PathBuilderLike): Promise; /** * The derivation fields that record the git checkouts an input directory holds. */ export type InputCheckouts = Required>; /** * The HEAD commit and uncommitted-file count of each git checkout in `path` * and its immediate subdirectories, keyed by the checkout's path relative to `path`, * or `undefined` for a file or a directory holding no checkout. */ export declare function inputCheckouts(path: PathBuilderLike): Promise; /** * The checkout fields shared by every input record, so a file merged from them * records the commits its rows came from. * * @returns `undefined` when any input record lacks the commits, since the merged * file's rows would then come partly from unrecorded commits. * @throws When two inputs record different commits or uncommitted counts for one checkout. */ export declare function mergeInputCheckouts(records: ReadonlyArray | null>): InputCheckouts | undefined; /** * The record path for a parquet file: `/.RECORD.json`. */ export declare function recordPathFor(parquetPath: PathBuilderLike): string; /** * The label a row's license is recorded under. */ export declare function licenseLabel(license: string | null | undefined): string; /** * Rows per license label, per source. */ export type SourceLicenseTally = Map>; /** * Add one count to a tally. */ export declare function addToTally(tally: SourceLicenseTally, source: string, label: string, rows: number): void; /** * The committed `corpus-source-inputs.json`, indexed by id and alias. * * The register audit runs where a build admits its sources. * A record copies the mapping the build admitted. */ export declare function committedCorpusSourceInputs(): Promise; export interface WriteParquetRecordOptions { /** * The parquet file the record describes. * It must already be written. */ path: PathBuilderLike; /** * Rows per license label, per source, counted while the file was written. * * A record identifies one source, so a tally with more than one is refused. */ tally: SourceLicenseTally; derivation: DerivationInputs; builtAt: string; /** * The producers' statements the writer replaced with the license id, with the rows under each. */ statements?: ReadonlyMap; /** * @defaultValue {@linkcode committedCorpusSourceInputs} */ sourceInputs?: CorpusSourceInputs; } /** * Write the record beside one parquet file and return it. * * @throws When the tally holds no source or more than one, or when * `corpus-source-inputs.json` maps no entry to the source, since a record without * register inputs would hide the gap the table exists to show. */ export declare function writeParquetRecord(options: WriteParquetRecordOptions): Promise; /** * The record beside a parquet file, or `null` when none was written. */ export declare function readParquetRecord(parquetPath: PathBuilderLike): Promise; /** * Count rows per `(source, license)` by reading the files' rows. * * @throws When a row has no source, because no record could attribute it. */ export declare function readSourceLicenseTally(paths: readonly string[]): Promise; /** * One file a corpus manifest lists. */ export interface ListedParquetFile { path: string; rows: number; sha256?: string; } export interface FoldedSourceLicenses { tally: SourceLicenseTally; /** * Files whose counts came from their record. */ folded: number; /** * Files whose rows were read because they have no record. */ reread: number; } /** * Tally rows per `(source, license)` over a manifest's files, from each file's record * where one exists and by reading rows for the files that have none. * * @throws When a record disagrees with the manifest on the file's rows or sha256, * or the re-read files hold a different number of rows than the manifest lists for them. */ export declare function foldSourceLicenses(files: readonly ListedParquetFile[]): Promise; /** * Shape a tally into the per-source entries a frozen training manifest records. * * A source with several row labels records the majority label as its license * and keeps the count for each label. * The record therefore preserves the full label distribution. */ export declare function rowsBySourceFromTally(tally: SourceLicenseTally): Map; }>; //# sourceMappingURL=record.d.ts.map