Files
reverse-engineering-anything/src/artifacts/createArtifactReader.ts
T
morlutoandCursor Agent 5f9187cd27 refactor(artifacts): describe formats in one registry (#8054)
* refactor(artifacts): describe formats in one registry

Reader construction, classification retention, container role, and
extraction now read one descriptor per domain format id. unknown has
no reader, and zip package families share one capability row.

* fix(artifacts): keep reader presence in format descriptor types

Descriptor helpers no longer widen every format to an optional reader,
so ArtifactReaderFormat stays the union of formats that construct one.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-10-30 04:27:17 +08:00

43 lines
1.4 KiB
TypeScript

import type { ArtifactOccurrence } from "../domain/artifactGraph.js";
import type { ArtifactReader } from "./ArtifactReader.js";
import {
ARTIFACT_FORMATS,
type ArtifactReaderConstruction,
} from "./artifactFormats.js";
export type { ArtifactReaderConstruction } from "./artifactFormats.js";
/** Formats with an artifact entry reader; availability policy belongs to the caller. */
export type ArtifactReaderFormat = {
[Id in keyof typeof ARTIFACT_FORMATS]: (typeof ARTIFACT_FORMATS)[Id] extends {
readonly createReader: (
path: string,
options: ArtifactReaderConstruction,
) => ArtifactReader;
}
? Id
: never;
}[keyof typeof ARTIFACT_FORMATS];
export function createArtifactReader(
path: string,
format: ArtifactReaderFormat,
options: ArtifactReaderConstruction,
): ArtifactReader;
export function createArtifactReader(
path: string,
format: ArtifactOccurrence["artifact_format"],
options: ArtifactReaderConstruction,
): ArtifactReader | undefined;
/** Construct a reader without acquiring or transferring its source ownership. */
export function createArtifactReader(
path: string,
format: ArtifactOccurrence["artifact_format"],
options: ArtifactReaderConstruction,
): ArtifactReader | undefined {
const descriptor = ARTIFACT_FORMATS[format];
return "createReader" in descriptor
? descriptor.createReader(path, options)
: undefined;
}