@ackplus/nest-dynamic-templates
Version:
A powerful and flexible dynamic template rendering library for NestJS applications with support for Nunjucks, Handlebars, EJS, Pug, MJML, Markdown, and more.
84 lines (83 loc) • 3.24 kB
TypeScript
import { BadRequestException, ConflictException, ForbiddenException, InternalServerErrorException, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
export declare enum TemplateErrorCode {
NOT_FOUND = "TEMPLATE_NOT_FOUND",
RENDER_FAILED = "TEMPLATE_RENDER_FAILED",
ENGINE_UNAVAILABLE = "TEMPLATE_ENGINE_UNAVAILABLE",
INVALID_INPUT = "TEMPLATE_INVALID_INPUT",
FORBIDDEN = "TEMPLATE_FORBIDDEN",
CONFLICT = "TEMPLATE_CONFLICT"
}
export type RenderStage = 'subject' | 'template-engine' | 'language-engine' | 'layout';
export interface TemplateErrorDetails {
code: TemplateErrorCode;
message: string;
stage?: RenderStage;
engine?: string;
language?: string;
templateName?: string;
scope?: string;
scopeId?: string;
locale?: string;
missingVariable?: string;
contextKeys?: string[];
location?: {
line: number;
column?: number;
};
snippet?: string;
hint?: string;
}
declare const TEMPLATE_ERROR: unique symbol;
export interface TemplateErrorLike {
code: TemplateErrorCode;
details: TemplateErrorDetails;
}
export declare function isTemplateError(e: unknown): e is TemplateErrorLike;
export declare class TemplateNotFoundError extends NotFoundException implements TemplateErrorLike {
readonly code = TemplateErrorCode.NOT_FOUND;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(args: {
templateName: string;
scope?: string;
scopeId?: string;
locale?: string;
kind?: 'template' | 'layout';
});
}
export declare class TemplateRenderError extends UnprocessableEntityException implements TemplateErrorLike {
readonly code = TemplateErrorCode.RENDER_FAILED;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(details: Omit<TemplateErrorDetails, 'code'>, cause?: unknown);
}
export declare class TemplateEngineUnavailableError extends InternalServerErrorException implements TemplateErrorLike {
readonly code = TemplateErrorCode.ENGINE_UNAVAILABLE;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(args: {
engine: string;
kind: 'template' | 'language';
reason: 'not-enabled' | 'not-installed';
peerPackage?: string;
});
}
export declare class TemplateInputError extends BadRequestException implements TemplateErrorLike {
readonly code = TemplateErrorCode.INVALID_INPUT;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(message: string, hint?: string);
}
export declare class TemplateForbiddenError extends ForbiddenException implements TemplateErrorLike {
readonly code = TemplateErrorCode.FORBIDDEN;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(message: string, hint?: string);
}
export declare class TemplateConflictError extends ConflictException implements TemplateErrorLike {
readonly code = TemplateErrorCode.CONFLICT;
readonly details: TemplateErrorDetails;
readonly [TEMPLATE_ERROR] = true;
constructor(message: string, hint?: string);
}
export {};