build
This commit is contained in:
parent
93d3caa378
commit
2cf1dfe75d
16 changed files with 149 additions and 201 deletions
|
|
@ -1,14 +0,0 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_deletar_registros: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
codigos: z.ZodArray<z.ZodString, "many">;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
}, {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
}>;
|
||||
export declare const deletar_registros: ({ conta, produto, emDesenvolvimento }: z.infer<typeof zp_produto_conta>) => ({ codigos: codigos_entrada, tabela, }: z.infer<typeof zp_deletar_registros>) => Promise<tipoResposta<true>>;
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
import node_fetch from "cross-fetch";
|
||||
import { respostaComuns } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { urlPilao } from "./variaveis";
|
||||
//enviar registros para base de dados
|
||||
export const zp_deletar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
codigos: z.array(z.string()),
|
||||
});
|
||||
export const deletar_registros = ({ conta, produto, emDesenvolvimento }) => async ({ codigos: codigos_entrada, tabela, }) => {
|
||||
const codigos = [...codigos_entrada];
|
||||
const url = new URL(`${urlPilao(emDesenvolvimento).api}/${Object.keys({ deletar_registros })[0]}/${produto}/${conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (codigos.length > 0) {
|
||||
const bloco = codigos.splice(0, tamanhoBlocos);
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, codigos: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
||||
.then((r) => r);
|
||||
if (resp.eErro) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
return respostaComuns.valor(true);
|
||||
};
|
||||
|
|
@ -57,11 +57,14 @@ declare class ClassPilaoEnviar {
|
|||
__emDesenvolvimento: boolean | undefined;
|
||||
__ver_log: boolean | undefined;
|
||||
__tabela: string | undefined;
|
||||
__registros: z.infer<typeof zp_enviar_registros>["registros"];
|
||||
__registrosParaEnvio: z.infer<typeof zp_enviar_registros>["registros"];
|
||||
__codigosParaDeletar: string[];
|
||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }: z.infer<typeof zp_produto_conta>);
|
||||
tabela(tabela: string): this;
|
||||
adicionarRegistro(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||
enviar(): Promise<tipoResposta<true>>;
|
||||
adicionarRegistroParaEnviar(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||
__salvar_enviar_registros(): Promise<tipoResposta<true>>;
|
||||
__salvar_deletar_registros(): Promise<import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<boolean>>;
|
||||
salvar(): Promise<import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<boolean>>;
|
||||
}
|
||||
export declare const PilaoEnviar: (_: z.infer<typeof zp_produto_conta>) => ClassPilaoEnviar;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ export const zp_enviar_registros = z.object({
|
|||
});
|
||||
class ClassPilaoEnviar {
|
||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
||||
this.__registros = [];
|
||||
this.__registrosParaEnvio = [];
|
||||
this.__codigosParaDeletar = [];
|
||||
this.__conta = conta;
|
||||
this.__produto = produto;
|
||||
this.__emDesenvolvimento = emDesenvolvimento;
|
||||
|
|
@ -29,12 +30,12 @@ class ClassPilaoEnviar {
|
|||
this.__tabela = tabela;
|
||||
return this;
|
||||
}
|
||||
adicionarRegistro(...registro) {
|
||||
this.__registros.push(...registro);
|
||||
adicionarRegistroParaEnviar(...registro) {
|
||||
this.__registrosParaEnvio.push(...registro);
|
||||
return this;
|
||||
}
|
||||
async enviar() {
|
||||
const registros = this.__registros;
|
||||
async __salvar_enviar_registros() {
|
||||
const registros = this.__registrosParaEnvio;
|
||||
const url = new URL(`${urlPilao(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
||||
if (this.__ver_log)
|
||||
console.log(`[PILÃO]: Enviando "${registros.length}" registros na tabela "${this.__tabela}" para "${url}".`);
|
||||
|
|
@ -57,5 +58,35 @@ class ClassPilaoEnviar {
|
|||
}
|
||||
return respostaComuns.valor(true);
|
||||
}
|
||||
async __salvar_deletar_registros() {
|
||||
const codigos = [...this.__codigosParaDeletar];
|
||||
const url = new URL(`${urlPilao(this.__emDesenvolvimento).api}/deletar_registros/${this.__produto}/${this.__conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (codigos.length > 0) {
|
||||
const bloco = codigos.splice(0, tamanhoBlocos);
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela: this.__tabela, codigos: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
||||
.then((r) => r);
|
||||
if (resp.eErro) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
this.__codigosParaDeletar;
|
||||
return respostaComuns.valor(true);
|
||||
}
|
||||
async salvar() {
|
||||
const re = await this.__salvar_enviar_registros();
|
||||
if (re.eErro)
|
||||
return re;
|
||||
const rd = await this.__salvar_deletar_registros();
|
||||
if (rd.eErro)
|
||||
return rd;
|
||||
return respostaComuns.valor(true);
|
||||
}
|
||||
}
|
||||
export const PilaoEnviar = (_) => new ClassPilaoEnviar(_);
|
||||
|
|
|
|||
21
dist-import/pilao-de-dados/index.d.ts
vendored
21
dist-import/pilao-de-dados/index.d.ts
vendored
|
|
@ -1,4 +1,3 @@
|
|||
import { zp_deletar_registros } from "./_deletar_registros";
|
||||
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||
import { zp_enviar_registros } from "./_enviar_registros";
|
||||
import { zp_produto_conta } from "./variaveis";
|
||||
|
|
@ -313,10 +312,13 @@ export declare const pPilao: {
|
|||
__emDesenvolvimento: boolean | undefined;
|
||||
__ver_log: boolean | undefined;
|
||||
__tabela: string | undefined;
|
||||
__registros: import("zod").TypeOf<typeof zp_enviar_registros>["registros"];
|
||||
__registrosParaEnvio: import("zod").TypeOf<typeof zp_enviar_registros>["registros"];
|
||||
__codigosParaDeletar: string[];
|
||||
tabela(tabela: string): any;
|
||||
adicionarRegistro(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
||||
enviar(): Promise<import("p-respostas").tipoResposta<true>>;
|
||||
adicionarRegistroParaEnviar(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
||||
__salvar_enviar_registros(): Promise<import("p-respostas").tipoResposta<true>>;
|
||||
__salvar_deletar_registros(): Promise<import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<boolean>>;
|
||||
salvar(): Promise<import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<boolean>>;
|
||||
};
|
||||
zp_enviar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
|
|
@ -368,17 +370,6 @@ export declare const pPilao: {
|
|||
ver_log?: boolean | undefined;
|
||||
}>;
|
||||
validarZ: <T>(zodType: import("zod").ZodType<T, any>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
|
||||
deletar_registros: ({ conta, produto, emDesenvolvimento }: import("zod").TypeOf<typeof zp_produto_conta>) => ({ codigos: codigos_entrada, tabela, }: import("zod").TypeOf<typeof zp_deletar_registros>) => Promise<import("p-respostas").tipoResposta<true>>;
|
||||
zp_deletar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
codigos: import("zod").ZodArray<import("zod").ZodString, "many">;
|
||||
}, "strip", import("zod").ZodTypeAny, {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
}, {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
}>;
|
||||
operadores_pilao: import("zod").ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
|
||||
operadores_permitidos_por_tipo: {
|
||||
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros";
|
||||
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||
import { PilaoEnviar, zp_enviar_registros, zp_registrar_base_dados, } from "./_enviar_registros";
|
||||
import { operadores_permitidos_por_tipo, operadores_pilao, validarZ, zp_produto_conta, } from "./variaveis";
|
||||
|
|
@ -11,8 +10,6 @@ export const pPilao = {
|
|||
serie_consultar,
|
||||
zp_produto_conta,
|
||||
validarZ,
|
||||
deletar_registros,
|
||||
zp_deletar_registros,
|
||||
operadores_pilao,
|
||||
operadores_permitidos_por_tipo,
|
||||
z_filtro,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue