refatoração do drive de pilão de dados
This commit is contained in:
parent
1ee3565d3d
commit
f6c203ee3e
31 changed files with 887 additions and 554 deletions
60
dist-require/pilao-de-dados/Pilao/index.d.ts
vendored
Normal file
60
dist-require/pilao-de-dados/Pilao/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/** Drive completo do piilão de dados */
|
||||
import { type tipoResposta } from "p-respostas";
|
||||
import type { z } from "zod";
|
||||
import type { zp_enviar_registros } from "../_enviar_registros";
|
||||
import { type zp_deletar_registros } from "../variaveis";
|
||||
import type { visoes } from "../visoes";
|
||||
import type { tipo_pilao_api } from "./pilao-api.ts";
|
||||
import type { tipoConstrutorPilao } from "./tipagem";
|
||||
declare class ClassPilao {
|
||||
#private;
|
||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }: tipoConstrutorPilao & {
|
||||
ver_log?: boolean;
|
||||
emDesenvolvimento?: boolean;
|
||||
});
|
||||
rotaEnviarRegistros(): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
rotaDeletarRegistro(): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
rotaConsultarSerie(tipoVisao: keyof typeof visoes | ":tipoVisao"): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
rotaIframeSerie(tipoVisao: keyof typeof visoes | ":tipoVisao"): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
rotaFuncaoApi(funcao: keyof tipo_pilao_api | ":funcao"): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
consultarApi<T extends keyof tipo_pilao_api>(funcao: T, parametros: tipo_pilao_api[T]["pr"]): Promise<tipoResposta<tipo_pilao_api[T]["rs"]>>;
|
||||
get baseUrlApi(): "https://carro-de-boi.idz.one" | "http://localhost:5080";
|
||||
get baseUrlSite(): "https://carro-de-boi.idz.one" | "http://localhost:5081";
|
||||
validarCliente(_: any): tipoResposta<tipoConstrutorPilao>;
|
||||
adicionarRegistroParaEnviar(tabela: string, ...registros: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||
adicionarCodigoParaDeletar(tabela: string, ...codigos: z.infer<typeof zp_deletar_registros>["codigos"]): this;
|
||||
private processarRegistros;
|
||||
salvarRegistros(): Promise<tipoResposta<true>>;
|
||||
serieConsultar<T extends keyof typeof visoes>(tipoVisao: T, parametros: z.infer<(typeof visoes)[T]>): {
|
||||
dados: () => Promise<tipoResposta<{
|
||||
registros: any[];
|
||||
legenda: string;
|
||||
serie: z.infer<(typeof visoes)[T]>;
|
||||
}>>;
|
||||
url: () => string;
|
||||
};
|
||||
urlLaboratorio(): {
|
||||
rota: string;
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
export declare const Pilao: (_: tipoConstrutorPilao & {
|
||||
ver_log?: boolean;
|
||||
emDesenvolvimento?: boolean;
|
||||
}) => ClassPilao;
|
||||
export {};
|
||||
189
dist-require/pilao-de-dados/Pilao/index.js
Normal file
189
dist-require/pilao-de-dados/Pilao/index.js
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
"use strict";
|
||||
/** Drive completo do piilão de dados */
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _ClassPilao_instances, _ClassPilao_produto, _ClassPilao_conta, _ClassPilao_emDesenvolvimento, _ClassPilao_ver_log, _ClassPilao_registrosParaEnvio, _ClassPilao_codigosParaDeletar, _ClassPilao_gerarUrl, _ClassPilao_salvarEnviarRegistros, _ClassPilao_salvarDeletarRegistros;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Pilao = void 0;
|
||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
const p_comuns_1 = require("p-comuns");
|
||||
const p_respostas_1 = require("p-respostas");
|
||||
const variaveis_1 = require("../variaveis");
|
||||
class ClassPilao {
|
||||
constructor({ conta, produto, emDesenvolvimento = false, ver_log = false, }) {
|
||||
_ClassPilao_instances.add(this);
|
||||
_ClassPilao_produto.set(this, void 0);
|
||||
_ClassPilao_conta.set(this, void 0);
|
||||
_ClassPilao_emDesenvolvimento.set(this, void 0);
|
||||
_ClassPilao_ver_log.set(this, void 0);
|
||||
_ClassPilao_registrosParaEnvio.set(this, {});
|
||||
_ClassPilao_codigosParaDeletar.set(this, {});
|
||||
__classPrivateFieldSet(this, _ClassPilao_produto, produto, "f");
|
||||
__classPrivateFieldSet(this, _ClassPilao_conta, conta, "f");
|
||||
__classPrivateFieldSet(this, _ClassPilao_emDesenvolvimento, emDesenvolvimento, "f");
|
||||
__classPrivateFieldSet(this, _ClassPilao_ver_log, ver_log, "f");
|
||||
}
|
||||
rotaEnviarRegistros() {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_gerarUrl).call(this, "enviar-registros");
|
||||
}
|
||||
rotaDeletarRegistro() {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_gerarUrl).call(this, "deletar-registros");
|
||||
}
|
||||
rotaConsultarSerie(tipoVisao) {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_gerarUrl).call(this, "consultar-serie", tipoVisao);
|
||||
}
|
||||
rotaIframeSerie(tipoVisao) {
|
||||
const rota = `${variaveis_1.PREFIXO_PILAO}/${__classPrivateFieldGet(this, _ClassPilao_conta, "f")}/${__classPrivateFieldGet(this, _ClassPilao_produto, "f")}/consultar-serie/${tipoVisao}`;
|
||||
const url = `${this.baseUrlSite}${rota}`;
|
||||
return { rota, url };
|
||||
}
|
||||
rotaFuncaoApi(funcao) {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_gerarUrl).call(this, "API", funcao);
|
||||
}
|
||||
async consultarApi(funcao, parametros) {
|
||||
try {
|
||||
const response = await (0, cross_fetch_1.default)(this.rotaFuncaoApi(funcao).url, {
|
||||
body: JSON.stringify(parametros),
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return await response.json();
|
||||
}
|
||||
catch (erro) {
|
||||
console.error(erro);
|
||||
return p_respostas_1.respostaComuns.erroInterno({
|
||||
erro,
|
||||
local: (0, p_comuns_1.nomeVariavel)({ ClassPilao }),
|
||||
});
|
||||
}
|
||||
}
|
||||
get baseUrlApi() {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_emDesenvolvimento, "f")
|
||||
? "http://localhost:5080"
|
||||
: "https://carro-de-boi.idz.one";
|
||||
}
|
||||
get baseUrlSite() {
|
||||
return __classPrivateFieldGet(this, _ClassPilao_emDesenvolvimento, "f")
|
||||
? "http://localhost:5081"
|
||||
: "https://carro-de-boi.idz.one";
|
||||
}
|
||||
validarCliente(_) {
|
||||
if (!_?.conta)
|
||||
return p_respostas_1.respostaComuns.erro("Conta não informada");
|
||||
if (!_?.produto)
|
||||
return p_respostas_1.respostaComuns.erro("Produto não informado");
|
||||
return p_respostas_1.respostaComuns.valor(_);
|
||||
}
|
||||
adicionarRegistroParaEnviar(tabela, ...registros) {
|
||||
__classPrivateFieldGet(this, _ClassPilao_registrosParaEnvio, "f")[tabela] = [
|
||||
...(__classPrivateFieldGet(this, _ClassPilao_registrosParaEnvio, "f")[tabela] || []),
|
||||
...registros,
|
||||
];
|
||||
return this;
|
||||
}
|
||||
adicionarCodigoParaDeletar(tabela, ...codigos) {
|
||||
__classPrivateFieldGet(this, _ClassPilao_codigosParaDeletar, "f")[tabela] = [
|
||||
...(__classPrivateFieldGet(this, _ClassPilao_codigosParaDeletar, "f")[tabela] || []),
|
||||
...codigos,
|
||||
];
|
||||
return this;
|
||||
}
|
||||
async processarRegistros(url, registros, tabela, acao) {
|
||||
const tamanhoBlocos = 1000;
|
||||
while (registros.length > 0) {
|
||||
const bloco = registros
|
||||
.splice(0, tamanhoBlocos)
|
||||
.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v === undefined ? null : v])));
|
||||
const resp = await (0, cross_fetch_1.default)(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, registros: bloco }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => p_respostas_1.respostaComuns.erro(`Erro ao ${acao} registros`, [e.message]));
|
||||
if (resp.eErro)
|
||||
return resp;
|
||||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
async salvarRegistros() {
|
||||
const re = await __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_salvarEnviarRegistros).call(this);
|
||||
if (re.eErro)
|
||||
return re;
|
||||
const rd = await __classPrivateFieldGet(this, _ClassPilao_instances, "m", _ClassPilao_salvarDeletarRegistros).call(this);
|
||||
if (rd.eErro)
|
||||
return rd;
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}
|
||||
serieConsultar(tipoVisao, parametros) {
|
||||
const dados = async () => {
|
||||
const url = this.rotaConsultarSerie(tipoVisao).url;
|
||||
const resp = await (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]));
|
||||
if (__classPrivateFieldGet(this, _ClassPilao_ver_log, "f"))
|
||||
console.log(`[PILÃO]: buscar dados de "${JSON.stringify(parametros)}" para "${url}".`);
|
||||
return resp;
|
||||
};
|
||||
const url = () => {
|
||||
const vUrl = this.rotaIframeSerie(tipoVisao).url;
|
||||
const serie = encodeURIComponent(JSON.stringify(parametros, null, 2));
|
||||
if (__classPrivateFieldGet(this, _ClassPilao_ver_log, "f"))
|
||||
console.log(`[PILÃO]: Serie Consultar url de "${JSON.stringify(serie)}" para "${vUrl}".`);
|
||||
return `${vUrl}?serie=${serie}`;
|
||||
};
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
};
|
||||
}
|
||||
urlLaboratorio() {
|
||||
const rota = `${variaveis_1.PREFIXO_PILAO}/${__classPrivateFieldGet(this, _ClassPilao_conta, "f")}/${__classPrivateFieldGet(this, _ClassPilao_produto, "f")}/laboratório`;
|
||||
const url = `${this.baseUrlSite}${rota}`;
|
||||
return { rota, url };
|
||||
}
|
||||
}
|
||||
_ClassPilao_produto = new WeakMap(), _ClassPilao_conta = new WeakMap(), _ClassPilao_emDesenvolvimento = new WeakMap(), _ClassPilao_ver_log = new WeakMap(), _ClassPilao_registrosParaEnvio = new WeakMap(), _ClassPilao_codigosParaDeletar = new WeakMap(), _ClassPilao_instances = new WeakSet(), _ClassPilao_gerarUrl = function _ClassPilao_gerarUrl(acao, extraPath) {
|
||||
const rota = `${variaveis_1.PREFIXO_PILAO}/${__classPrivateFieldGet(this, _ClassPilao_conta, "f")}/${__classPrivateFieldGet(this, _ClassPilao_produto, "f")}/${acao}${extraPath ? `/${extraPath}` : ""}`;
|
||||
const url = `${this.baseUrlApi}${rota}`;
|
||||
return { rota, url };
|
||||
}, _ClassPilao_salvarEnviarRegistros = async function _ClassPilao_salvarEnviarRegistros() {
|
||||
for (const tabela of Object.keys(__classPrivateFieldGet(this, _ClassPilao_registrosParaEnvio, "f"))) {
|
||||
const registros = __classPrivateFieldGet(this, _ClassPilao_registrosParaEnvio, "f")[tabela] || [];
|
||||
const url = this.rotaEnviarRegistros().url;
|
||||
if (__classPrivateFieldGet(this, _ClassPilao_ver_log, "f"))
|
||||
console.log(`[PILÃO]: Enviando ${registros.length} registros na tabela "${tabela}" para "${url}".`);
|
||||
const resp = await this.processarRegistros(url, registros, tabela, "enviar");
|
||||
if (resp.eErro)
|
||||
return resp;
|
||||
__classPrivateFieldGet(this, _ClassPilao_registrosParaEnvio, "f")[tabela] = [];
|
||||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
}, _ClassPilao_salvarDeletarRegistros = async function _ClassPilao_salvarDeletarRegistros() {
|
||||
for (const tabela of Object.keys(__classPrivateFieldGet(this, _ClassPilao_codigosParaDeletar, "f"))) {
|
||||
const codigos = [...(__classPrivateFieldGet(this, _ClassPilao_codigosParaDeletar, "f")[tabela] || [])];
|
||||
const url = this.rotaDeletarRegistro().url;
|
||||
const resp = await this.processarRegistros(url, codigos, tabela, "deletar");
|
||||
if (resp.eErro)
|
||||
return resp;
|
||||
}
|
||||
return p_respostas_1.respostaComuns.valor(true);
|
||||
};
|
||||
const Pilao = (_) => new ClassPilao(_);
|
||||
exports.Pilao = Pilao;
|
||||
30
dist-require/pilao-de-dados/Pilao/pilao-api.ts.d.ts
vendored
Normal file
30
dist-require/pilao-de-dados/Pilao/pilao-api.ts.d.ts
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import type { z } from "zod";
|
||||
import type { zp_registrar_base_dados } from "../_enviar_registros";
|
||||
/**
|
||||
* {
|
||||
* 'rota':{
|
||||
* pr:{}// paramentros de entrada
|
||||
* rs:{}// resposta
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export type tipo_pilao_api = {
|
||||
/** retorna da data e hora do servido em formato iso */
|
||||
estado_servidor: {
|
||||
pr: {};
|
||||
rs: {
|
||||
data_hora: string;
|
||||
};
|
||||
};
|
||||
tabelas: {
|
||||
pr: {};
|
||||
rs: z.infer<typeof zp_registrar_base_dados>[];
|
||||
};
|
||||
unicos: {
|
||||
pr: {
|
||||
tabela: string;
|
||||
coluna: string;
|
||||
};
|
||||
rs: any[];
|
||||
};
|
||||
};
|
||||
2
dist-require/pilao-de-dados/Pilao/pilao-api.ts.js
Normal file
2
dist-require/pilao-de-dados/Pilao/pilao-api.ts.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
4
dist-require/pilao-de-dados/Pilao/tipagem.d.ts
vendored
Normal file
4
dist-require/pilao-de-dados/Pilao/tipagem.d.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export type tipoConstrutorPilao = {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
2
dist-require/pilao-de-dados/Pilao/tipagem.js
Normal file
2
dist-require/pilao-de-dados/Pilao/tipagem.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_deletar_registros, type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_registrar_base_dados: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
colunas: z.ZodArray<z.ZodObject<{
|
||||
|
|
@ -51,21 +49,3 @@ export declare const zp_enviar_registros: z.ZodObject<{
|
|||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "lista_mes" | "lista_data" | "mes" | "data" | null | undefined;
|
||||
}>[];
|
||||
}>;
|
||||
declare class ClassPilaoEnviar {
|
||||
__conta: string | undefined;
|
||||
__produto: string | undefined;
|
||||
__emDesenvolvimento: boolean | undefined;
|
||||
__ver_log: boolean | undefined;
|
||||
__tabela: string | undefined;
|
||||
__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;
|
||||
adicionarRegistroParaEnviar(...registro: z.infer<typeof zp_enviar_registros>["registros"]): this;
|
||||
adicionarCodigoParaDeletar(...codigos: z.infer<typeof zp_deletar_registros>["codigos"]): 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 {};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PilaoEnviar = exports.zp_enviar_registros = exports.zp_registrar_base_dados = void 0;
|
||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
const p_respostas_1 = require("p-respostas");
|
||||
exports.zp_enviar_registros = exports.zp_registrar_base_dados = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const variaveis_1 = require("./variaveis");
|
||||
exports.zp_registrar_base_dados = zod_1.z.object({
|
||||
|
|
@ -23,81 +18,3 @@ exports.zp_enviar_registros = zod_1.z.object({
|
|||
tipo: variaveis_1.z_tipo_coluna_base_dados.optional().nullable(),
|
||||
}))),
|
||||
});
|
||||
class ClassPilaoEnviar {
|
||||
constructor({ conta, produto, emDesenvolvimento, ver_log, }) {
|
||||
this.__registrosParaEnvio = [];
|
||||
this.__codigosParaDeletar = [];
|
||||
this.__conta = conta;
|
||||
this.__produto = produto;
|
||||
this.__emDesenvolvimento = emDesenvolvimento;
|
||||
this.__ver_log = ver_log;
|
||||
}
|
||||
tabela(tabela) {
|
||||
this.__tabela = tabela;
|
||||
return this;
|
||||
}
|
||||
adicionarRegistroParaEnviar(...registro) {
|
||||
this.__registrosParaEnvio.push(...registro);
|
||||
return this;
|
||||
}
|
||||
adicionarCodigoParaDeletar(...codigos) {
|
||||
this.__codigosParaDeletar.push(...codigos);
|
||||
return this;
|
||||
}
|
||||
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}".`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (registros.length > 0) {
|
||||
const bloco = registros
|
||||
.splice(0, tamanhoBlocos)
|
||||
.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v === undefined ? null : v])));
|
||||
const resp = await (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela: this.__tabela, registros: 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);
|
||||
}
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
import type { visoes } from "./visoes";
|
||||
export declare const z_filtro: z.ZodObject<{
|
||||
coluna: z.ZodString;
|
||||
valor: z.ZodAny;
|
||||
|
|
@ -15,11 +12,3 @@ export declare const z_filtro: z.ZodObject<{
|
|||
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
|
||||
valor?: any;
|
||||
}>;
|
||||
export declare const serie_consultar: (cliente: z.infer<typeof zp_produto_conta>) => <T extends keyof typeof visoes>(tipoVisao: T, parametros: z.infer<(typeof visoes)[T]>) => {
|
||||
dados: () => Promise<tipoResposta<{
|
||||
registros: any[];
|
||||
legenda: string;
|
||||
serie: z.infer<(typeof visoes)[T]>;
|
||||
}>>;
|
||||
url: () => string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.serie_consultar = exports.z_filtro = void 0;
|
||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
const p_respostas_1 = require("p-respostas");
|
||||
exports.z_filtro = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const variaveis_1 = require("./variaveis");
|
||||
exports.z_filtro = zod_1.z.object({
|
||||
|
|
@ -13,31 +8,3 @@ exports.z_filtro = zod_1.z.object({
|
|||
valor: zod_1.z.any(),
|
||||
operador: variaveis_1.operadores_pilao,
|
||||
});
|
||||
const serie_consultar = (cliente) => (tipoVisao, parametros) => {
|
||||
const dados = async () => {
|
||||
const url = new URL(`${(0, variaveis_1.urlPilao)(cliente.emDesenvolvimento).api}/${tipoVisao}/${cliente.produto}/${cliente.conta}`);
|
||||
const resp = await (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
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 (cliente.ver_log)
|
||||
console.log(`[PILÃO]: buscar dados de "${JSON.stringify(parametros)}" para "${url.href}".`);
|
||||
return resp;
|
||||
};
|
||||
const url = () => {
|
||||
const vUrl = new URL(`${(0, variaveis_1.urlPilao)(cliente.emDesenvolvimento).site}/${tipoVisao}/${cliente.produto}/${cliente.conta}`);
|
||||
const serie = encodeURIComponent(JSON.stringify(parametros, null, 2));
|
||||
if (cliente.ver_log)
|
||||
console.log(`[PILÃO]: Serie Consultar url de "${JSON.stringify(serie)}" para "${vUrl.href}".`);
|
||||
return `${vUrl.href}?serie=${serie}`;
|
||||
};
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
};
|
||||
};
|
||||
exports.serie_consultar = serie_consultar;
|
||||
|
|
|
|||
27
dist-require/pilao-de-dados/index.d.ts
vendored
27
dist-require/pilao-de-dados/index.d.ts
vendored
|
|
@ -1,7 +1,5 @@
|
|||
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
|
||||
import { zp_enviar_registros } from "./_enviar_registros";
|
||||
import { zp_deletar_registros, zp_produto_conta } from "./variaveis";
|
||||
import { visoes } from "./visoes";
|
||||
export * from "./Pilao";
|
||||
export declare const pPilao: {
|
||||
extruturas_de_campos: {
|
||||
z_contagem_em_barra_vertical: {
|
||||
|
|
@ -316,21 +314,6 @@ export declare const pPilao: {
|
|||
tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "lista_mes" | "lista_data" | "mes" | "data";
|
||||
}[];
|
||||
}>;
|
||||
PilaoEnviar: (_: import("zod").TypeOf<typeof zp_produto_conta>) => {
|
||||
__conta: string | undefined;
|
||||
__produto: string | undefined;
|
||||
__emDesenvolvimento: boolean | undefined;
|
||||
__ver_log: boolean | undefined;
|
||||
__tabela: string | undefined;
|
||||
__registrosParaEnvio: import("zod").TypeOf<typeof zp_enviar_registros>["registros"];
|
||||
__codigosParaDeletar: string[];
|
||||
tabela(tabela: string): any;
|
||||
adicionarRegistroParaEnviar(...registro: import("zod").TypeOf<typeof zp_enviar_registros>["registros"]): any;
|
||||
adicionarCodigoParaDeletar(...codigos: import("zod").TypeOf<typeof zp_deletar_registros>["codigos"]): 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;
|
||||
registros: import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
||||
|
|
@ -356,14 +339,6 @@ export declare const pPilao: {
|
|||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "lista_mes" | "lista_data" | "mes" | "data" | null | undefined;
|
||||
}>[];
|
||||
}>;
|
||||
serie_consultar: (cliente: import("zod").TypeOf<typeof zp_produto_conta>) => <T extends keyof typeof visoes>(tipoVisao: T, parametros: import("zod").TypeOf<(typeof visoes)[T]>) => {
|
||||
dados: () => Promise<import("p-respostas").tipoResposta<{
|
||||
registros: any[];
|
||||
legenda: string;
|
||||
serie: import("zod").TypeOf<(typeof visoes)[T]>;
|
||||
}>>;
|
||||
url: () => string;
|
||||
};
|
||||
zp_produto_conta: import("zod").ZodObject<{
|
||||
produto: import("zod").ZodString;
|
||||
conta: import("zod").ZodString;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,18 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pPilao = exports.urlPilao = exports.PREFIXO_PILAO = void 0;
|
||||
var variaveis_1 = require("./variaveis");
|
||||
|
|
@ -6,14 +20,13 @@ Object.defineProperty(exports, "PREFIXO_PILAO", { enumerable: true, get: functio
|
|||
Object.defineProperty(exports, "urlPilao", { enumerable: true, get: function () { return variaveis_1.urlPilao; } });
|
||||
const _enviar_registros_1 = require("./_enviar_registros");
|
||||
const variaveis_2 = require("./variaveis");
|
||||
__exportStar(require("./Pilao"), exports);
|
||||
const _serie_consultar_1 = require("./_serie_consultar");
|
||||
const visoes_1 = require("./visoes");
|
||||
exports.pPilao = {
|
||||
zp_deletar_registros: variaveis_2.zp_deletar_registros,
|
||||
zp_registrar_base_dados: _enviar_registros_1.zp_registrar_base_dados,
|
||||
PilaoEnviar: _enviar_registros_1.PilaoEnviar,
|
||||
zp_enviar_registros: _enviar_registros_1.zp_enviar_registros,
|
||||
serie_consultar: _serie_consultar_1.serie_consultar,
|
||||
zp_produto_conta: variaveis_2.zp_produto_conta,
|
||||
validarZ: variaveis_2.validarZ,
|
||||
operadores_pilao: variaveis_2.operadores_pilao,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue