@cisstech/nestjs-expand
Version:
A NestJS module to build Dynamic Resource Expansion for APIs
50 lines (49 loc) • 2.19 kB
TypeScript
import { DiscoveryService } from '@golevelup/nestjs-discovery';
import { OnModuleInit } from '@nestjs/common';
import 'reflect-metadata';
import { ExpandConfig, ExpandableParams, SelectableParams } from './expand';
export declare class ExpandService implements OnModuleInit {
private readonly discovery;
private readonly conf;
private readonly logger;
private readonly standardExpanders;
private readonly expanderMethodsInstances;
private readonly expansionMethodLinks;
/**
* The configuration for the module.
*/
get config(): Readonly<ExpandConfig>;
constructor(discovery: DiscoveryService, conf: ExpandConfig);
/**
* Lifecycle hook to discover standard expanders, reusable expanders,
* and the links (@UseExpansionMethod) between them.
*/
onModuleInit(): Promise<void>;
/**
* Expands/selects properties of a resource based on the provided parameters.
* @param request - The incoming request object.
* @param resource - The resource to be expanded.
* @param expandable - The parameters for expansion, including the target class and rootField.
* @returns The expanded resource.
* @throws Error if there's an issue during the expansion process.
*/
expandAndSelect<T = any>(request: any, resource: any, expandable?: ExpandableParams, selectable?: SelectableParams): Promise<T>;
private log;
/**
* Helper to discover @UseExpansionMethod metadata on a class.
* @param targetClass The class to inspect for @UseExpansionMethod metadata.
* @returns A map of field names to their corresponding UseExpansionMethodMetadata.
*/
private discoverExpansionMethodLinks;
/**
* Returns the @Expandable metadata for a given method using the Reflect API.
* @remarks
* This method is used internally as a wrapper around Reflect.getMetadata to make testing easier.
* @param target - The method to be inspected.
* @returns The @Expandable metadata for the given method or undefined if none is found.
*/
private getMethodExpandableMetadata;
private transformResource;
private expandResource;
private selectResource;
}