diff --git a/dist-import/autenticacao/_codigoContaSite.d.ts b/dist-import/autenticacao/_codigoContaSite.d.ts index 12b9a29..78e8e4a 100644 --- a/dist-import/autenticacao/_codigoContaSite.d.ts +++ b/dist-import/autenticacao/_codigoContaSite.d.ts @@ -1,9 +1,11 @@ import { type tipoResposta } from "p-respostas"; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; type tipoPostCodigoContaSite = { site: string; }; export declare const codigoContaSite: ({ ambiente, post, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; post: tipoPostCodigoContaSite; /** função que conecta com a API */ buscar: (url: string, post: tipoPostCodigoContaSite) => Promise>; diff --git a/dist-import/autenticacao/_urlAutenticacao.d.ts b/dist-import/autenticacao/_urlAutenticacao.d.ts index 242cc7f..e6f02b0 100644 --- a/dist-import/autenticacao/_urlAutenticacao.d.ts +++ b/dist-import/autenticacao/_urlAutenticacao.d.ts @@ -1 +1,3 @@ -export declare const urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; +export declare const urlAutenticacao: (ambiente: z.infer) => string; diff --git a/dist-import/autenticacao/_usuarios_quipo_governo.d.ts b/dist-import/autenticacao/_usuarios_quipo_governo.d.ts index 9435543..95b4511 100644 --- a/dist-import/autenticacao/_usuarios_quipo_governo.d.ts +++ b/dist-import/autenticacao/_usuarios_quipo_governo.d.ts @@ -1,4 +1,6 @@ import { type tipoResposta } from "p-respostas"; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; export type tipoUsuarioExterno = { nome: string; email: string; @@ -8,7 +10,7 @@ export type tipoUsuarioExterno = { chave_produto: string; }; export declare const usuarios_quipo_governo: ({ token_produto, ambiente, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; token_produto: string; buscar: (url: string, headers: { [k: string]: string; diff --git a/dist-import/autenticacao/_validarToken.d.ts b/dist-import/autenticacao/_validarToken.d.ts index 137313e..4a8e9b7 100644 --- a/dist-import/autenticacao/_validarToken.d.ts +++ b/dist-import/autenticacao/_validarToken.d.ts @@ -2,9 +2,11 @@ import type { tipoResposta } from "p-respostas"; type tipoPostValidarTokem = { token: string; }; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; /** faz a validação do token */ export declare const validarToken: ({ ambiente, post, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; post: tipoPostValidarTokem; /** função que conecta com a API */ buscar: (url: string, post: tipoPostValidarTokem) => Promise>; diff --git a/dist-import/index.d.ts b/dist-import/index.d.ts index f0ada90..ab49bc6 100644 --- a/dist-import/index.d.ts +++ b/dist-import/index.d.ts @@ -1,3 +1,4 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; export * from "./produtos"; +export * from "./pilao-de-dados"; diff --git a/dist-import/index.js b/dist-import/index.js index f0ada90..ab49bc6 100644 --- a/dist-import/index.js +++ b/dist-import/index.js @@ -1,3 +1,4 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; export * from "./produtos"; +export * from "./pilao-de-dados"; diff --git a/dist-import/pilao-de-dados/_variaveis.d.ts b/dist-import/pilao-de-dados/_variaveis.d.ts new file mode 100644 index 0000000..0827823 --- /dev/null +++ b/dist-import/pilao-de-dados/_variaveis.d.ts @@ -0,0 +1,22 @@ +import { z } from "zod"; +export declare const zAmbiente: z.ZodEnum<["desenvolvimento", "producao"]>; +export declare const PREFIXO = "/pilao-de-dados"; +export declare const validarZ: (zodType: z.ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; +export declare const zp_produto_conta: z.ZodObject<{ + produto: z.ZodString; + conta: z.ZodString; +}, "strip", z.ZodTypeAny, { + produto: string; + conta: string; +}, { + produto: string; + conta: string; +}>; +export declare const tiposColunas: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero"]>; +export declare const validarColuna: { + texto: z.ZodNullable; + numero: z.ZodNullable; + confirmacao: z.ZodNullable; + lista_texto: z.ZodNullable>; + lista_numero: z.ZodNullable>; +}; diff --git a/dist-import/pilao-de-dados/_variaveis.js b/dist-import/pilao-de-dados/_variaveis.js new file mode 100644 index 0000000..8135743 --- /dev/null +++ b/dist-import/pilao-de-dados/_variaveis.js @@ -0,0 +1,30 @@ +import { respostaComuns } from "p-respostas"; +import { z } from "zod"; +export const zAmbiente = z.enum(["desenvolvimento", "producao"]); +export const PREFIXO = "/pilao-de-dados"; +export const validarZ = (zodType, objeto, mensagem) => { + const validar = zodType.safeParse(objeto); + if (!validar.success) { + debugger; + return respostaComuns.erro(mensagem, validar.error.errors.map((e) => `${e.path} ${e.message}`)); + } + return respostaComuns.valor(validar.data); +}; +export const zp_produto_conta = z.object({ + produto: z.string(), + conta: z.string(), +}); +export const tiposColunas = z.enum([ + "texto", + "numero", + "confirmacao", + "lista_texto", + "lista_numero", +]); +export const validarColuna = { + texto: z.string().nullable(), + numero: z.number().nullable(), + confirmacao: z.boolean().nullable(), + lista_texto: z.array(z.string()).nullable(), + lista_numero: z.array(z.number()).nullable(), +}; diff --git a/dist-import/pilao-de-dados/consultar_serie.d.ts b/dist-import/pilao-de-dados/consultar_serie.d.ts new file mode 100644 index 0000000..df886d4 --- /dev/null +++ b/dist-import/pilao-de-dados/consultar_serie.d.ts @@ -0,0 +1,24 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +import type { zp_registrar_serie } from "./registrar_serie"; +export declare const zp_consultar_serie: z.ZodObject<{ + identificador: z.ZodString; +}, "strip", z.ZodTypeAny, { + identificador: string; +}, { + identificador: string; +}>; +export declare const consultar_serie: ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + parametros: z.infer; +}) => { + dados: () => Promise; + }>>; + url: () => string; +}; diff --git a/dist-import/pilao-de-dados/consultar_serie.js b/dist-import/pilao-de-dados/consultar_serie.js new file mode 100644 index 0000000..f280fe9 --- /dev/null +++ b/dist-import/pilao-de-dados/consultar_serie.js @@ -0,0 +1,47 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { respostaComuns } from "p-respostas"; +import { z } from "zod"; +import { PREFIXO } from "./_variaveis"; +//consultar compilação +export const zp_consultar_serie = z.object({ + identificador: z.string(), +}); +export const consultar_serie = ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }) => { + const dados = () => __awaiter(void 0, void 0, void 0, function* () { + const url = new URL(`${emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one"}${`${PREFIXO}/consultar-serie/${produto}/${conta}`}`); + const resp = yield fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r); + return resp; + }); + const url = () => { + const vUrl = new URL(`${emDesenvolvimento + ? "http://127.0.0.1:5081" + : "https://carro-de-boi.idz.one"}${PREFIXO}/grafico`); + vUrl.searchParams.append("produto", produto); + vUrl.searchParams.append("conta", conta); + vUrl.searchParams.append("identificador", identificador); + return vUrl.href; + }; + return { + dados, + url, + }; +}; diff --git a/dist-import/pilao-de-dados/enviar_registros.d.ts b/dist-import/pilao-de-dados/enviar_registros.d.ts new file mode 100644 index 0000000..02309a9 --- /dev/null +++ b/dist-import/pilao-de-dados/enviar_registros.d.ts @@ -0,0 +1,20 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +export declare const zp_enviar_registros: z.ZodObject<{ + tabela: z.ZodString; + registros: z.ZodArray; +}, "strip", z.ZodTypeAny, { + tabela: string; + registros: any[]; +}, { + tabela: string; + registros: any[]; +}>; +export declare const enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-import/pilao-de-dados/enviar_registros.js b/dist-import/pilao-de-dados/enviar_registros.js new file mode 100644 index 0000000..26f860f --- /dev/null +++ b/dist-import/pilao-de-dados/enviar_registros.js @@ -0,0 +1,31 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { respostaComuns } from "p-respostas"; +import { z } from "zod"; +import { PREFIXO } from "./_variaveis"; +//enviar registros para base de dados +export const zp_enviar_registros = z.object({ + tabela: z.string(), + registros: z.array(z.any()), +}); +export const enviar_registros = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () { + const url = new URL(`${emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one"}${PREFIXO}/enviar-registro/${produto}/${conta}`); + const resp = yield fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela, registros }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r); + return resp; +}); diff --git a/dist-import/pilao-de-dados/index.d.ts b/dist-import/pilao-de-dados/index.d.ts new file mode 100644 index 0000000..510606c --- /dev/null +++ b/dist-import/pilao-de-dados/index.d.ts @@ -0,0 +1,138 @@ +import { tiposColunas } from "./_variaveis"; +export { tiposColunas }; +export declare const pPilao: { + registrar_base_dados: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }; + }) => Promise>; + zp_registrar_base_dados: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + colunas: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }>, "many">; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }>; + enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + registros: any[]; + }; + }) => Promise>; + zp_enviar_registros: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + registros: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + registros: any[]; + }, { + tabela: string; + registros: any[]; + }>; + registrar_serie: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, tabela, }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }; + }) => Promise>; + zp_registrar_serie: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + identificador: import("zod").ZodString; + colanuEixoX: import("zod").ZodString; + colunaAgrupamento: import("zod").ZodString; + agregacao: import("zod").ZodEnum<["contagem"]>; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }>; + consultar_serie: ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + identificador: string; + }; + }) => { + dados: () => Promise>; + url: () => string; + }; + zp_consultar_serie: import("zod").ZodObject<{ + identificador: import("zod").ZodString; + }, "strip", import("zod").ZodTypeAny, { + identificador: string; + }, { + identificador: string; + }>; + zp_produto_conta: import("zod").ZodObject<{ + produto: import("zod").ZodString; + conta: import("zod").ZodString; + }, "strip", import("zod").ZodTypeAny, { + produto: string; + conta: string; + }, { + produto: string; + conta: string; + }>; + validarZ: (zodType: import("zod").ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; +}; diff --git a/dist-import/pilao-de-dados/index.js b/dist-import/pilao-de-dados/index.js new file mode 100644 index 0000000..7060546 --- /dev/null +++ b/dist-import/pilao-de-dados/index.js @@ -0,0 +1,18 @@ +import { tiposColunas, validarZ, zp_produto_conta } from "./_variaveis"; +import { consultar_serie, zp_consultar_serie } from "./consultar_serie"; +import { enviar_registros, zp_enviar_registros } from "./enviar_registros"; +import { registrar_base_dados, zp_registrar_base_dados, } from "./registrar_base_dados"; +import { registrar_serie, zp_registrar_serie } from "./registrar_serie"; +export { tiposColunas }; +export const pPilao = { + registrar_base_dados, + zp_registrar_base_dados, + enviar_registros, + zp_enviar_registros, + registrar_serie, + zp_registrar_serie, + consultar_serie, + zp_consultar_serie, + zp_produto_conta, + validarZ, +}; diff --git a/dist-import/pilao-de-dados/registrar_base_dados.d.ts b/dist-import/pilao-de-dados/registrar_base_dados.d.ts new file mode 100644 index 0000000..fcd89ee --- /dev/null +++ b/dist-import/pilao-de-dados/registrar_base_dados.d.ts @@ -0,0 +1,36 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */ +export declare const zp_registrar_base_dados: z.ZodObject<{ + tabela: z.ZodString; + colunas: z.ZodArray; + }, "strip", z.ZodTypeAny, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }>, "many">; +}, "strip", z.ZodTypeAny, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; +}, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; +}>; +export declare const registrar_base_dados: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-import/pilao-de-dados/registrar_base_dados.js b/dist-import/pilao-de-dados/registrar_base_dados.js new file mode 100644 index 0000000..b0a7329 --- /dev/null +++ b/dist-import/pilao-de-dados/registrar_base_dados.js @@ -0,0 +1,34 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { respostaComuns } from "p-respostas"; +import { z } from "zod"; +import { PREFIXO, tiposColunas } from "./_variaveis"; +/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */ +export const zp_registrar_base_dados = z.object({ + tabela: z.string(), + colunas: z.array(z.object({ + coluna: z.string(), + tipo: tiposColunas, + })), +}); +export const registrar_base_dados = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }) => __awaiter(void 0, void 0, void 0, function* () { + const url = new URL(`${emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one"}${`${PREFIXO}/registar-base-dados/${produto}/${conta}`}`); + const resp = yield fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela, colunas }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r); + return resp; +}); diff --git a/dist-import/pilao-de-dados/registrar_serie.d.ts b/dist-import/pilao-de-dados/registrar_serie.d.ts new file mode 100644 index 0000000..09e5638 --- /dev/null +++ b/dist-import/pilao-de-dados/registrar_serie.d.ts @@ -0,0 +1,29 @@ +import { type tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +export declare const zp_registrar_serie: z.ZodObject<{ + tabela: z.ZodString; + identificador: z.ZodString; + colanuEixoX: z.ZodString; + colunaAgrupamento: z.ZodString; + agregacao: z.ZodEnum<["contagem"]>; +}, "strip", z.ZodTypeAny, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; +}, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; +}>; +export declare const registrar_serie: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, tabela, }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-import/pilao-de-dados/registrar_serie.js b/dist-import/pilao-de-dados/registrar_serie.js new file mode 100644 index 0000000..50fd569 --- /dev/null +++ b/dist-import/pilao-de-dados/registrar_serie.js @@ -0,0 +1,41 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { respostaComuns } from "p-respostas"; +import { z } from "zod"; +import { PREFIXO } from "./_variaveis"; +//registrar serie +export const zp_registrar_serie = z.object({ + tabela: z.string(), + identificador: z.string(), + colanuEixoX: z.string(), + colunaAgrupamento: z.string(), + agregacao: z.enum(["contagem"]), +}); +export const registrar_serie = ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, tabela, }, }) => __awaiter(void 0, void 0, void 0, function* () { + const url = new URL(`${emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one"}${`${PREFIXO}/registar-serie/${produto}/${conta}`}`); + const resp = yield fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + tabela, + agregacao, + emDesenvolvimento, + colanuEixoX, + colunaAgrupamento, + identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r); + return resp; +}); diff --git a/dist-import/ts/ambiente.d.ts b/dist-import/ts/ambiente.d.ts new file mode 100644 index 0000000..396720c --- /dev/null +++ b/dist-import/ts/ambiente.d.ts @@ -0,0 +1,2 @@ +import { z } from "zod"; +export declare const zAmbiente: z.ZodEnum<["desenvolvimento", "producao"]>; diff --git a/dist-import/ts/ambiente.js b/dist-import/ts/ambiente.js new file mode 100644 index 0000000..6b25786 --- /dev/null +++ b/dist-import/ts/ambiente.js @@ -0,0 +1,2 @@ +import { z } from "zod"; +export const zAmbiente = z.enum(["desenvolvimento", "producao"]); diff --git a/dist-require/autenticacao/_codigoContaSite.d.ts b/dist-require/autenticacao/_codigoContaSite.d.ts index 12b9a29..78e8e4a 100644 --- a/dist-require/autenticacao/_codigoContaSite.d.ts +++ b/dist-require/autenticacao/_codigoContaSite.d.ts @@ -1,9 +1,11 @@ import { type tipoResposta } from "p-respostas"; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; type tipoPostCodigoContaSite = { site: string; }; export declare const codigoContaSite: ({ ambiente, post, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; post: tipoPostCodigoContaSite; /** função que conecta com a API */ buscar: (url: string, post: tipoPostCodigoContaSite) => Promise>; diff --git a/dist-require/autenticacao/_urlAutenticacao.d.ts b/dist-require/autenticacao/_urlAutenticacao.d.ts index 242cc7f..e6f02b0 100644 --- a/dist-require/autenticacao/_urlAutenticacao.d.ts +++ b/dist-require/autenticacao/_urlAutenticacao.d.ts @@ -1 +1,3 @@ -export declare const urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; +export declare const urlAutenticacao: (ambiente: z.infer) => string; diff --git a/dist-require/autenticacao/_usuarios_quipo_governo.d.ts b/dist-require/autenticacao/_usuarios_quipo_governo.d.ts index 9435543..95b4511 100644 --- a/dist-require/autenticacao/_usuarios_quipo_governo.d.ts +++ b/dist-require/autenticacao/_usuarios_quipo_governo.d.ts @@ -1,4 +1,6 @@ import { type tipoResposta } from "p-respostas"; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; export type tipoUsuarioExterno = { nome: string; email: string; @@ -8,7 +10,7 @@ export type tipoUsuarioExterno = { chave_produto: string; }; export declare const usuarios_quipo_governo: ({ token_produto, ambiente, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; token_produto: string; buscar: (url: string, headers: { [k: string]: string; diff --git a/dist-require/autenticacao/_validarToken.d.ts b/dist-require/autenticacao/_validarToken.d.ts index 137313e..4a8e9b7 100644 --- a/dist-require/autenticacao/_validarToken.d.ts +++ b/dist-require/autenticacao/_validarToken.d.ts @@ -2,9 +2,11 @@ import type { tipoResposta } from "p-respostas"; type tipoPostValidarTokem = { token: string; }; +import type { z } from "zod"; +import type { zAmbiente } from "../ts/ambiente"; /** faz a validação do token */ export declare const validarToken: ({ ambiente, post, buscar, }: { - ambiente: "desenvolvimento" | "producao"; + ambiente: z.infer; post: tipoPostValidarTokem; /** função que conecta com a API */ buscar: (url: string, post: tipoPostValidarTokem) => Promise>; diff --git a/dist-require/index.d.ts b/dist-require/index.d.ts index f0ada90..ab49bc6 100644 --- a/dist-require/index.d.ts +++ b/dist-require/index.d.ts @@ -1,3 +1,4 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; export * from "./produtos"; +export * from "./pilao-de-dados"; diff --git a/dist-require/index.js b/dist-require/index.js index 2c09e18..11487db 100644 --- a/dist-require/index.js +++ b/dist-require/index.js @@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./tokenQuipo"), exports); __exportStar(require("./autenticacao"), exports); __exportStar(require("./produtos"), exports); +__exportStar(require("./pilao-de-dados"), exports); diff --git a/dist-require/pilao-de-dados/_variaveis.d.ts b/dist-require/pilao-de-dados/_variaveis.d.ts new file mode 100644 index 0000000..0827823 --- /dev/null +++ b/dist-require/pilao-de-dados/_variaveis.d.ts @@ -0,0 +1,22 @@ +import { z } from "zod"; +export declare const zAmbiente: z.ZodEnum<["desenvolvimento", "producao"]>; +export declare const PREFIXO = "/pilao-de-dados"; +export declare const validarZ: (zodType: z.ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; +export declare const zp_produto_conta: z.ZodObject<{ + produto: z.ZodString; + conta: z.ZodString; +}, "strip", z.ZodTypeAny, { + produto: string; + conta: string; +}, { + produto: string; + conta: string; +}>; +export declare const tiposColunas: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero"]>; +export declare const validarColuna: { + texto: z.ZodNullable; + numero: z.ZodNullable; + confirmacao: z.ZodNullable; + lista_texto: z.ZodNullable>; + lista_numero: z.ZodNullable>; +}; diff --git a/dist-require/pilao-de-dados/_variaveis.js b/dist-require/pilao-de-dados/_variaveis.js new file mode 100644 index 0000000..284701b --- /dev/null +++ b/dist-require/pilao-de-dados/_variaveis.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.validarColuna = exports.tiposColunas = exports.zp_produto_conta = exports.validarZ = exports.PREFIXO = exports.zAmbiente = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +exports.zAmbiente = zod_1.z.enum(["desenvolvimento", "producao"]); +exports.PREFIXO = "/pilao-de-dados"; +var validarZ = function (zodType, objeto, mensagem) { + var validar = zodType.safeParse(objeto); + if (!validar.success) { + debugger; + return p_respostas_1.respostaComuns.erro(mensagem, validar.error.errors.map(function (e) { return "".concat(e.path, " ").concat(e.message); })); + } + return p_respostas_1.respostaComuns.valor(validar.data); +}; +exports.validarZ = validarZ; +exports.zp_produto_conta = zod_1.z.object({ + produto: zod_1.z.string(), + conta: zod_1.z.string(), +}); +exports.tiposColunas = zod_1.z.enum([ + "texto", + "numero", + "confirmacao", + "lista_texto", + "lista_numero", +]); +exports.validarColuna = { + texto: zod_1.z.string().nullable(), + numero: zod_1.z.number().nullable(), + confirmacao: zod_1.z.boolean().nullable(), + lista_texto: zod_1.z.array(zod_1.z.string()).nullable(), + lista_numero: zod_1.z.array(zod_1.z.number()).nullable(), +}; diff --git a/dist-require/pilao-de-dados/consultar_serie.d.ts b/dist-require/pilao-de-dados/consultar_serie.d.ts new file mode 100644 index 0000000..df886d4 --- /dev/null +++ b/dist-require/pilao-de-dados/consultar_serie.d.ts @@ -0,0 +1,24 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +import type { zp_registrar_serie } from "./registrar_serie"; +export declare const zp_consultar_serie: z.ZodObject<{ + identificador: z.ZodString; +}, "strip", z.ZodTypeAny, { + identificador: string; +}, { + identificador: string; +}>; +export declare const consultar_serie: ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + parametros: z.infer; +}) => { + dados: () => Promise; + }>>; + url: () => string; +}; diff --git a/dist-require/pilao-de-dados/consultar_serie.js b/dist-require/pilao-de-dados/consultar_serie.js new file mode 100644 index 0000000..1c06c1e --- /dev/null +++ b/dist-require/pilao-de-dados/consultar_serie.js @@ -0,0 +1,89 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.consultar_serie = exports.zp_consultar_serie = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +var _variaveis_1 = require("./_variaveis"); +//consultar compilação +exports.zp_consultar_serie = zod_1.z.object({ + identificador: zod_1.z.string(), +}); +var consultar_serie = function (_a) { + var emDesenvolvimento = _a.emDesenvolvimento, identificador = _a.parametros.identificador, _b = _a.cliente, conta = _b.conta, produto = _b.produto; + 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(emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/consultar-serie/").concat(produto, "/").concat(conta))); + return [4 /*yield*/, fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + identificador: identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then(function (r) { return r.json(); }) + .catch(function (e) { + return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]); + }) + .then(function (r) { return r; })]; + case 1: + resp = _a.sent(); + return [2 /*return*/, resp]; + } + }); + }); }; + var url = function () { + var vUrl = new URL("".concat(emDesenvolvimento + ? "http://127.0.0.1:5081" + : "https://carro-de-boi.idz.one").concat(_variaveis_1.PREFIXO, "/grafico")); + vUrl.searchParams.append("produto", produto); + vUrl.searchParams.append("conta", conta); + vUrl.searchParams.append("identificador", identificador); + return vUrl.href; + }; + return { + dados: dados, + url: url, + }; +}; +exports.consultar_serie = consultar_serie; diff --git a/dist-require/pilao-de-dados/enviar_registros.d.ts b/dist-require/pilao-de-dados/enviar_registros.d.ts new file mode 100644 index 0000000..02309a9 --- /dev/null +++ b/dist-require/pilao-de-dados/enviar_registros.d.ts @@ -0,0 +1,20 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +export declare const zp_enviar_registros: z.ZodObject<{ + tabela: z.ZodString; + registros: z.ZodArray; +}, "strip", z.ZodTypeAny, { + tabela: string; + registros: any[]; +}, { + tabela: string; + registros: any[]; +}>; +export declare const enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-require/pilao-de-dados/enviar_registros.js b/dist-require/pilao-de-dados/enviar_registros.js new file mode 100644 index 0000000..e5ada83 --- /dev/null +++ b/dist-require/pilao-de-dados/enviar_registros.js @@ -0,0 +1,73 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.enviar_registros = exports.zp_enviar_registros = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +var _variaveis_1 = require("./_variaveis"); +//enviar registros para base de dados +exports.zp_enviar_registros = zod_1.z.object({ + tabela: zod_1.z.string(), + registros: zod_1.z.array(zod_1.z.any()), +}); +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; + return __awaiter(void 0, void 0, void 0, function () { + var url, resp; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + url = new URL("".concat(emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one").concat(_variaveis_1.PREFIXO, "/enviar-registro/").concat(produto, "/").concat(conta)); + return [4 /*yield*/, fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela: tabela, registros: registros }), + headers: { "Content-Type": "application/json" }, + }) + .then(function (r) { return r.json(); }) + .catch(function (e) { return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]); }) + .then(function (r) { return r; })]; + case 1: + resp = _d.sent(); + return [2 /*return*/, resp]; + } + }); + }); +}; +exports.enviar_registros = enviar_registros; diff --git a/dist-require/pilao-de-dados/index.d.ts b/dist-require/pilao-de-dados/index.d.ts new file mode 100644 index 0000000..510606c --- /dev/null +++ b/dist-require/pilao-de-dados/index.d.ts @@ -0,0 +1,138 @@ +import { tiposColunas } from "./_variaveis"; +export { tiposColunas }; +export declare const pPilao: { + registrar_base_dados: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }; + }) => Promise>; + zp_registrar_base_dados: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + colunas: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }>, "many">; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; + }>; + enviar_registros: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { registros, tabela }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + registros: any[]; + }; + }) => Promise>; + zp_enviar_registros: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + registros: import("zod").ZodArray; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + registros: any[]; + }, { + tabela: string; + registros: any[]; + }>; + registrar_serie: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, tabela, }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }; + }) => Promise>; + zp_registrar_serie: import("zod").ZodObject<{ + tabela: import("zod").ZodString; + identificador: import("zod").ZodString; + colanuEixoX: import("zod").ZodString; + colunaAgrupamento: import("zod").ZodString; + agregacao: import("zod").ZodEnum<["contagem"]>; + }, "strip", import("zod").ZodTypeAny, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; + }>; + consultar_serie: ({ emDesenvolvimento, parametros: { identificador }, cliente: { conta, produto }, }: { + emDesenvolvimento?: boolean | null | undefined; + cliente: { + produto: string; + conta: string; + }; + parametros: { + identificador: string; + }; + }) => { + dados: () => Promise>; + url: () => string; + }; + zp_consultar_serie: import("zod").ZodObject<{ + identificador: import("zod").ZodString; + }, "strip", import("zod").ZodTypeAny, { + identificador: string; + }, { + identificador: string; + }>; + zp_produto_conta: import("zod").ZodObject<{ + produto: import("zod").ZodString; + conta: import("zod").ZodString; + }, "strip", import("zod").ZodTypeAny, { + produto: string; + conta: string; + }, { + produto: string; + conta: string; + }>; + validarZ: (zodType: import("zod").ZodType, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso; +}; diff --git a/dist-require/pilao-de-dados/index.js b/dist-require/pilao-de-dados/index.js new file mode 100644 index 0000000..cf2c9cb --- /dev/null +++ b/dist-require/pilao-de-dados/index.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.pPilao = exports.tiposColunas = void 0; +var _variaveis_1 = require("./_variaveis"); +Object.defineProperty(exports, "tiposColunas", { enumerable: true, get: function () { return _variaveis_1.tiposColunas; } }); +var consultar_serie_1 = require("./consultar_serie"); +var enviar_registros_1 = require("./enviar_registros"); +var registrar_base_dados_1 = require("./registrar_base_dados"); +var registrar_serie_1 = require("./registrar_serie"); +exports.pPilao = { + registrar_base_dados: registrar_base_dados_1.registrar_base_dados, + zp_registrar_base_dados: registrar_base_dados_1.zp_registrar_base_dados, + enviar_registros: enviar_registros_1.enviar_registros, + zp_enviar_registros: enviar_registros_1.zp_enviar_registros, + registrar_serie: registrar_serie_1.registrar_serie, + zp_registrar_serie: registrar_serie_1.zp_registrar_serie, + consultar_serie: consultar_serie_1.consultar_serie, + zp_consultar_serie: consultar_serie_1.zp_consultar_serie, + zp_produto_conta: _variaveis_1.zp_produto_conta, + validarZ: _variaveis_1.validarZ, +}; diff --git a/dist-require/pilao-de-dados/registrar_base_dados.d.ts b/dist-require/pilao-de-dados/registrar_base_dados.d.ts new file mode 100644 index 0000000..fcd89ee --- /dev/null +++ b/dist-require/pilao-de-dados/registrar_base_dados.d.ts @@ -0,0 +1,36 @@ +import type { tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */ +export declare const zp_registrar_base_dados: z.ZodObject<{ + tabela: z.ZodString; + colunas: z.ZodArray; + }, "strip", z.ZodTypeAny, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }, { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }>, "many">; +}, "strip", z.ZodTypeAny, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; +}, { + tabela: string; + colunas: { + coluna: string; + tipo: "texto" | "numero" | "confirmacao" | "lista_texto" | "lista_numero"; + }[]; +}>; +export declare const registrar_base_dados: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { colunas, tabela }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-require/pilao-de-dados/registrar_base_dados.js b/dist-require/pilao-de-dados/registrar_base_dados.js new file mode 100644 index 0000000..469ae7b --- /dev/null +++ b/dist-require/pilao-de-dados/registrar_base_dados.js @@ -0,0 +1,76 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.registrar_base_dados = exports.zp_registrar_base_dados = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +var _variaveis_1 = require("./_variaveis"); +/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */ +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.tiposColunas, + })), +}); +var registrar_base_dados = function (_a) { + var emDesenvolvimento = _a.emDesenvolvimento, _b = _a.cliente, conta = _b.conta, produto = _b.produto, _c = _a.parametros, colunas = _c.colunas, tabela = _c.tabela; + return __awaiter(void 0, void 0, void 0, function () { + var url, resp; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + url = new URL("".concat(emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/registar-base-dados/").concat(produto, "/").concat(conta))); + return [4 /*yield*/, fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela: tabela, colunas: colunas }), + headers: { "Content-Type": "application/json" }, + }) + .then(function (r) { return r.json(); }) + .catch(function (e) { return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]); }) + .then(function (r) { return r; })]; + case 1: + resp = _d.sent(); + return [2 /*return*/, resp]; + } + }); + }); +}; +exports.registrar_base_dados = registrar_base_dados; diff --git a/dist-require/pilao-de-dados/registrar_serie.d.ts b/dist-require/pilao-de-dados/registrar_serie.d.ts new file mode 100644 index 0000000..09e5638 --- /dev/null +++ b/dist-require/pilao-de-dados/registrar_serie.d.ts @@ -0,0 +1,29 @@ +import { type tipoResposta } from "p-respostas"; +import { z } from "zod"; +import { type zp_produto_conta } from "./_variaveis"; +export declare const zp_registrar_serie: z.ZodObject<{ + tabela: z.ZodString; + identificador: z.ZodString; + colanuEixoX: z.ZodString; + colunaAgrupamento: z.ZodString; + agregacao: z.ZodEnum<["contagem"]>; +}, "strip", z.ZodTypeAny, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; +}, { + tabela: string; + identificador: string; + colanuEixoX: string; + colunaAgrupamento: string; + agregacao: "contagem"; +}>; +export declare const registrar_serie: ({ emDesenvolvimento, cliente: { conta, produto }, parametros: { agregacao, colanuEixoX, colunaAgrupamento, identificador, tabela, }, }: { + emDesenvolvimento?: boolean | undefined | null; + /** Identificação do cliente */ + cliente: z.infer; + /** Parametros da função */ + parametros: z.infer; +}) => Promise>; diff --git a/dist-require/pilao-de-dados/registrar_serie.js b/dist-require/pilao-de-dados/registrar_serie.js new file mode 100644 index 0000000..d552698 --- /dev/null +++ b/dist-require/pilao-de-dados/registrar_serie.js @@ -0,0 +1,83 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.registrar_serie = exports.zp_registrar_serie = void 0; +var p_respostas_1 = require("p-respostas"); +var zod_1 = require("zod"); +var _variaveis_1 = require("./_variaveis"); +//registrar serie +exports.zp_registrar_serie = zod_1.z.object({ + tabela: zod_1.z.string(), + identificador: zod_1.z.string(), + colanuEixoX: zod_1.z.string(), + colunaAgrupamento: zod_1.z.string(), + agregacao: zod_1.z.enum(["contagem"]), +}); +var registrar_serie = function (_a) { + var emDesenvolvimento = _a.emDesenvolvimento, _b = _a.cliente, conta = _b.conta, produto = _b.produto, _c = _a.parametros, agregacao = _c.agregacao, colanuEixoX = _c.colanuEixoX, colunaAgrupamento = _c.colunaAgrupamento, identificador = _c.identificador, tabela = _c.tabela; + return __awaiter(void 0, void 0, void 0, function () { + var url, resp; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + url = new URL("".concat(emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one").concat("".concat(_variaveis_1.PREFIXO, "/registar-serie/").concat(produto, "/").concat(conta))); + return [4 /*yield*/, fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + tabela: tabela, + agregacao: agregacao, + emDesenvolvimento: emDesenvolvimento, + colanuEixoX: colanuEixoX, + colunaAgrupamento: colunaAgrupamento, + identificador: identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then(function (r) { return r.json(); }) + .catch(function (e) { return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]); }) + .then(function (r) { return r; })]; + case 1: + resp = _d.sent(); + return [2 /*return*/, resp]; + } + }); + }); +}; +exports.registrar_serie = registrar_serie; diff --git a/dist-require/ts/ambiente.d.ts b/dist-require/ts/ambiente.d.ts new file mode 100644 index 0000000..396720c --- /dev/null +++ b/dist-require/ts/ambiente.d.ts @@ -0,0 +1,2 @@ +import { z } from "zod"; +export declare const zAmbiente: z.ZodEnum<["desenvolvimento", "producao"]>; diff --git a/dist-require/ts/ambiente.js b/dist-require/ts/ambiente.js new file mode 100644 index 0000000..38d7d9c --- /dev/null +++ b/dist-require/ts/ambiente.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.zAmbiente = void 0; +var zod_1 = require("zod"); +exports.zAmbiente = zod_1.z.enum(["desenvolvimento", "producao"]); diff --git a/package.json b/package.json index 77b4430..4356660 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-drives", - "version": "0.51.0", + "version": "0.55.0", "description": "", "main": "src/index.ts", "exports": { @@ -27,7 +27,11 @@ "typescript": "^4.9.5" }, "keywords": [], - "author": "", + "author": { + "name": "AZTECA SOFTWARE LTDA", + "email": "ti@e-licencie.com.br", + "url": "https://e-licencie.com.br" + }, "license": "ISC", "dependencies": { "zod": "3.23.8" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e14b6d0..8affe27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,7 +26,7 @@ importers: version: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#ac72e915630a0f7750630a24389367141b0e8ae0(typescript@4.9.5) p-respostas: specifier: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#producao - version: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#7d895ac6d96b0f52f61668c9017249f36ab01c7d + version: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#d13e633204f5485d3af48c46f37317561250808a typescript: specifier: ^4.9.5 version: 4.9.5 @@ -128,9 +128,9 @@ packages: peerDependencies: typescript: ^5.0.0 - p-respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#7d895ac6d96b0f52f61668c9017249f36ab01c7d: - resolution: {commit: 7d895ac6d96b0f52f61668c9017249f36ab01c7d, repo: http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git, type: git} - version: 0.5.0 + p-respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#d13e633204f5485d3af48c46f37317561250808a: + resolution: {commit: d13e633204f5485d3af48c46f37317561250808a, repo: http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git, type: git} + version: 0.9.0 queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -235,7 +235,7 @@ snapshots: typescript: 4.9.5 zod: 3.23.8 - p-respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#7d895ac6d96b0f52f61668c9017249f36ab01c7d: + p-respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#d13e633204f5485d3af48c46f37317561250808a: dependencies: zod: 3.23.8 diff --git a/src/autenticacao/_codigoContaSite.ts b/src/autenticacao/_codigoContaSite.ts index 8533fe1..b15e0e7 100644 --- a/src/autenticacao/_codigoContaSite.ts +++ b/src/autenticacao/_codigoContaSite.ts @@ -1,4 +1,6 @@ import { respostaComuns, type tipoResposta } from "p-respostas" +import type { z } from "zod" +import type { zAmbiente } from "../ts/ambiente" import { urlAutenticacao } from "./_urlAutenticacao" type tipoPostCodigoContaSite = { site: string } @@ -7,7 +9,7 @@ export const codigoContaSite = async ({ post, buscar, }: { - ambiente: "desenvolvimento" | "producao" + ambiente: z.infer post: tipoPostCodigoContaSite /** função que conecta com a API */ buscar: ( diff --git a/src/autenticacao/_urlAutenticacao.ts b/src/autenticacao/_urlAutenticacao.ts index f04b3aa..c01d7d7 100644 --- a/src/autenticacao/_urlAutenticacao.ts +++ b/src/autenticacao/_urlAutenticacao.ts @@ -1,4 +1,7 @@ -export const urlAutenticacao = (ambiente: "desenvolvimento" | "producao") => +import type { z } from "zod" +import type { zAmbiente } from "../ts/ambiente" + +export const urlAutenticacao = (ambiente: z.infer) => `${ ambiente == "producao" ? "https://carro-de-boi.idz.one" diff --git a/src/autenticacao/_usuarios_quipo_governo.ts b/src/autenticacao/_usuarios_quipo_governo.ts index 260bafe..c611728 100644 --- a/src/autenticacao/_usuarios_quipo_governo.ts +++ b/src/autenticacao/_usuarios_quipo_governo.ts @@ -1,4 +1,6 @@ import { respostaComuns, type tipoResposta } from "p-respostas" +import type { z } from "zod" +import type { zAmbiente } from "../ts/ambiente" import { urlAutenticacao } from "./_urlAutenticacao" export type tipoUsuarioExterno = { @@ -15,7 +17,7 @@ export const usuarios_quipo_governo = async ({ ambiente, buscar, }: { - ambiente: "desenvolvimento" | "producao" + ambiente: z.infer token_produto: string buscar: ( url: string, diff --git a/src/autenticacao/_validarToken.ts b/src/autenticacao/_validarToken.ts index b77eb2c..f35ab87 100644 --- a/src/autenticacao/_validarToken.ts +++ b/src/autenticacao/_validarToken.ts @@ -1,6 +1,8 @@ import type { tipoResposta } from "p-respostas" import { urlAutenticacao } from "./_urlAutenticacao" type tipoPostValidarTokem = { token: string } +import type { z } from "zod" +import type { zAmbiente } from "../ts/ambiente" /** faz a validação do token */ export const validarToken = async ({ @@ -8,7 +10,7 @@ export const validarToken = async ({ post, buscar, }: { - ambiente: "desenvolvimento" | "producao" + ambiente: z.infer post: tipoPostValidarTokem /** função que conecta com a API */ buscar: ( diff --git a/src/index.ts b/src/index.ts index 6b3c250..8025858 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ export * from "./tokenQuipo" export * from "./autenticacao" export * from "./produtos" +export * from "./pilao-de-dados" diff --git a/src/pilao-de-dados/_variaveis.ts b/src/pilao-de-dados/_variaveis.ts new file mode 100644 index 0000000..7e384c1 --- /dev/null +++ b/src/pilao-de-dados/_variaveis.ts @@ -0,0 +1,43 @@ +import { respostaComuns } from "p-respostas" +import { z } from "zod" + +export const zAmbiente = z.enum(["desenvolvimento", "producao"]) + +export const PREFIXO = "/pilao-de-dados" + +export const validarZ = ( + zodType: z.ZodType, + objeto: any, + mensagem: string, +) => { + const validar = zodType.safeParse(objeto) + if (!validar.success) { + debugger + return respostaComuns.erro( + mensagem, + validar.error.errors.map((e) => `${e.path} ${e.message}`), + ) + } + return respostaComuns.valor(validar.data) +} + +export const zp_produto_conta = z.object({ + produto: z.string(), + conta: z.string(), +}) + +export const tiposColunas = z.enum([ + "texto", + "numero", + "confirmacao", + "lista_texto", + "lista_numero", +]) + +export const validarColuna = { + texto: z.string().nullable(), + numero: z.number().nullable(), + confirmacao: z.boolean().nullable(), + lista_texto: z.array(z.string()).nullable(), + lista_numero: z.array(z.number()).nullable(), +} diff --git a/src/pilao-de-dados/consultar_serie.ts b/src/pilao-de-dados/consultar_serie.ts new file mode 100644 index 0000000..ef92b15 --- /dev/null +++ b/src/pilao-de-dados/consultar_serie.ts @@ -0,0 +1,75 @@ +import type { tipoResposta } from "p-respostas" +import { respostaComuns } from "p-respostas" +import { z } from "zod" +import { PREFIXO, type zp_produto_conta } from "./_variaveis" +import type { zp_registrar_serie } from "./registrar_serie" + +//consultar compilação + +export const zp_consultar_serie = z.object({ + identificador: z.string(), +}) + +export const consultar_serie = ({ + emDesenvolvimento, + parametros: { identificador }, + cliente: { conta, produto }, +}: { + emDesenvolvimento?: boolean | undefined | null + + /** Identificação do cliente */ + cliente: z.infer + parametros: z.infer +}) => { + const dados = async (): Promise< + tipoResposta<{ + registros: any[] + legenda: string + serie: z.infer + }> + > => { + const url = new URL( + `${ + emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one" + }${`${PREFIXO}/consultar-serie/${produto}/${conta}`}`, + ) + + const resp = await fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => + respostaComuns.erro("Erro ao enviar registros", [e.message]), + ) + .then((r) => r as tipoResposta) + + return resp + } + + const url = (): string => { + const vUrl = new URL( + `${ + emDesenvolvimento + ? "http://127.0.0.1:5081" + : "https://carro-de-boi.idz.one" + }${PREFIXO}/grafico`, + ) + + vUrl.searchParams.append("produto", produto) + vUrl.searchParams.append("conta", conta) + vUrl.searchParams.append("identificador", identificador) + + return vUrl.href + } + + return { + dados, + url, + } +} diff --git a/src/pilao-de-dados/enviar_registros.ts b/src/pilao-de-dados/enviar_registros.ts new file mode 100644 index 0000000..6a97d02 --- /dev/null +++ b/src/pilao-de-dados/enviar_registros.ts @@ -0,0 +1,43 @@ +import type { tipoResposta } from "p-respostas" +import { respostaComuns } from "p-respostas" +import { z } from "zod" +import { PREFIXO, type zp_produto_conta } from "./_variaveis" + +//enviar registros para base de dados +export const zp_enviar_registros = z.object({ + tabela: z.string(), + registros: z.array(z.any()), +}) + +export const enviar_registros = async ({ + emDesenvolvimento, + cliente: { conta, produto }, + parametros: { registros, tabela }, +}: { + emDesenvolvimento?: boolean | undefined | null + + /** Identificação do cliente */ + cliente: z.infer + /** Parametros da função */ + + parametros: z.infer +}): Promise> => { + const url = new URL( + `${ + emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one" + }${PREFIXO}/enviar-registro/${produto}/${conta}`, + ) + + const resp = await fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela, registros }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r as tipoResposta) + + return resp +} diff --git a/src/pilao-de-dados/index.ts b/src/pilao-de-dados/index.ts new file mode 100644 index 0000000..9e5ff26 --- /dev/null +++ b/src/pilao-de-dados/index.ts @@ -0,0 +1,27 @@ +import { tiposColunas, validarZ, zp_produto_conta } from "./_variaveis" +import { consultar_serie, zp_consultar_serie } from "./consultar_serie" +import { enviar_registros, zp_enviar_registros } from "./enviar_registros" +import { + registrar_base_dados, + zp_registrar_base_dados, +} from "./registrar_base_dados" +import { registrar_serie, zp_registrar_serie } from "./registrar_serie" + +export { tiposColunas } + +export const pPilao = { + registrar_base_dados, + zp_registrar_base_dados, + + enviar_registros, + zp_enviar_registros, + + registrar_serie, + zp_registrar_serie, + + consultar_serie, + zp_consultar_serie, + + zp_produto_conta, + validarZ, +} diff --git a/src/pilao-de-dados/registrar_base_dados.ts b/src/pilao-de-dados/registrar_base_dados.ts new file mode 100644 index 0000000..af55edf --- /dev/null +++ b/src/pilao-de-dados/registrar_base_dados.ts @@ -0,0 +1,47 @@ +import type { tipoResposta } from "p-respostas" +import { respostaComuns } from "p-respostas" +import { z } from "zod" +import { PREFIXO, tiposColunas, type zp_produto_conta } from "./_variaveis" + +/** Faz o registro de uma nova base de dados configurado a estrutura de colunas */ + +export const zp_registrar_base_dados = z.object({ + tabela: z.string(), + colunas: z.array( + z.object({ + coluna: z.string(), + tipo: tiposColunas, + }), + ), +}) + +export const registrar_base_dados = async ({ + emDesenvolvimento, + cliente: { conta, produto }, + parametros: { colunas, tabela }, +}: { + emDesenvolvimento?: boolean | undefined | null + /** Identificação do cliente */ + cliente: z.infer + /** parametros da função */ + parametros: z.infer +}): Promise> => { + const url = new URL( + `${ + emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one" + }${`${PREFIXO}/registar-base-dados/${produto}/${conta}`}`, + ) + + const resp = await fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ tabela, colunas }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r as tipoResposta) + + return resp +} diff --git a/src/pilao-de-dados/registrar_serie.ts b/src/pilao-de-dados/registrar_serie.ts new file mode 100644 index 0000000..76087db --- /dev/null +++ b/src/pilao-de-dados/registrar_serie.ts @@ -0,0 +1,59 @@ +import { respostaComuns, type tipoResposta } from "p-respostas" +import { z } from "zod" + +import { PREFIXO, type zp_produto_conta } from "./_variaveis" + +//registrar serie + +export const zp_registrar_serie = z.object({ + tabela: z.string(), + identificador: z.string(), + colanuEixoX: z.string(), + colunaAgrupamento: z.string(), + agregacao: z.enum(["contagem"]), +}) + +export const registrar_serie = async ({ + emDesenvolvimento, + cliente: { conta, produto }, + parametros: { + agregacao, + colanuEixoX, + colunaAgrupamento, + identificador, + tabela, + }, +}: { + emDesenvolvimento?: boolean | undefined | null + + /** Identificação do cliente */ + cliente: z.infer + /** Parametros da função */ + parametros: z.infer +}): Promise> => { + const url = new URL( + `${ + emDesenvolvimento + ? "http://127.0.0.1:5080" + : "https://carro-de-boi.idz.one" + }${`${PREFIXO}/registar-serie/${produto}/${conta}`}`, + ) + + const resp = await fetch(url.toString(), { + method: "POST", + body: JSON.stringify({ + tabela, + agregacao, + emDesenvolvimento, + colanuEixoX, + colunaAgrupamento, + identificador, + }), + headers: { "Content-Type": "application/json" }, + }) + .then((r) => r.json()) + .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])) + .then((r) => r as tipoResposta) + + return resp +} diff --git a/src/ts/ambiente.ts b/src/ts/ambiente.ts new file mode 100644 index 0000000..099d091 --- /dev/null +++ b/src/ts/ambiente.ts @@ -0,0 +1,3 @@ +import { z } from "zod" + +export const zAmbiente = z.enum(["desenvolvimento", "producao"])