implementado drive pilão de dados

This commit is contained in:
Luiz H. R. Silva 2024-06-14 12:30:08 -03:00
parent a1e543cfb8
commit daae40f4b2
54 changed files with 1476 additions and 19 deletions

View file

@ -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<typeof zAmbiente>;
post: tipoPostCodigoContaSite;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostCodigoContaSite) => Promise<tipoResposta<string>>;

View file

@ -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<typeof zAmbiente>) => string;

View file

@ -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<typeof zAmbiente>;
token_produto: string;
buscar: (url: string, headers: {
[k: string]: string;

View file

@ -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<typeof zAmbiente>;
post: tipoPostValidarTokem;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostValidarTokem) => Promise<tipoResposta<any>>;

View file

@ -1,3 +1,4 @@
export * from "./tokenQuipo";
export * from "./autenticacao";
export * from "./produtos";
export * from "./pilao-de-dados";

View file

@ -1,3 +1,4 @@
export * from "./tokenQuipo";
export * from "./autenticacao";
export * from "./produtos";
export * from "./pilao-de-dados";

View file

@ -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: <T>(zodType: z.ZodType<T, any, T>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
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<z.ZodString>;
numero: z.ZodNullable<z.ZodNumber>;
confirmacao: z.ZodNullable<z.ZodBoolean>;
lista_texto: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
lista_numero: z.ZodNullable<z.ZodArray<z.ZodNumber, "many">>;
};

View file

@ -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(),
};

View file

@ -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<typeof zp_produto_conta>;
parametros: z.infer<typeof zp_consultar_serie>;
}) => {
dados: () => Promise<tipoResposta<{
registros: any[];
legenda: string;
serie: z.infer<typeof zp_registrar_serie>;
}>>;
url: () => string;
};

View file

@ -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,
};
};

View file

@ -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<z.ZodAny, "many">;
}, "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<typeof zp_produto_conta>;
/** Parametros da função */
parametros: z.infer<typeof zp_enviar_registros>;
}) => Promise<tipoResposta<true>>;

View file

@ -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;
});

138
dist-import/pilao-de-dados/index.d.ts vendored Normal file
View file

@ -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<import("p-respostas").tipoResposta<true>>;
zp_registrar_base_dados: import("zod").ZodObject<{
tabela: import("zod").ZodString;
colunas: import("zod").ZodArray<import("zod").ZodObject<{
coluna: import("zod").ZodString;
tipo: import("zod").ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero"]>;
}, "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<import("p-respostas").tipoResposta<true>>;
zp_enviar_registros: import("zod").ZodObject<{
tabela: import("zod").ZodString;
registros: import("zod").ZodArray<import("zod").ZodAny, "many">;
}, "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<import("p-respostas").tipoResposta<true>>;
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<import("p-respostas").tipoResposta<{
registros: any[];
legenda: string;
serie: {
tabela: string;
identificador: string;
colanuEixoX: string;
colunaAgrupamento: string;
agregacao: "contagem";
};
}>>;
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: <T>(zodType: import("zod").ZodType<T, any, T>, objeto: any, mensagem: string) => import("p-respostas").tipoRespostaErro | import("p-respostas").tipoRespostaSucesso<T>;
};

View file

@ -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,
};

View file

@ -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<z.ZodObject<{
coluna: z.ZodString;
tipo: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero"]>;
}, "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<typeof zp_produto_conta>;
/** parametros da função */
parametros: z.infer<typeof zp_registrar_base_dados>;
}) => Promise<tipoResposta<true>>;

View file

@ -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;
});

View file

@ -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<typeof zp_produto_conta>;
/** Parametros da função */
parametros: z.infer<typeof zp_registrar_serie>;
}) => Promise<tipoResposta<true>>;

View file

@ -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;
});

2
dist-import/ts/ambiente.d.ts vendored Normal file
View file

@ -0,0 +1,2 @@
import { z } from "zod";
export declare const zAmbiente: z.ZodEnum<["desenvolvimento", "producao"]>;

View file

@ -0,0 +1,2 @@
import { z } from "zod";
export const zAmbiente = z.enum(["desenvolvimento", "producao"]);