.
This commit is contained in:
parent
9f8aa2299a
commit
91952a6fa5
8 changed files with 420 additions and 3 deletions
|
|
@ -68,4 +68,69 @@ declare const gerarRespostas: (callback?: tipoCallbackResposta) => InterfaceResp
|
|||
*/
|
||||
declare const respostaComuns: InterfaceRespostas;
|
||||
|
||||
export { IniciarRespostas, type InterfaceRespostas, codigosResposta, gerarRespostas, respostaComuns, type tipoCallbackResposta, type tipoPrErroInterno, type tipoResposta, type tipoRespostaErro, type tipoRespostaSucesso };
|
||||
/**
|
||||
* Mapa de códigos HTTP de erro usados pelo sistema ELicencie.
|
||||
*
|
||||
* Single source of truth para derivar `codigoErroELicencie`.
|
||||
*/
|
||||
declare const codigosErros: {
|
||||
readonly 400: "Erro de requisição";
|
||||
readonly 403: "Não autenticado";
|
||||
readonly 500: "Erro interno";
|
||||
readonly 504: "Tempo de resposta excedido";
|
||||
};
|
||||
/** Códigos HTTP de erro reconhecidos pelo ELicencie. */
|
||||
type codigoErroELicencie = keyof typeof codigosErros;
|
||||
interface tipoRespostaSucessoELicencie<T> {
|
||||
codigo: 200;
|
||||
eErro: false;
|
||||
valor: T;
|
||||
erro: undefined;
|
||||
detalhes?: Record<string, any>;
|
||||
}
|
||||
interface tipoRespostaErroELicencie {
|
||||
codigo: codigoErroELicencie;
|
||||
eErro: true;
|
||||
erro: string;
|
||||
valor: undefined;
|
||||
detalhes?: Record<string, any>;
|
||||
}
|
||||
type tipoRespostaELicencie<T> = tipoRespostaSucessoELicencie<T> | tipoRespostaErroELicencie;
|
||||
/**
|
||||
* Durante a transição de sistema, a entrada pode chegar em qualquer um
|
||||
* dos dois formatos. O conversor detecta e normaliza para P-Resposta.
|
||||
*/
|
||||
type tipoEntradaTransicao<T> = tipoRespostaELicencie<T> | tipoResposta<T>;
|
||||
/**
|
||||
* Converte uma resposta para o formato **P-Resposta** (padrão do pacote),
|
||||
* mantendo em runtime os campos de **ambos** os formatos para
|
||||
* compatibilidade durante a transição de sistema.
|
||||
*
|
||||
* **Tipo de retorno:** `tipoResposta<T>`
|
||||
*
|
||||
* **Conteúdo em runtime:** campos P-Resposta + campos ELicencie
|
||||
*
|
||||
* | P-Resposta | ELicencie | Relação |
|
||||
* |-------------|-------------|----------------------|
|
||||
* | `cod` | `codigo` | mapeamento de código |
|
||||
* | `mensagem` | `erro` | mesmo conteúdo |
|
||||
* | `valor` | `valor` | direto |
|
||||
* | `eErro` | `eErro` | direto |
|
||||
* | `eCerto` | — | derivado |
|
||||
* | `detalhes` | `detalhes` | string[] / Record |
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const res = converterRespostaELicencieParaPResposta(respostaQualquer)
|
||||
*
|
||||
* // Consumidor P-Resposta
|
||||
* if (res.eCerto) console.log(res.valor)
|
||||
*
|
||||
* // Consumidor ELicencie (lê campo extra em runtime)
|
||||
* const resAny = res as any
|
||||
* if (!resAny.eErro) console.log(resAny.valor)
|
||||
* ```
|
||||
*/
|
||||
declare const converterRespostaELicencieParaPResposta: <T>(entrada: tipoEntradaTransicao<T>) => tipoResposta<T>;
|
||||
|
||||
export { IniciarRespostas, type InterfaceRespostas, type codigoErroELicencie, codigosErros, codigosResposta, converterRespostaELicencieParaPResposta, gerarRespostas, respostaComuns, type tipoCallbackResposta, type tipoEntradaTransicao, type tipoPrErroInterno, type tipoResposta, type tipoRespostaELicencie, type tipoRespostaErro, type tipoRespostaErroELicencie, type tipoRespostaSucesso, type tipoRespostaSucessoELicencie };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue