Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 8, 2024
1 parent 67b0b85 commit be012a4
Showing 1 changed file with 77 additions and 30 deletions.
107 changes: 77 additions & 30 deletions docs/api_refs/typedoc_plugins/hide_underscore_lc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,82 @@ const VERSION_DROPDOWN_HTML = `<div class="version-select">
</select>
</div>`;

/**
* Checks if the reflection is a property of a chat model class,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelProperties(reflection) {
if (
reflection.kind === ReflectionKind.Property &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
return true;
}
return false;
}

/**
* Checks if the reflection is a method on a chat model class,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelMethods(reflection) {
if (
reflection.kind === ReflectionKind.Method &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
if (
!WHITELISTED_CHAT_MODEL_INHERITED_METHODS.find(
(n) => n === reflection.name
)
) {
return true;
}
}
return false;
}

/**
* Checks if the reflection is an accessor and is named `callKeys`,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelAccessors(reflection) {
if (
reflection.kind === ReflectionKind.Accessor &&
reflection.name === "callKeys"
) {
return true;
}
return false;
}

/**
* Check if the reflection should be hidden. If it should, it
* returns true.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelReflection(reflection) {
return (
hideChatModelProperties(reflection) ||
hideChatModelMethods(reflection) ||
hideChatModelAccessors(reflection)
);
}

/**
* @param {string | undefined} deprecationText
* @returns {string}
Expand Down Expand Up @@ -136,36 +212,7 @@ function load(application) {
function resolveReflection(_context, reflection) {
const reflectionKind = reflection.kind;

if (
reflectionKind === ReflectionKind.Method &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
if (
!WHITELISTED_CHAT_MODEL_INHERITED_METHODS.find(
(n) => n === reflection.name
)
) {
reflectionsToHide.push(reflection);
}
}

if (
reflectionKind === ReflectionKind.Property &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
// Hide all properties of chat models
reflectionsToHide.push(reflection);
}

if (
reflectionKind === ReflectionKind.Accessor &&
reflection.name === "callKeys"
) {
// Hide all `callKeys` accessors
if (hideChatModelReflection(reflection)) {
reflectionsToHide.push(reflection);
}

Expand Down

0 comments on commit be012a4

Please sign in to comment.