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Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport type { Constructor, PropertiesOf } from '../mixins/Mixin';\nimport type { ApiPackage } from '../model/ApiPackage';\nimport { ApiParameterListMixin } from '../mixins/ApiParameterListMixin';\nimport type { DeserializerContext } from '../model/DeserializerContext';\nimport { InternalError } from '@rushstack/node-core-library';\nimport { ApiItemContainerMixin } from '../mixins/ApiItemContainerMixin';\nimport type { ApiModel } from '../model/ApiModel';\n\n/**\n * The type returned by the {@link ApiItem.kind} property, which can be used to easily distinguish subclasses of\n * {@link ApiItem}.\n *\n * @public\n */\nexport enum ApiItemKind {\n CallSignature = 'CallSignature',\n Class = 'Class',\n Constructor = 'Constructor',\n ConstructSignature = 'ConstructSignature',\n EntryPoint = 'EntryPoint',\n Enum = 'Enum',\n EnumMember = 'EnumMember',\n Function = 'Function',\n IndexSignature = 'IndexSignature',\n Interface = 'Interface',\n Method = 'Method',\n MethodSignature = 'MethodSignature',\n Model = 'Model',\n Namespace = 'Namespace',\n Package = 'Package',\n Property = 'Property',\n PropertySignature = 'PropertySignature',\n TypeAlias = 'TypeAlias',\n Variable = 'Variable',\n None = 'None'\n}\n\n/**\n * Constructor options for {@link ApiItem}.\n * @public\n */\nexport interface IApiItemOptions {}\n\nexport interface IApiItemJson {\n kind: ApiItemKind;\n canonicalReference: string;\n}\n\n// PRIVATE - Allows ApiItemContainerMixin to assign the parent.\n//\nexport const apiItem_onParentChanged: unique symbol = Symbol('ApiItem._onAddToContainer');\n\n/**\n * The abstract base class for all members of an `ApiModel` object.\n *\n * @remarks\n * This is part of the {@link ApiModel} hierarchy of classes, which are serializable representations of\n * API declarations.\n * @public\n */\nexport class ApiItem {\n private _canonicalReference: DeclarationReference | undefined;\n private _parent: ApiItem | undefined;\n\n public constructor(options: IApiItemOptions) {\n // (\"options\" is not used here, but part of the inheritance pattern)\n }\n\n public static deserialize(jsonObject: IApiItemJson, context: DeserializerContext): ApiItem {\n // The Deserializer class is coupled with a ton of other classes, so we delay loading it\n // to avoid ES5 circular imports.\n const deserializerModule: typeof import('../model/Deserializer') = require('../model/Deserializer');\n return deserializerModule.Deserializer.deserialize(context, jsonObject);\n }\n\n /** @virtual */\n public static onDeserializeInto(\n options: Partial,\n context: DeserializerContext,\n jsonObject: IApiItemJson\n ): void {\n // (implemented by subclasses)\n }\n\n /** @virtual */\n public serializeInto(jsonObject: Partial): void {\n jsonObject.kind = this.kind;\n jsonObject.canonicalReference = this.canonicalReference.toString();\n }\n\n /**\n * Identifies the subclass of the `ApiItem` base class.\n * @virtual\n */\n public get kind(): ApiItemKind {\n throw new Error('ApiItem.kind was not implemented by the child class');\n }\n\n /**\n * Warning: This API is used internally by API extractor but is not yet ready for general usage.\n *\n * @remarks\n *\n * Returns a `DeclarationReference` object using the experimental new declaration reference notation.\n *\n * @beta\n */\n public get canonicalReference(): DeclarationReference {\n if (!this._canonicalReference) {\n try {\n this._canonicalReference = this.buildCanonicalReference();\n } catch (e) {\n const name: string = this.getScopedNameWithinPackage() || this.displayName;\n throw new InternalError(`Error building canonical reference for ${name}:\\n` + (e as Error).message);\n }\n }\n return this._canonicalReference;\n }\n\n /**\n * Returns a string key that can be used to efficiently retrieve an `ApiItem` from an `ApiItemContainerMixin`.\n * The key is unique within the container. Its format is undocumented and may change at any time.\n *\n * @remarks\n * Use the `getContainerKey()` static member to construct the key. Each subclass has a different implementation\n * of this function, according to the aspects that are important for identifying it.\n *\n * @virtual\n */\n public get containerKey(): string {\n throw new InternalError('ApiItem.containerKey was not implemented by the child class');\n }\n\n /**\n * Returns a name for this object that can be used in diagnostic messages, for example.\n *\n * @remarks\n * For an object that inherits ApiNameMixin, this will return the declared name (e.g. the name of a TypeScript\n * function). Otherwise, it will return a string such as \"(call signature)\" or \"(model)\".\n *\n * @virtual\n */\n public get displayName(): string {\n switch (this.kind) {\n case ApiItemKind.CallSignature:\n return '(call)';\n case ApiItemKind.Constructor:\n return '(constructor)';\n case ApiItemKind.ConstructSignature:\n return '(new)';\n case ApiItemKind.IndexSignature:\n return '(indexer)';\n case ApiItemKind.Model:\n return '(model)';\n }\n return '(???)'; // All other types should inherit ApiNameMixin which will override this property\n }\n\n /**\n * If this item was added to a ApiItemContainerMixin item, then this returns the container item.\n * If this is an Parameter that was added to a method or function, then this returns the function item.\n * Otherwise, it returns undefined.\n * @virtual\n */\n public get parent(): ApiItem | undefined {\n return this._parent;\n }\n\n /**\n * This property supports a visitor pattern for walking the tree.\n * For items with ApiItemContainerMixin, it returns the contained items, sorted alphabetically.\n * Otherwise it returns an empty array.\n * @virtual\n */\n public get members(): ReadonlyArray {\n return [];\n }\n\n /**\n * If this item has a name (i.e. extends `ApiNameMixin`), then return all items that have the same parent\n * and the same name. Otherwise, return all items that have the same parent and the same `ApiItemKind`.\n *\n * @remarks\n * Examples: For a function, this would return all overloads for the function. For a constructor, this would\n * return all overloads for the constructor. For a merged declaration (e.g. a `namespace` and `enum` with the\n * same name), this would return both declarations. If this item does not have a parent, or if it is the only\n * item of its name/kind, then the result is an array containing only this item.\n */\n public getMergedSiblings(): ReadonlyArray {\n const parent: ApiItem | undefined = this._parent;\n if (parent && ApiItemContainerMixin.isBaseClassOf(parent)) {\n return parent._getMergedSiblingsForMember(this);\n }\n return [];\n }\n\n /**\n * Returns the chain of ancestors, starting from the root of the tree, and ending with the this item.\n */\n public getHierarchy(): ReadonlyArray {\n const hierarchy: ApiItem[] = [];\n for (let current: ApiItem | undefined = this; current !== undefined; current = current.parent) {\n hierarchy.push(current);\n }\n hierarchy.reverse();\n return hierarchy;\n }\n\n /**\n * This returns a scoped name such as `\"Namespace1.Namespace2.MyClass.myMember()\"`. It does not include the\n * package name or entry point.\n *\n * @remarks\n * If called on an ApiEntrypoint, ApiPackage, or ApiModel item, the result is an empty string.\n */\n public getScopedNameWithinPackage(): string {\n const reversedParts: string[] = [];\n\n for (let current: ApiItem | undefined = this; current !== undefined; current = current.parent) {\n if (\n current.kind === ApiItemKind.Model ||\n current.kind === ApiItemKind.Package ||\n current.kind === ApiItemKind.EntryPoint\n ) {\n break;\n }\n if (reversedParts.length !== 0) {\n reversedParts.push('.');\n } else {\n switch (current.kind) {\n case ApiItemKind.CallSignature:\n case ApiItemKind.ConstructSignature:\n case ApiItemKind.Constructor:\n case ApiItemKind.IndexSignature:\n // These functional forms don't have a proper name, so we don't append the \"()\" suffix\n break;\n default:\n if (ApiParameterListMixin.isBaseClassOf(current)) {\n reversedParts.push('()');\n }\n }\n }\n reversedParts.push(current.displayName);\n }\n\n return reversedParts.reverse().join('');\n }\n\n /**\n * If this item is an ApiPackage or has an ApiPackage as one of its parents, then that object is returned.\n * Otherwise undefined is returned.\n */\n public getAssociatedPackage(): ApiPackage | undefined {\n for (let current: ApiItem | undefined = this; current !== undefined; current = current.parent) {\n if (current.kind === ApiItemKind.Package) {\n return current as ApiPackage;\n }\n }\n return undefined;\n }\n\n /**\n * If this item is an ApiModel or has an ApiModel as one of its parents, then that object is returned.\n * Otherwise undefined is returned.\n */\n public getAssociatedModel(): ApiModel | undefined {\n for (let current: ApiItem | undefined = this; current !== undefined; current = current.parent) {\n if (current.kind === ApiItemKind.Model) {\n return current as ApiModel;\n }\n }\n return undefined;\n }\n\n /**\n * A text string whose value determines the sort order that is automatically applied by the\n * {@link (ApiItemContainerMixin:interface)} class.\n *\n * @remarks\n * The value of this string is undocumented and may change at any time.\n * If {@link (ApiItemContainerMixin:interface).preserveMemberOrder} is enabled for the `ApiItem`'s parent,\n * then no sorting is performed, and this key is not used.\n *\n * @virtual\n */\n public getSortKey(): string {\n return this.containerKey;\n }\n\n /**\n * PRIVATE\n *\n * @privateRemarks\n * Allows ApiItemContainerMixin to assign the parent when the item is added to a container.\n *\n * @internal\n */\n public [apiItem_onParentChanged](parent: ApiItem | undefined): void {\n this._parent = parent;\n this._canonicalReference = undefined;\n }\n\n /**\n * Builds the cached object used by the `canonicalReference` property.\n * @virtual\n */\n protected buildCanonicalReference(): DeclarationReference {\n throw new InternalError('ApiItem.canonicalReference was not implemented by the child class');\n }\n}\n\n/**\n * This abstraction is used by the mixin pattern.\n * It describes a class type that inherits from {@link ApiItem}.\n *\n * @public\n */\nexport interface IApiItemConstructor extends Constructor, PropertiesOf {}\n"]}