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IAAI,6CAAqB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;YAChD,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE;gBACvC,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;aACtE;SACF;IACH,CAAC;IAED,sBAAsB;IACf,uBAAuB;QAC5B,OAAO,2CAAoB,CAAC,KAAK,EAAE,CAAC;IACtC,CAAC;CACF;AApJD,4BAoJC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { ApiItem, ApiItemKind } from '../items/ApiItem';\nimport { ApiItemContainerMixin } from '../mixins/ApiItemContainerMixin';\nimport { ApiPackage } from './ApiPackage';\nimport { PackageName } from '@rushstack/node-core-library';\nimport { ModelReferenceResolver, type IResolveDeclarationReferenceResult } from './ModelReferenceResolver';\nimport { DocDeclarationReference } from '@microsoft/tsdoc';\n\n/**\n * A serializable representation of a collection of API declarations.\n *\n * @remarks\n *\n * An `ApiModel` represents a collection of API declarations that can be serialized to disk. It captures all the\n * important information needed to generate documentation, without any reliance on the TypeScript compiler engine.\n *\n * An `ApiModel` acts as the root of a tree of objects that all inherit from the `ApiItem` base class.\n * The tree children are determined by the {@link (ApiItemContainerMixin:interface)} mixin base class. The model\n * contains packages. Packages have an entry point (today, only one). And the entry point can contain various types\n * of API declarations. The container relationships might look like this:\n *\n * ```\n * Things that can contain other things:\n *\n * - ApiModel\n * - ApiPackage\n * - ApiEntryPoint\n * - ApiClass\n * - ApiMethod\n * - ApiProperty\n * - ApiEnum\n * - ApiEnumMember\n * - ApiInterface\n * - ApiMethodSignature\n * - ApiPropertySignature\n * - ApiNamespace\n * - (ApiClass, ApiEnum, ApiInterace, ...)\n *\n * ```\n *\n * Normally, API Extractor writes an .api.json file to disk for each project that it builds. Then, a tool like\n * API Documenter can load the various `ApiPackage` objects into a single `ApiModel` and process them as a group.\n * This is useful because compilation generally occurs separately (e.g. because projects may reside in different\n * Git repos, or because they build with different TypeScript compiler configurations that may be incompatible),\n * whereas API Documenter cannot detect broken hyperlinks without seeing the entire documentation set.\n *\n * @public\n */\nexport class ApiModel extends ApiItemContainerMixin(ApiItem) {\n private readonly _resolver: ModelReferenceResolver;\n\n private _packagesByName: Map | undefined = undefined;\n private _apiItemsByCanonicalReference: Map | undefined = undefined;\n public constructor() {\n super({});\n\n this._resolver = new ModelReferenceResolver(this);\n }\n\n public loadPackage(apiJsonFilename: string): ApiPackage {\n const apiPackage: ApiPackage = ApiPackage.loadFromJsonFile(apiJsonFilename);\n this.addMember(apiPackage);\n return apiPackage;\n }\n\n /** @override */\n public get kind(): ApiItemKind {\n return ApiItemKind.Model;\n }\n\n /** @override */\n public get containerKey(): string {\n return '';\n }\n\n public get packages(): ReadonlyArray {\n return this.members as ReadonlyArray;\n }\n\n /** @override */\n public addMember(member: ApiPackage): void {\n if (member.kind !== ApiItemKind.Package) {\n throw new Error('Only items of type ApiPackage may be added to an ApiModel');\n }\n super.addMember(member);\n this._packagesByName = undefined; // invalidate the cache\n this._apiItemsByCanonicalReference = undefined; // invalidate the cache\n }\n\n /**\n * Efficiently finds a package by the NPM package name.\n *\n * @remarks\n *\n * If the NPM scope is omitted in the package name, it will still be found provided that it is an unambiguous match.\n * For example, it's often convenient to write `{@link node-core-library#JsonFile}` instead of\n * `{@link @rushstack/node-core-library#JsonFile}`.\n */\n public tryGetPackageByName(packageName: string): ApiPackage | undefined {\n // Build the lookup on demand\n if (this._packagesByName === undefined) {\n this._packagesByName = new Map();\n\n const unscopedMap: Map = new Map();\n\n for (const apiPackage of this.packages) {\n if (this._packagesByName.get(apiPackage.name)) {\n // This should not happen\n throw new Error(`The model contains multiple packages with the name ${apiPackage.name}`);\n }\n\n this._packagesByName.set(apiPackage.name, apiPackage);\n\n const unscopedName: string = PackageName.parse(apiPackage.name).unscopedName;\n\n if (unscopedMap.has(unscopedName)) {\n // If another package has the same unscoped name, then we won't register it\n unscopedMap.set(unscopedName, undefined);\n } else {\n unscopedMap.set(unscopedName, apiPackage);\n }\n }\n\n for (const [unscopedName, apiPackage] of unscopedMap) {\n if (apiPackage) {\n if (!this._packagesByName.has(unscopedName)) {\n // If the unscoped name is unambiguous, then we can also use it as a lookup\n this._packagesByName.set(unscopedName, apiPackage);\n }\n }\n }\n }\n\n return this._packagesByName.get(packageName);\n }\n\n public resolveDeclarationReference(\n declarationReference: DocDeclarationReference | DeclarationReference,\n contextApiItem: ApiItem | undefined\n ): IResolveDeclarationReferenceResult {\n if (declarationReference instanceof DocDeclarationReference) {\n return this._resolver.resolve(declarationReference, contextApiItem);\n } else if (declarationReference instanceof DeclarationReference) {\n // use this._apiItemsByCanonicalReference to look up ApiItem\n\n // Build the lookup on demand\n if (!this._apiItemsByCanonicalReference) {\n this._apiItemsByCanonicalReference = new Map();\n\n for (const apiPackage of this.packages) {\n this._initApiItemsRecursive(apiPackage, this._apiItemsByCanonicalReference);\n }\n }\n\n const result: IResolveDeclarationReferenceResult = {\n resolvedApiItem: undefined,\n errorMessage: undefined\n };\n\n const apiItem: ApiItem | undefined = this._apiItemsByCanonicalReference.get(\n declarationReference.toString()\n );\n\n if (!apiItem) {\n result.errorMessage = `${declarationReference.toString()} can not be located`;\n } else {\n result.resolvedApiItem = apiItem;\n }\n\n return result;\n } else {\n // NOTE: The \"instanceof DeclarationReference\" test assumes a specific version of the @microsoft/tsdoc package.\n throw new Error(\n 'The \"declarationReference\" parameter must be an instance of' +\n ' DocDeclarationReference or DeclarationReference'\n );\n }\n }\n\n private _initApiItemsRecursive(apiItem: ApiItem, apiItemsByCanonicalReference: Map): void {\n if (apiItem.canonicalReference && !apiItem.canonicalReference.isEmpty) {\n apiItemsByCanonicalReference.set(apiItem.canonicalReference.toString(), apiItem);\n }\n\n // Recurse container members\n if (ApiItemContainerMixin.isBaseClassOf(apiItem)) {\n for (const apiMember of apiItem.members) {\n this._initApiItemsRecursive(apiMember, apiItemsByCanonicalReference);\n }\n }\n }\n\n /** @beta @override */\n public buildCanonicalReference(): DeclarationReference {\n return DeclarationReference.empty();\n }\n}\n"]}