UNPKG

3.44 kBTypeScriptView Raw
1import type { Application } from "../application.js";
2import { ProjectReflection, type ReflectionVariant, type TypeKindMap } from "../models/index.js";
3import type { Logger } from "../utils/loggers.js";
4import type { JSONOutput } from "./index.js";
5import type { FileRegistry } from "../models/FileRegistry.js";
6export interface DeserializerComponent {
7 priority: number;
8 supports(model: unknown, obj: unknown): boolean;
9 fromObject(model: unknown, obj: unknown): void;
10}
11export interface Deserializable<T> {
12 fromObject(d: Deserializer, o: T): void;
13}
14/**
15 * Deserializes TypeDoc's JSON output back to {@link Reflection} instances.
16 *
17 * @group Common
18 * @summary Deserializes TypeDoc's JSON output
19 */
20export declare class Deserializer {
21 readonly application: Application;
22 private deferred;
23 private deserializers;
24 private activeReflection;
25 constructor(application: Application);
26 get logger(): Logger;
27 reflectionBuilders: {
28 [K in keyof ReflectionVariant]: (parent: NonNullable<ReflectionVariant[K]["parent"]>, obj: JSONOutput.ModelToObject<ReflectionVariant[K]>) => ReflectionVariant[K];
29 };
30 typeBuilders: {
31 [K in keyof TypeKindMap]: (obj: JSONOutput.ModelToObject<TypeKindMap[K]>, de: Deserializer) => TypeKindMap[K];
32 };
33 /**
34 * Only set when deserializing.
35 */
36 projectRoot: string;
37 oldIdToNewId: Record<number, number | undefined>;
38 oldFileIdToNewFileId: Record<number, number | undefined>;
39 project: ProjectReflection | undefined;
40 addDeserializer(de: DeserializerComponent): void;
41 /**
42 * Revive a single project into the structure it was originally created with.
43 * This is generally not appropriate for merging multiple projects since projects may
44 * contain reflections in their root, not inside a module.
45 */
46 reviveProject(name: string, projectObj: JSONOutput.ProjectReflection, options: {
47 projectRoot: string;
48 registry: FileRegistry;
49 addProjectDocuments?: boolean;
50 }): ProjectReflection;
51 reviveProjects(name: string, projects: readonly JSONOutput.ProjectReflection[], options: {
52 projectRoot: string;
53 registry: FileRegistry;
54 addProjectDocuments?: boolean;
55 }): ProjectReflection;
56 revive<T, U extends Deserializable<T>>(source: NonNullable<T>, creator: (obj: T) => U): U;
57 revive<T, U extends Deserializable<T>>(source: T | undefined, creator: (obj: T) => U): U | undefined;
58 reviveMany<T, U extends Deserializable<T>>(sourceArray: T[], creator: (obj: T) => U): U[];
59 reviveMany<T, U extends Deserializable<T>>(sourceArray: T[] | undefined, creator: (obj: T) => U): U[] | undefined;
60 reviveType<T extends JSONOutput.SomeType>(obj: T): TypeKindMap[T["type"]];
61 reviveType<T extends JSONOutput.SomeType>(obj: T | undefined): TypeKindMap[T["type"]] | undefined;
62 constructReflection<T extends JSONOutput.SomeReflection>(obj: T): ReflectionVariant[T["variant"]];
63 constructType<T extends JSONOutput.SomeType>(obj: T): TypeKindMap[T["type"]];
64 fromObject<T>(receiver: {
65 fromObject(d: Deserializer, o: T): void;
66 }, obj: T): void;
67 /**
68 * Defers work until the initial pass of serialization has been completed.
69 * This can be used to set up references which cannot be immediately restored.
70 *
71 * May only be called when deserializing.
72 */
73 defer(cb: (project: ProjectReflection) => void): void;
74}
75
\No newline at end of file