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;
|
__emDesenvolvimento: boolean | undefined;
|
||||||
__ver_log: boolean | undefined;
|
__ver_log: boolean | undefined;
|
||||||
__tabela: string | 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>);
|
constructor({ conta, produto, emDesenvolvimento, ver_log, }: z.infer<typeof zp_produto_conta>);
|
||||||
tabela(tabela: string): this;
|
tabela(tabela: string): this;
|
||||||
adicionarRegistro(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
adicionarRegistroParaEnviar(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||||
enviar(): Promise<tipoResposta<true>>;
|
__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 declare const PilaoEnviar: (_: z.infer<typeof zp_produto_conta>) => ClassPilaoEnviar;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ export const zp_enviar_registros = z.object({
|
||||||
});
|
});
|
||||||
class ClassPilaoEnviar {
|
class ClassPilaoEnviar {
|
||||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
||||||
this.__registros = [];
|
this.__registrosParaEnvio = [];
|
||||||
|
this.__codigosParaDeletar = [];
|
||||||
this.__conta = conta;
|
this.__conta = conta;
|
||||||
this.__produto = produto;
|
this.__produto = produto;
|
||||||
this.__emDesenvolvimento = emDesenvolvimento;
|
this.__emDesenvolvimento = emDesenvolvimento;
|
||||||
|
|
@ -29,12 +30,12 @@ class ClassPilaoEnviar {
|
||||||
this.__tabela = tabela;
|
this.__tabela = tabela;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
adicionarRegistro(...registro) {
|
adicionarRegistroParaEnviar(...registro) {
|
||||||
this.__registros.push(...registro);
|
this.__registrosParaEnvio.push(...registro);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
async enviar() {
|
async __salvar_enviar_registros() {
|
||||||
const registros = this.__registros;
|
const registros = this.__registrosParaEnvio;
|
||||||
const url = new URL(`${urlPilao(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
const url = new URL(`${urlPilao(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
||||||
if (this.__ver_log)
|
if (this.__ver_log)
|
||||||
console.log(`[PILÃO]: Enviando "${registros.length}" registros na tabela "${this.__tabela}" para "${url}".`);
|
console.log(`[PILÃO]: Enviando "${registros.length}" registros na tabela "${this.__tabela}" para "${url}".`);
|
||||||
|
|
@ -57,5 +58,35 @@ class ClassPilaoEnviar {
|
||||||
}
|
}
|
||||||
return respostaComuns.valor(true);
|
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(_);
|
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";
|
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||||
import { zp_enviar_registros } from "./_enviar_registros";
|
import { zp_enviar_registros } from "./_enviar_registros";
|
||||||
import { zp_produto_conta } from "./variaveis";
|
import { zp_produto_conta } from "./variaveis";
|
||||||
|
|
@ -313,10 +312,13 @@ export declare const pPilao: {
|
||||||
__emDesenvolvimento: boolean | undefined;
|
__emDesenvolvimento: boolean | undefined;
|
||||||
__ver_log: boolean | undefined;
|
__ver_log: boolean | undefined;
|
||||||
__tabela: string | 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;
|
tabela(tabela: string): any;
|
||||||
adicionarRegistro(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
adicionarRegistroParaEnviar(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
||||||
enviar(): Promise<import("p-respostas").tipoResposta<true>>;
|
__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<{
|
zp_enviar_registros: import("zod").ZodObject<{
|
||||||
tabela: import("zod").ZodString;
|
tabela: import("zod").ZodString;
|
||||||
|
|
@ -368,17 +370,6 @@ export declare const pPilao: {
|
||||||
ver_log?: boolean | undefined;
|
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>;
|
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_pilao: import("zod").ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
|
||||||
operadores_permitidos_por_tipo: {
|
operadores_permitidos_por_tipo: {
|
||||||
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
|
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros";
|
|
||||||
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||||
import { PilaoEnviar, zp_enviar_registros, zp_registrar_base_dados, } from "./_enviar_registros";
|
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";
|
import { operadores_permitidos_por_tipo, operadores_pilao, validarZ, zp_produto_conta, } from "./variaveis";
|
||||||
|
|
@ -11,8 +10,6 @@ export const pPilao = {
|
||||||
serie_consultar,
|
serie_consultar,
|
||||||
zp_produto_conta,
|
zp_produto_conta,
|
||||||
validarZ,
|
validarZ,
|
||||||
deletar_registros,
|
|
||||||
zp_deletar_registros,
|
|
||||||
operadores_pilao,
|
operadores_pilao,
|
||||||
operadores_permitidos_por_tipo,
|
operadores_permitidos_por_tipo,
|
||||||
z_filtro,
|
z_filtro,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
__emDesenvolvimento: boolean | undefined;
|
||||||
__ver_log: boolean | undefined;
|
__ver_log: boolean | undefined;
|
||||||
__tabela: string | 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>);
|
constructor({ conta, produto, emDesenvolvimento, ver_log, }: z.infer<typeof zp_produto_conta>);
|
||||||
tabela(tabela: string): this;
|
tabela(tabela: string): this;
|
||||||
adicionarRegistro(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
adicionarRegistroParaEnviar(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||||
enviar(): Promise<tipoResposta<true>>;
|
__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 declare const PilaoEnviar: (_: z.infer<typeof zp_produto_conta>) => ClassPilaoEnviar;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ exports.zp_enviar_registros = zod_1.z.object({
|
||||||
});
|
});
|
||||||
class ClassPilaoEnviar {
|
class ClassPilaoEnviar {
|
||||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
||||||
this.__registros = [];
|
this.__registrosParaEnvio = [];
|
||||||
|
this.__codigosParaDeletar = [];
|
||||||
this.__conta = conta;
|
this.__conta = conta;
|
||||||
this.__produto = produto;
|
this.__produto = produto;
|
||||||
this.__emDesenvolvimento = emDesenvolvimento;
|
this.__emDesenvolvimento = emDesenvolvimento;
|
||||||
|
|
@ -35,12 +36,12 @@ class ClassPilaoEnviar {
|
||||||
this.__tabela = tabela;
|
this.__tabela = tabela;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
adicionarRegistro(...registro) {
|
adicionarRegistroParaEnviar(...registro) {
|
||||||
this.__registros.push(...registro);
|
this.__registrosParaEnvio.push(...registro);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
async enviar() {
|
async __salvar_enviar_registros() {
|
||||||
const registros = this.__registros;
|
const registros = this.__registrosParaEnvio;
|
||||||
const url = new URL(`${(0, variaveis_1.urlPilao)(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
const url = new URL(`${(0, variaveis_1.urlPilao)(this.__emDesenvolvimento).api}/enviar_registros/${this.__produto}/${this.__conta}`);
|
||||||
if (this.__ver_log)
|
if (this.__ver_log)
|
||||||
console.log(`[PILÃO]: Enviando "${registros.length}" registros na tabela "${this.__tabela}" para "${url}".`);
|
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);
|
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(_);
|
const PilaoEnviar = (_) => new ClassPilaoEnviar(_);
|
||||||
exports.PilaoEnviar = PilaoEnviar;
|
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";
|
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||||
import { zp_enviar_registros } from "./_enviar_registros";
|
import { zp_enviar_registros } from "./_enviar_registros";
|
||||||
import { zp_produto_conta } from "./variaveis";
|
import { zp_produto_conta } from "./variaveis";
|
||||||
|
|
@ -313,10 +312,13 @@ export declare const pPilao: {
|
||||||
__emDesenvolvimento: boolean | undefined;
|
__emDesenvolvimento: boolean | undefined;
|
||||||
__ver_log: boolean | undefined;
|
__ver_log: boolean | undefined;
|
||||||
__tabela: string | 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;
|
tabela(tabela: string): any;
|
||||||
adicionarRegistro(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
adicionarRegistroParaEnviar(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
||||||
enviar(): Promise<import("p-respostas").tipoResposta<true>>;
|
__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<{
|
zp_enviar_registros: import("zod").ZodObject<{
|
||||||
tabela: import("zod").ZodString;
|
tabela: import("zod").ZodString;
|
||||||
|
|
@ -368,17 +370,6 @@ export declare const pPilao: {
|
||||||
ver_log?: boolean | undefined;
|
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>;
|
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_pilao: import("zod").ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
|
||||||
operadores_permitidos_por_tipo: {
|
operadores_permitidos_por_tipo: {
|
||||||
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
|
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.pPilao = exports.urlPilao = exports.PREFIXO_PILAO = void 0;
|
exports.pPilao = exports.urlPilao = exports.PREFIXO_PILAO = void 0;
|
||||||
const _deletar_registros_1 = require("./_deletar_registros");
|
|
||||||
var variaveis_1 = require("./variaveis");
|
var variaveis_1 = require("./variaveis");
|
||||||
Object.defineProperty(exports, "PREFIXO_PILAO", { enumerable: true, get: function () { return variaveis_1.PREFIXO_PILAO; } });
|
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; } });
|
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,
|
serie_consultar: _serie_consultar_1.serie_consultar,
|
||||||
zp_produto_conta: variaveis_2.zp_produto_conta,
|
zp_produto_conta: variaveis_2.zp_produto_conta,
|
||||||
validarZ: variaveis_2.validarZ,
|
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_pilao: variaveis_2.operadores_pilao,
|
||||||
operadores_permitidos_por_tipo: variaveis_2.operadores_permitidos_por_tipo,
|
operadores_permitidos_por_tipo: variaveis_2.operadores_permitidos_por_tipo,
|
||||||
z_filtro: _serie_consultar_1.z_filtro,
|
z_filtro: _serie_consultar_1.z_filtro,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "p-drives",
|
"name": "p-drives",
|
||||||
"version": "0.151.0",
|
"version": "0.152.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
import node_fetch from "cross-fetch"
|
|
||||||
import type { tipoResposta } from "p-respostas"
|
|
||||||
import { respostaComuns } from "p-respostas"
|
|
||||||
import { z } from "zod"
|
|
||||||
import { urlPilao, type zp_produto_conta } 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 }: z.infer<typeof zp_produto_conta>) =>
|
|
||||||
async ({
|
|
||||||
codigos: codigos_entrada,
|
|
||||||
tabela,
|
|
||||||
}: z.infer<typeof zp_deletar_registros>): Promise<tipoResposta<true>> => {
|
|
||||||
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 as tipoResposta<true>)
|
|
||||||
|
|
||||||
if (resp.eErro) {
|
|
||||||
return resp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return respostaComuns.valor(true)
|
|
||||||
}
|
|
||||||
|
|
@ -38,7 +38,8 @@ class ClassPilaoEnviar {
|
||||||
__emDesenvolvimento: boolean | undefined
|
__emDesenvolvimento: boolean | undefined
|
||||||
__ver_log: boolean | undefined
|
__ver_log: boolean | undefined
|
||||||
__tabela: string | undefined
|
__tabela: string | undefined
|
||||||
__registros: z.infer<typeof zp_enviar_registros>["registros"] = []
|
__registrosParaEnvio: z.infer<typeof zp_enviar_registros>["registros"] = []
|
||||||
|
__codigosParaDeletar: string[] = []
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
conta,
|
conta,
|
||||||
|
|
@ -57,15 +58,15 @@ class ClassPilaoEnviar {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
adicionarRegistro(
|
adicionarRegistroParaEnviar(
|
||||||
...registro: z.infer<typeof zp_enviar_registros>["registros"]
|
...registro: z.infer<typeof zp_enviar_registros>["registros"]
|
||||||
) {
|
) {
|
||||||
this.__registros.push(...registro)
|
this.__registrosParaEnvio.push(...registro)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
async enviar(): Promise<tipoResposta<true>> {
|
async __salvar_enviar_registros(): Promise<tipoResposta<true>> {
|
||||||
const registros = this.__registros
|
const registros = this.__registrosParaEnvio
|
||||||
|
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`${
|
`${
|
||||||
|
|
@ -107,6 +108,50 @@ class ClassPilaoEnviar {
|
||||||
|
|
||||||
return respostaComuns.valor(true)
|
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 as tipoResposta<true>)
|
||||||
|
|
||||||
|
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 = (_: z.infer<typeof zp_produto_conta>) =>
|
export const PilaoEnviar = (_: z.infer<typeof zp_produto_conta>) =>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros"
|
|
||||||
export { PREFIXO_PILAO, urlPilao } from "./variaveis"
|
export { PREFIXO_PILAO, urlPilao } from "./variaveis"
|
||||||
import {
|
import {
|
||||||
PilaoEnviar,
|
PilaoEnviar,
|
||||||
|
|
@ -18,12 +17,12 @@ import { extruturas_de_campos, visoes } from "./visoes"
|
||||||
export const pPilao = {
|
export const pPilao = {
|
||||||
zp_registrar_base_dados,
|
zp_registrar_base_dados,
|
||||||
PilaoEnviar,
|
PilaoEnviar,
|
||||||
|
|
||||||
zp_enviar_registros,
|
zp_enviar_registros,
|
||||||
serie_consultar,
|
serie_consultar,
|
||||||
zp_produto_conta,
|
zp_produto_conta,
|
||||||
validarZ,
|
validarZ,
|
||||||
deletar_registros,
|
|
||||||
zp_deletar_registros,
|
|
||||||
operadores_pilao,
|
operadores_pilao,
|
||||||
operadores_permitidos_por_tipo,
|
operadores_permitidos_por_tipo,
|
||||||
z_filtro,
|
z_filtro,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue