_respostas/dist-front/index.d.mts
2026-04-02 10:08:55 -03:00

62 lines
2.3 KiB
TypeScript

/**
* Códigos padrão usados pelo contrato de respostas.
*
* Observação: este enum é parte da API pública do pacote.
*/
declare enum codigosResposta {
sucesso = 200,
erroConhecido = 400,
erroPermissao = 401,
erroNaoEncontrado = 404,
erroDesconhecido = 500,
tempoEsgotado = 504
}
type tipoRespostaSucesso<T> = {
cod: codigosResposta.sucesso;
valor: T;
mensagem: undefined;
eErro: false;
eCerto: true;
detalhes?: string[];
};
type tipoRespostaErro = {
cod: codigosResposta.erroConhecido | codigosResposta.erroDesconhecido | codigosResposta.erroPermissao | codigosResposta.erroNaoEncontrado | codigosResposta.tempoEsgotado;
valor: undefined;
mensagem: string;
eErro: true;
eCerto: false;
detalhes?: string[];
};
type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
type tipoPrErroInterno = {
erro: any;
mensagem?: string;
local: string;
__filename?: string;
};
/**
* Cria um conjunto de geradores de respostas.
*
* @param registrarErroInterno callback para registrar/normalizar erros internos.
*/
interface InterfaceRespostas {
valor: <T>(valor: T, detalhes?: string[]) => tipoRespostaSucesso<T>;
valorTrue: (detalhes?: string[]) => tipoRespostaSucesso<true>;
erro: (mensagem: string, detalhes?: string[]) => tipoRespostaErro;
erroPermissao: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
erroInterno: (op: tipoPrErroInterno) => tipoRespostaErro;
naoEncontrado: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
tempoEsgotado: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
erroEspera: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
}
declare const gerarRespostas: (
/** Faz um processamento quando erro interno
* Recebe o erro gerado, mensagem personalizada e detalhes
*/
registrarErroInterno: (op: tipoPrErroInterno) => Partial<tipoRespostaErro>) => InterfaceRespostas;
/**
* Instância default (sem handler de erro interno).
*/
declare const respostaComuns: InterfaceRespostas;
export { type InterfaceRespostas, codigosResposta, gerarRespostas, respostaComuns, type tipoPrErroInterno, type tipoResposta, type tipoRespostaErro, type tipoRespostaSucesso };