melhorias de tipagem
This commit is contained in:
parent
1d5d3a48b4
commit
afa28a0699
32 changed files with 435 additions and 486 deletions
|
|
@ -1 +1,3 @@
|
|||
# drivers
|
||||
|
||||
`pnpm config set fetch-timeout 60000`
|
||||
|
|
|
|||
14
dist-import/pilao-de-dados/_deletar_registros.d.ts
vendored
Normal file
14
dist-import/pilao-de-dados/_deletar_registros.d.ts
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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, tabela, }: z.infer<typeof zp_deletar_registros>) => Promise<tipoResposta<true>>;
|
||||
|
|
@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
import node_fetch from "cross-fetch";
|
||||
import { respostaComuns } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { PREFIXO, baseUrlPilao } from "./_variaveis";
|
||||
import { PREFIXO, baseUrlPilao } 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 = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
export const deletar_registros = ({ conta, produto, emDesenvolvimento }) => ({ codigos, tabela, }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${PREFIXO}/${Object.keys({ deletar_registros })[0]}/${produto}/${conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (codigos.length > 0) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./_variaveis";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_registrar_base_dados: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
colunas: z.ZodArray<z.ZodObject<{
|
||||
|
|
@ -51,10 +51,4 @@ export declare const zp_enviar_registros: z.ZodObject<{
|
|||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes" | null | undefined;
|
||||
}>[];
|
||||
}>;
|
||||
export declare const enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
/** Parametros da função */
|
||||
parametros: z.infer<typeof zp_enviar_registros>;
|
||||
}) => Promise<tipoResposta<true>>;
|
||||
export declare const enviar_registros: ({ conta, produto, emDesenvolvimento }: z.infer<typeof zp_produto_conta>) => ({ registros, tabela, }: z.infer<typeof zp_enviar_registros>) => Promise<tipoResposta<true>>;
|
||||
|
|
@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
import node_fetch from "cross-fetch";
|
||||
import { respostaComuns } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { PREFIXO, baseUrlPilao, z_tipo_coluna_base_dados, } from "./_variaveis";
|
||||
import { PREFIXO, baseUrlPilao, z_tipo_coluna_base_dados, } from "./variaveis";
|
||||
export const zp_registrar_base_dados = z.object({
|
||||
tabela: z.string(),
|
||||
colunas: z.array(z.object({
|
||||
|
|
@ -26,7 +26,7 @@ export const zp_enviar_registros = z.object({
|
|||
tipo: z_tipo_coluna_base_dados.optional().nullable(),
|
||||
}))),
|
||||
});
|
||||
export const enviar_registros = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
export const enviar_registros = ({ conta, produto, emDesenvolvimento }) => ({ registros, tabela, }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`);
|
||||
const tamanhoBlocos = 1000;
|
||||
while (registros.length > 0) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./_variaveis";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_serie_registrar: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
colanuEixoX: z.ZodString;
|
||||
|
|
@ -17,12 +17,7 @@ export declare const zp_serie_registrar: z.ZodObject<{
|
|||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
}>;
|
||||
export declare const serie_consultar: ({ emDesenvolvimento, cliente, parametros, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
parametros: z.infer<typeof zp_serie_registrar>;
|
||||
}) => {
|
||||
export declare const serie_consultar: (cliente: z.infer<typeof zp_produto_conta>) => (parametros: z.infer<typeof zp_serie_registrar>) => {
|
||||
dados: () => Promise<tipoResposta<{
|
||||
registros: any[];
|
||||
legenda: string;
|
||||
|
|
@ -10,16 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
import node_fetch from "cross-fetch";
|
||||
import { respostaComuns } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { PREFIXO, baseUrlPilao, tiposSeriesAgregacoes, } from "./_variaveis";
|
||||
import { PREFIXO, baseUrlPilao, tiposSeriesAgregacoes, } from "./variaveis";
|
||||
export const zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
});
|
||||
export const serie_consultar = ({ emDesenvolvimento, cliente, parametros, }) => {
|
||||
export const serie_consultar = (cliente) => (parametros) => {
|
||||
const dados = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`}`);
|
||||
const url = new URL(`${baseUrlPilao(cliente.emDesenvolvimento)}${`${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`}`);
|
||||
const resp = yield node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
|
|
@ -35,7 +35,7 @@ export const serie_consultar = ({ emDesenvolvimento, cliente, parametros, }) =>
|
|||
cliente,
|
||||
parametros,
|
||||
};
|
||||
const vUrl = new URL(`${emDesenvolvimento
|
||||
const vUrl = new URL(`${cliente.emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one"}${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}`);
|
||||
const serie = encodeURIComponent(JSON.stringify(pr, null, 2));
|
||||
|
|
@ -1,20 +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: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
/** Parametros da função */
|
||||
parametros: z.infer<typeof zp_deletar_registros>;
|
||||
}) => Promise<tipoResposta<true>>;
|
||||
32
dist-import/pilao-de-dados/index.d.ts
vendored
32
dist-import/pilao-de-dados/index.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { tiposSeriesAgregacoes } from "./_variaveis";
|
||||
import { tiposSeriesAgregacoes } from "./variaveis";
|
||||
export { tiposSeriesAgregacoes };
|
||||
export declare const pPilao: {
|
||||
zp_registrar_base_dados: import("zod").ZodObject<{
|
||||
|
|
@ -26,19 +26,16 @@ export declare const pPilao: {
|
|||
tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes";
|
||||
}[];
|
||||
}>;
|
||||
enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
enviar_registros: ({ conta, produto, emDesenvolvimento }: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => ({ registros, tabela, }: {
|
||||
tabela: string;
|
||||
registros: Record<string, {
|
||||
valor?: any;
|
||||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes" | null | undefined;
|
||||
}>[];
|
||||
};
|
||||
}) => Promise<import("p-respostas").tipoResposta<true>>;
|
||||
zp_enviar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
|
|
@ -81,18 +78,15 @@ export declare const pPilao: {
|
|||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
}>;
|
||||
serie_consultar: ({ emDesenvolvimento, cliente, parametros, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
serie_consultar: (cliente: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => (parametros: {
|
||||
tabela: string;
|
||||
colanuEixoX: string;
|
||||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
};
|
||||
}) => {
|
||||
dados: () => Promise<import("p-respostas").tipoResposta<{
|
||||
registros: any[];
|
||||
|
|
@ -109,24 +103,24 @@ export declare const pPilao: {
|
|||
zp_produto_conta: import("zod").ZodObject<{
|
||||
produto: import("zod").ZodString;
|
||||
conta: import("zod").ZodString;
|
||||
emDesenvolvimento: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
||||
}, "strip", import("zod").ZodTypeAny, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}>;
|
||||
validarZ: <T>(zodType: import("zod").ZodType<T, any, T>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
|
||||
deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
deletar_registros: ({ conta, produto, emDesenvolvimento }: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => ({ codigos, tabela, }: {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
};
|
||||
}) => Promise<import("p-respostas").tipoResposta<true>>;
|
||||
zp_deletar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./_variaveis";
|
||||
import { deletar_registros, zp_deletar_registros } from "./deletar_registros";
|
||||
import { enviar_registros, zp_enviar_registros, zp_registrar_base_dados, } from "./enviar_registros";
|
||||
import { serie_consultar, zp_serie_registrar } from "./serie_consultar";
|
||||
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros";
|
||||
import { enviar_registros, zp_enviar_registros, zp_registrar_base_dados, } from "./_enviar_registros";
|
||||
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./variaveis";
|
||||
import { serie_consultar, zp_serie_registrar } from "./_serie_consultar";
|
||||
export { tiposSeriesAgregacoes };
|
||||
export const pPilao = {
|
||||
zp_registrar_base_dados,
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ export declare const validarZ: <T>(zodType: z.ZodType<T, any, T>, objeto: any, m
|
|||
export declare const zp_produto_conta: z.ZodObject<{
|
||||
produto: z.ZodString;
|
||||
conta: z.ZodString;
|
||||
emDesenvolvimento: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}>;
|
||||
export declare const z_tipo_coluna_base_dados: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero", "data", "mes"]>;
|
||||
export declare const tiposSeriesAgregacoes: z.ZodEnum<["contagem", "somatoria"]>;
|
||||
|
|
@ -13,6 +13,7 @@ export const validarZ = (zodType, objeto, mensagem) => {
|
|||
export const zp_produto_conta = z.object({
|
||||
produto: z.string(),
|
||||
conta: z.string(),
|
||||
emDesenvolvimento: z.boolean().optional(),
|
||||
});
|
||||
export const z_tipo_coluna_base_dados = z.enum([
|
||||
"texto",
|
||||
14
dist-require/pilao-de-dados/_deletar_registros.d.ts
vendored
Normal file
14
dist-require/pilao-de-dados/_deletar_registros.d.ts
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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, tabela, }: z.infer<typeof zp_deletar_registros>) => Promise<tipoResposta<true>>;
|
||||
|
|
@ -43,22 +43,24 @@ exports.deletar_registros = exports.zp_deletar_registros = void 0;
|
|||
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
var p_respostas_1 = require("p-respostas");
|
||||
var zod_1 = require("zod");
|
||||
var _variaveis_1 = require("./_variaveis");
|
||||
var 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()),
|
||||
});
|
||||
var deletar_registros = function (_a) {
|
||||
var emDesenvolvimento = _a.emDesenvolvimento, _b = _a.cliente, conta = _b.conta, produto = _b.produto, _c = _a.parametros, codigos = _c.codigos, tabela = _c.tabela;
|
||||
var conta = _a.conta, produto = _a.produto, emDesenvolvimento = _a.emDesenvolvimento;
|
||||
return function (_a) {
|
||||
var codigos = _a.codigos, tabela = _a.tabela;
|
||||
return __awaiter(void 0, void 0, void 0, function () {
|
||||
var url, tamanhoBlocos, bloco, resp;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ deletar_registros: exports.deletar_registros })[0], "/").concat(produto, "/").concat(conta));
|
||||
url = new URL("".concat((0, variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(variaveis_1.PREFIXO, "/").concat(Object.keys({ deletar_registros: exports.deletar_registros })[0], "/").concat(produto, "/").concat(conta));
|
||||
tamanhoBlocos = 1000;
|
||||
_d.label = 1;
|
||||
_b.label = 1;
|
||||
case 1:
|
||||
if (!(codigos.length > 0)) return [3 /*break*/, 3];
|
||||
bloco = codigos.splice(0, tamanhoBlocos);
|
||||
|
|
@ -73,7 +75,7 @@ var deletar_registros = function (_a) {
|
|||
})
|
||||
.then(function (r) { return r; })];
|
||||
case 2:
|
||||
resp = _d.sent();
|
||||
resp = _b.sent();
|
||||
if (resp.eErro) {
|
||||
return [2 /*return*/, resp];
|
||||
}
|
||||
|
|
@ -82,5 +84,6 @@ var deletar_registros = function (_a) {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
exports.deletar_registros = deletar_registros;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./_variaveis";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_registrar_base_dados: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
colunas: z.ZodArray<z.ZodObject<{
|
||||
|
|
@ -51,10 +51,4 @@ export declare const zp_enviar_registros: z.ZodObject<{
|
|||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes" | null | undefined;
|
||||
}>[];
|
||||
}>;
|
||||
export declare const enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
/** Parametros da função */
|
||||
parametros: z.infer<typeof zp_enviar_registros>;
|
||||
}) => Promise<tipoResposta<true>>;
|
||||
export declare const enviar_registros: ({ conta, produto, emDesenvolvimento }: z.infer<typeof zp_produto_conta>) => ({ registros, tabela, }: z.infer<typeof zp_enviar_registros>) => Promise<tipoResposta<true>>;
|
||||
|
|
@ -43,12 +43,12 @@ exports.enviar_registros = exports.zp_enviar_registros = exports.zp_registrar_ba
|
|||
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
var p_respostas_1 = require("p-respostas");
|
||||
var zod_1 = require("zod");
|
||||
var _variaveis_1 = require("./_variaveis");
|
||||
var variaveis_1 = require("./variaveis");
|
||||
exports.zp_registrar_base_dados = zod_1.z.object({
|
||||
tabela: zod_1.z.string(),
|
||||
colunas: zod_1.z.array(zod_1.z.object({
|
||||
coluna: zod_1.z.string(),
|
||||
tipo: _variaveis_1.z_tipo_coluna_base_dados,
|
||||
tipo: variaveis_1.z_tipo_coluna_base_dados,
|
||||
})),
|
||||
});
|
||||
//enviar registros para base de dados
|
||||
|
|
@ -56,19 +56,21 @@ exports.zp_enviar_registros = zod_1.z.object({
|
|||
tabela: zod_1.z.string(),
|
||||
registros: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.object({
|
||||
valor: zod_1.z.any(),
|
||||
tipo: _variaveis_1.z_tipo_coluna_base_dados.optional().nullable(),
|
||||
tipo: variaveis_1.z_tipo_coluna_base_dados.optional().nullable(),
|
||||
}))),
|
||||
});
|
||||
var enviar_registros = function (_a) {
|
||||
var emDesenvolvimento = _a.emDesenvolvimento, _b = _a.cliente, conta = _b.conta, produto = _b.produto, _c = _a.parametros, registros = _c.registros, tabela = _c.tabela;
|
||||
var conta = _a.conta, produto = _a.produto, emDesenvolvimento = _a.emDesenvolvimento;
|
||||
return function (_a) {
|
||||
var registros = _a.registros, tabela = _a.tabela;
|
||||
return __awaiter(void 0, void 0, void 0, function () {
|
||||
var url, tamanhoBlocos, bloco, resp;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(_variaveis_1.PREFIXO, "/").concat(Object.keys({ enviar_registros: exports.enviar_registros })[0], "/").concat(produto, "/").concat(conta));
|
||||
url = new URL("".concat((0, variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat(variaveis_1.PREFIXO, "/").concat(Object.keys({ enviar_registros: exports.enviar_registros })[0], "/").concat(produto, "/").concat(conta));
|
||||
tamanhoBlocos = 1000;
|
||||
_d.label = 1;
|
||||
_b.label = 1;
|
||||
case 1:
|
||||
if (!(registros.length > 0)) return [3 /*break*/, 3];
|
||||
bloco = registros.splice(0, tamanhoBlocos);
|
||||
|
|
@ -83,7 +85,7 @@ var enviar_registros = function (_a) {
|
|||
})
|
||||
.then(function (r) { return r; })];
|
||||
case 2:
|
||||
resp = _d.sent();
|
||||
resp = _b.sent();
|
||||
if (resp.eErro) {
|
||||
return [2 /*return*/, resp];
|
||||
}
|
||||
|
|
@ -92,5 +94,6 @@ var enviar_registros = function (_a) {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
exports.enviar_registros = enviar_registros;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import type { tipoResposta } from "p-respostas";
|
||||
import { z } from "zod";
|
||||
import { type zp_produto_conta } from "./_variaveis";
|
||||
import { type zp_produto_conta } from "./variaveis";
|
||||
export declare const zp_serie_registrar: z.ZodObject<{
|
||||
tabela: z.ZodString;
|
||||
colanuEixoX: z.ZodString;
|
||||
|
|
@ -17,12 +17,7 @@ export declare const zp_serie_registrar: z.ZodObject<{
|
|||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
}>;
|
||||
export declare const serie_consultar: ({ emDesenvolvimento, cliente, parametros, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
parametros: z.infer<typeof zp_serie_registrar>;
|
||||
}) => {
|
||||
export declare const serie_consultar: (cliente: z.infer<typeof zp_produto_conta>) => (parametros: z.infer<typeof zp_serie_registrar>) => {
|
||||
dados: () => Promise<tipoResposta<{
|
||||
registros: any[];
|
||||
legenda: string;
|
||||
|
|
@ -43,21 +43,21 @@ exports.serie_consultar = exports.zp_serie_registrar = void 0;
|
|||
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
var p_respostas_1 = require("p-respostas");
|
||||
var zod_1 = require("zod");
|
||||
var _variaveis_1 = require("./_variaveis");
|
||||
var variaveis_1 = require("./variaveis");
|
||||
exports.zp_serie_registrar = zod_1.z.object({
|
||||
tabela: zod_1.z.string(),
|
||||
colanuEixoX: zod_1.z.string(),
|
||||
colunaAgrupamento: zod_1.z.string().array().optional(),
|
||||
agregacao: _variaveis_1.tiposSeriesAgregacoes,
|
||||
agregacao: variaveis_1.tiposSeriesAgregacoes,
|
||||
});
|
||||
var serie_consultar = function (_a) {
|
||||
var emDesenvolvimento = _a.emDesenvolvimento, cliente = _a.cliente, parametros = _a.parametros;
|
||||
var serie_consultar = function (cliente) {
|
||||
return function (parametros) {
|
||||
var dados = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var url, resp;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
url = new URL("".concat((0, _variaveis_1.baseUrlPilao)(emDesenvolvimento)).concat("".concat(_variaveis_1.PREFIXO, "/").concat(_variaveis_1.tiposSeriesAgregacoes.enum.contagem, "/").concat(cliente.produto, "/").concat(cliente.conta)));
|
||||
url = new URL("".concat((0, variaveis_1.baseUrlPilao)(cliente.emDesenvolvimento)).concat("".concat(variaveis_1.PREFIXO, "/").concat(variaveis_1.tiposSeriesAgregacoes.enum.contagem, "/").concat(cliente.produto, "/").concat(cliente.conta)));
|
||||
return [4 /*yield*/, (0, cross_fetch_1.default)(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
|
|
@ -79,9 +79,9 @@ var serie_consultar = function (_a) {
|
|||
cliente: cliente,
|
||||
parametros: parametros,
|
||||
};
|
||||
var vUrl = new URL("".concat(emDesenvolvimento
|
||||
var vUrl = new URL("".concat(cliente.emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one").concat(_variaveis_1.PREFIXO, "/").concat(_variaveis_1.tiposSeriesAgregacoes.enum.contagem));
|
||||
: "https://carro-de-boi.idz.one").concat(variaveis_1.PREFIXO, "/").concat(variaveis_1.tiposSeriesAgregacoes.enum.contagem));
|
||||
var serie = encodeURIComponent(JSON.stringify(pr, null, 2));
|
||||
return "".concat(vUrl.href, "?serie=").concat(serie);
|
||||
};
|
||||
|
|
@ -89,5 +89,6 @@ var serie_consultar = function (_a) {
|
|||
dados: dados,
|
||||
url: url,
|
||||
};
|
||||
};
|
||||
};
|
||||
exports.serie_consultar = serie_consultar;
|
||||
|
|
@ -1,20 +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: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | undefined | null;
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>;
|
||||
/** Parametros da função */
|
||||
parametros: z.infer<typeof zp_deletar_registros>;
|
||||
}) => Promise<tipoResposta<true>>;
|
||||
32
dist-require/pilao-de-dados/index.d.ts
vendored
32
dist-require/pilao-de-dados/index.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { tiposSeriesAgregacoes } from "./_variaveis";
|
||||
import { tiposSeriesAgregacoes } from "./variaveis";
|
||||
export { tiposSeriesAgregacoes };
|
||||
export declare const pPilao: {
|
||||
zp_registrar_base_dados: import("zod").ZodObject<{
|
||||
|
|
@ -26,19 +26,16 @@ export declare const pPilao: {
|
|||
tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes";
|
||||
}[];
|
||||
}>;
|
||||
enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
enviar_registros: ({ conta, produto, emDesenvolvimento }: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => ({ registros, tabela, }: {
|
||||
tabela: string;
|
||||
registros: Record<string, {
|
||||
valor?: any;
|
||||
tipo?: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero" | "data" | "mes" | null | undefined;
|
||||
}>[];
|
||||
};
|
||||
}) => Promise<import("p-respostas").tipoResposta<true>>;
|
||||
zp_enviar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
|
|
@ -81,18 +78,15 @@ export declare const pPilao: {
|
|||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
}>;
|
||||
serie_consultar: ({ emDesenvolvimento, cliente, parametros, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
serie_consultar: (cliente: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => (parametros: {
|
||||
tabela: string;
|
||||
colanuEixoX: string;
|
||||
agregacao: "contagem" | "somatoria";
|
||||
colunaAgrupamento?: string[] | undefined;
|
||||
};
|
||||
}) => {
|
||||
dados: () => Promise<import("p-respostas").tipoResposta<{
|
||||
registros: any[];
|
||||
|
|
@ -109,24 +103,24 @@ export declare const pPilao: {
|
|||
zp_produto_conta: import("zod").ZodObject<{
|
||||
produto: import("zod").ZodString;
|
||||
conta: import("zod").ZodString;
|
||||
emDesenvolvimento: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
||||
}, "strip", import("zod").ZodTypeAny, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}>;
|
||||
validarZ: <T>(zodType: import("zod").ZodType<T, any, T>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
|
||||
deletar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { codigos, tabela }, }: {
|
||||
emDesenvolvimento?: boolean | null | undefined;
|
||||
cliente: {
|
||||
deletar_registros: ({ conta, produto, emDesenvolvimento }: {
|
||||
produto: string;
|
||||
conta: string;
|
||||
};
|
||||
parametros: {
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}) => ({ codigos, tabela, }: {
|
||||
tabela: string;
|
||||
codigos: string[];
|
||||
};
|
||||
}) => Promise<import("p-respostas").tipoResposta<true>>;
|
||||
zp_deletar_registros: import("zod").ZodObject<{
|
||||
tabela: import("zod").ZodString;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pPilao = exports.tiposSeriesAgregacoes = void 0;
|
||||
var _variaveis_1 = require("./_variaveis");
|
||||
Object.defineProperty(exports, "tiposSeriesAgregacoes", { enumerable: true, get: function () { return _variaveis_1.tiposSeriesAgregacoes; } });
|
||||
var deletar_registros_1 = require("./deletar_registros");
|
||||
var enviar_registros_1 = require("./enviar_registros");
|
||||
var serie_consultar_1 = require("./serie_consultar");
|
||||
var _deletar_registros_1 = require("./_deletar_registros");
|
||||
var _enviar_registros_1 = require("./_enviar_registros");
|
||||
var variaveis_1 = require("./variaveis");
|
||||
Object.defineProperty(exports, "tiposSeriesAgregacoes", { enumerable: true, get: function () { return variaveis_1.tiposSeriesAgregacoes; } });
|
||||
var _serie_consultar_1 = require("./_serie_consultar");
|
||||
exports.pPilao = {
|
||||
zp_registrar_base_dados: enviar_registros_1.zp_registrar_base_dados,
|
||||
enviar_registros: enviar_registros_1.enviar_registros,
|
||||
zp_enviar_registros: enviar_registros_1.zp_enviar_registros,
|
||||
zp_serie_registrar: serie_consultar_1.zp_serie_registrar,
|
||||
serie_consultar: serie_consultar_1.serie_consultar,
|
||||
zp_produto_conta: _variaveis_1.zp_produto_conta,
|
||||
validarZ: _variaveis_1.validarZ,
|
||||
deletar_registros: deletar_registros_1.deletar_registros,
|
||||
zp_deletar_registros: deletar_registros_1.zp_deletar_registros,
|
||||
zp_registrar_base_dados: _enviar_registros_1.zp_registrar_base_dados,
|
||||
enviar_registros: _enviar_registros_1.enviar_registros,
|
||||
zp_enviar_registros: _enviar_registros_1.zp_enviar_registros,
|
||||
zp_serie_registrar: _serie_consultar_1.zp_serie_registrar,
|
||||
serie_consultar: _serie_consultar_1.serie_consultar,
|
||||
zp_produto_conta: variaveis_1.zp_produto_conta,
|
||||
validarZ: variaveis_1.validarZ,
|
||||
deletar_registros: _deletar_registros_1.deletar_registros,
|
||||
zp_deletar_registros: _deletar_registros_1.zp_deletar_registros,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ export declare const validarZ: <T>(zodType: z.ZodType<T, any, T>, objeto: any, m
|
|||
export declare const zp_produto_conta: z.ZodObject<{
|
||||
produto: z.ZodString;
|
||||
conta: z.ZodString;
|
||||
emDesenvolvimento: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}, {
|
||||
produto: string;
|
||||
conta: string;
|
||||
emDesenvolvimento?: boolean | undefined;
|
||||
}>;
|
||||
export declare const z_tipo_coluna_base_dados: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero", "data", "mes"]>;
|
||||
export declare const tiposSeriesAgregacoes: z.ZodEnum<["contagem", "somatoria"]>;
|
||||
|
|
@ -17,6 +17,7 @@ exports.validarZ = validarZ;
|
|||
exports.zp_produto_conta = zod_1.z.object({
|
||||
produto: zod_1.z.string(),
|
||||
conta: zod_1.z.string(),
|
||||
emDesenvolvimento: zod_1.z.boolean().optional(),
|
||||
});
|
||||
exports.z_tipo_coluna_base_dados = zod_1.z.enum([
|
||||
"texto",
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "p-drives",
|
||||
"version": "0.83.0",
|
||||
"version": "0.84.0",
|
||||
"description": "",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
|
|
|||
44
src/pilao-de-dados/_deletar_registros.ts
Normal file
44
src/pilao-de-dados/_deletar_registros.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import { PREFIXO, baseUrlPilao, 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,
|
||||
tabela,
|
||||
}: z.infer<typeof zp_deletar_registros>): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${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)
|
||||
}
|
||||
69
src/pilao-de-dados/_enviar_registros.ts
Normal file
69
src/pilao-de-dados/_enviar_registros.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
z_tipo_coluna_base_dados,
|
||||
type zp_produto_conta,
|
||||
} from "./variaveis"
|
||||
|
||||
export const zp_registrar_base_dados = z.object({
|
||||
tabela: z.string(),
|
||||
colunas: z.array(
|
||||
z.object({
|
||||
coluna: z.string(),
|
||||
tipo: z_tipo_coluna_base_dados,
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
//enviar registros para base de dados
|
||||
export const zp_enviar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
registros: z.array(
|
||||
z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
valor: z.any(),
|
||||
tipo: z_tipo_coluna_base_dados.optional().nullable(),
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
|
||||
export const enviar_registros =
|
||||
({ conta, produto, emDesenvolvimento }: z.infer<typeof zp_produto_conta>) =>
|
||||
async ({
|
||||
registros,
|
||||
tabela,
|
||||
}: z.infer<typeof zp_enviar_registros>): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`,
|
||||
)
|
||||
|
||||
const tamanhoBlocos = 1000
|
||||
|
||||
while (registros.length > 0) {
|
||||
const bloco = registros.splice(0, tamanhoBlocos)
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, registros: 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)
|
||||
}
|
||||
72
src/pilao-de-dados/_serie_consultar.ts
Normal file
72
src/pilao-de-dados/_serie_consultar.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./variaveis"
|
||||
|
||||
export const zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
})
|
||||
|
||||
export const serie_consultar =
|
||||
(cliente: z.infer<typeof zp_produto_conta>) =>
|
||||
(parametros: z.infer<typeof zp_serie_registrar>) => {
|
||||
const dados = async (): Promise<
|
||||
tipoResposta<{
|
||||
registros: any[]
|
||||
legenda: string
|
||||
serie: z.infer<typeof zp_serie_registrar>
|
||||
}>
|
||||
> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(cliente.emDesenvolvimento)}${`${PREFIXO}/${
|
||||
tiposSeriesAgregacoes.enum.contagem
|
||||
}/${cliente.produto}/${cliente.conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<any>)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
const url = (): string => {
|
||||
const pr = {
|
||||
cliente,
|
||||
parametros,
|
||||
}
|
||||
|
||||
const vUrl = new URL(
|
||||
`${
|
||||
cliente.emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}`,
|
||||
)
|
||||
|
||||
const serie = encodeURIComponent(JSON.stringify(pr, null, 2))
|
||||
|
||||
return `${vUrl.href}?serie=${serie}`
|
||||
}
|
||||
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import { PREFIXO, baseUrlPilao, 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 = async ({
|
||||
emDesenvolvimento,
|
||||
cliente: { conta, produto },
|
||||
parametros: { codigos, tabela },
|
||||
}: {
|
||||
emDesenvolvimento?: boolean | undefined | null
|
||||
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>
|
||||
/** Parametros da função */
|
||||
|
||||
parametros: z.infer<typeof zp_deletar_registros>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${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)
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
z_tipo_coluna_base_dados,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
||||
export const zp_registrar_base_dados = z.object({
|
||||
tabela: z.string(),
|
||||
colunas: z.array(
|
||||
z.object({
|
||||
coluna: z.string(),
|
||||
tipo: z_tipo_coluna_base_dados,
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
//enviar registros para base de dados
|
||||
export const zp_enviar_registros = z.object({
|
||||
tabela: z.string(),
|
||||
registros: z.array(
|
||||
z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
valor: z.any(),
|
||||
tipo: z_tipo_coluna_base_dados.optional().nullable(),
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
|
||||
export const enviar_registros = async ({
|
||||
emDesenvolvimento,
|
||||
cliente: { conta, produto },
|
||||
parametros: { registros, tabela },
|
||||
}: {
|
||||
emDesenvolvimento?: boolean | undefined | null
|
||||
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>
|
||||
/** Parametros da função */
|
||||
|
||||
parametros: z.infer<typeof zp_enviar_registros>
|
||||
}): Promise<tipoResposta<true>> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(
|
||||
emDesenvolvimento,
|
||||
)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`,
|
||||
)
|
||||
|
||||
const tamanhoBlocos = 1000
|
||||
|
||||
while (registros.length > 0) {
|
||||
const bloco = registros.splice(0, tamanhoBlocos)
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tabela, registros: 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)
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./_variaveis"
|
||||
import { deletar_registros, zp_deletar_registros } from "./deletar_registros"
|
||||
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros"
|
||||
import {
|
||||
enviar_registros,
|
||||
zp_enviar_registros,
|
||||
zp_registrar_base_dados,
|
||||
} from "./enviar_registros"
|
||||
} from "./_enviar_registros"
|
||||
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./variaveis"
|
||||
|
||||
import { serie_consultar, zp_serie_registrar } from "./serie_consultar"
|
||||
import { serie_consultar, zp_serie_registrar } from "./_serie_consultar"
|
||||
|
||||
export { tiposSeriesAgregacoes }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import { respostaComuns } from "p-respostas"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
PREFIXO,
|
||||
baseUrlPilao,
|
||||
tiposSeriesAgregacoes,
|
||||
type zp_produto_conta,
|
||||
} from "./_variaveis"
|
||||
|
||||
export const zp_serie_registrar = z.object({
|
||||
tabela: z.string(),
|
||||
colanuEixoX: z.string(),
|
||||
colunaAgrupamento: z.string().array().optional(),
|
||||
agregacao: tiposSeriesAgregacoes,
|
||||
})
|
||||
|
||||
export const serie_consultar = ({
|
||||
emDesenvolvimento,
|
||||
cliente,
|
||||
parametros,
|
||||
}: {
|
||||
emDesenvolvimento?: boolean | undefined | null
|
||||
|
||||
/** Identificação do cliente */
|
||||
cliente: z.infer<typeof zp_produto_conta>
|
||||
parametros: z.infer<typeof zp_serie_registrar>
|
||||
}) => {
|
||||
const dados = async (): Promise<
|
||||
tipoResposta<{
|
||||
registros: any[]
|
||||
legenda: string
|
||||
serie: z.infer<typeof zp_serie_registrar>
|
||||
}>
|
||||
> => {
|
||||
const url = new URL(
|
||||
`${baseUrlPilao(emDesenvolvimento)}${`${PREFIXO}/${
|
||||
tiposSeriesAgregacoes.enum.contagem
|
||||
}/${cliente.produto}/${cliente.conta}`}`,
|
||||
)
|
||||
|
||||
const resp = await node_fetch(url.toString(), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(parametros),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<any>)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
const url = (): string => {
|
||||
const pr = {
|
||||
cliente,
|
||||
parametros,
|
||||
}
|
||||
|
||||
const vUrl = new URL(
|
||||
`${
|
||||
emDesenvolvimento
|
||||
? "http://127.0.0.1:5081"
|
||||
: "https://carro-de-boi.idz.one"
|
||||
}${PREFIXO}/${tiposSeriesAgregacoes.enum.contagem}`,
|
||||
)
|
||||
|
||||
const serie = encodeURIComponent(JSON.stringify(pr, null, 2))
|
||||
|
||||
return `${vUrl.href}?serie=${serie}`
|
||||
}
|
||||
|
||||
return {
|
||||
dados,
|
||||
url,
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ export const validarZ = <T>(
|
|||
export const zp_produto_conta = z.object({
|
||||
produto: z.string(),
|
||||
conta: z.string(),
|
||||
emDesenvolvimento: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const z_tipo_coluna_base_dados = z.enum([
|
||||
Loading…
Add table
Add a link
Reference in a new issue