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,36 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deletar_registros = exports.zp_deletar_registros = void 0;
|
||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
const p_respostas_1 = require("p-respostas");
|
||||
const zod_1 = require("zod");
|
||||
const variaveis_1 = require("./variaveis");
|
||||
//enviar registros para base de dados
|
||||
exports.zp_deletar_registros = zod_1.z.object({
|
||||
tabela: zod_1.z.string(),
|
||||
codigos: zod_1.z.array(zod_1.z.string()),
|
||||
});
|
||||
const deletar_registros = ({ conta, produto, emDesenvolvimento }) => async ({ codigos: codigos_entrada, tabela, }) => {
|
||||
const codigos = [...codigos_entrada];
|
||||
const url = new URL(`${(0, variaveis_1.urlPilao)(emDesenvolvimento).api}/${Object.keys({ deletar_registros: exports.deletar_registros })[0]}/${produto}/${conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (codigos.length > 0) {
|
||||
const bloco = codigos.splice(0, tamanhoBlocos);
|
||||
const resp = await (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, codigos: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
||||
.then((r) => r);
|
||||
if (resp.eErro) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
};
|
||||
exports.deletar_registros = deletar_registros;
|
||||
|
|
@ -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 {};
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ exports.zp_enviar_registros = zod_1.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;
|
||||
|
|
@ -35,12 +36,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(`${(0, variaveis_1.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}".`);
|
||||
|
|
@ -63,6 +64,36 @@ class ClassPilaoEnviar {
|
|||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
async __salvar_deletar_registros() {
|
||||
const codigos = [...this.__codigosParaDeletar];
|
||||
const url = new URL(`${(0, variaveis_1.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 (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela: this.__tabela, codigos: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]))
|
||||
.then((r) => r);
|
||||
if (resp.eErro) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
this.__codigosParaDeletar;
|
||||
return p_respostas_1.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 p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
}
|
||||
const PilaoEnviar = (_) => new ClassPilaoEnviar(_);
|
||||
exports.PilaoEnviar = PilaoEnviar;
|
||||
|
|
|
|||
21
dist-require/pilao-de-dados/index.d.ts
vendored
21
dist-require/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,7 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pPilao = exports.urlPilao = exports.PREFIXO_PILAO = void 0;
|
||||
const _deletar_registros_1 = require("./_deletar_registros");
|
||||
var variaveis_1 = require("./variaveis");
|
||||
Object.defineProperty(exports, "PREFIXO_PILAO", { enumerable: true, get: function () { return variaveis_1.PREFIXO_PILAO; } });
|
||||
Object.defineProperty(exports, "urlPilao", { enumerable: true, get: function () { return variaveis_1.urlPilao; } });
|
||||
|
|
@ -16,8 +15,6 @@ exports.pPilao = {
|
|||
serie_consultar: _serie_consultar_1.serie_consultar,
|
||||
zp_produto_conta: variaveis_2.zp_produto_conta,
|
||||
validarZ: variaveis_2.validarZ,
|
||||
deletar_registros: _deletar_registros_1.deletar_registros,
|
||||
zp_deletar_registros: _deletar_registros_1.zp_deletar_registros,
|
||||
operadores_pilao: variaveis_2.operadores_pilao,
|
||||
operadores_permitidos_por_tipo: variaveis_2.operadores_permitidos_por_tipo,
|
||||
z_filtro: _serie_consultar_1.z_filtro,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue