This commit is contained in:
Luiz Silva 2026-02-08 20:30:35 -03:00
parent 0cbe901499
commit dbe0f66daf
51 changed files with 30 additions and 304 deletions

0
.gitignore vendored Normal file → Executable file
View file

0
.npmignore Normal file → Executable file
View file

0
.npmrc Normal file → Executable file
View file

0
.vscode/settings.json vendored Normal file → Executable file
View file

0
Documentos/biome.json Normal file → Executable file
View file

0
README.md Normal file → Executable file
View file

0
biome.json Normal file → Executable file
View file

0
build.config.ts Normal file → Executable file
View file

View file

@ -25,8 +25,6 @@ __reExport(index_exports, require("./extensoes"), module.exports);
__reExport(index_exports, require("./extensoes"), module.exports); __reExport(index_exports, require("./extensoes"), module.exports);
__reExport(index_exports, require("./graficosPilao"), module.exports); __reExport(index_exports, require("./graficosPilao"), module.exports);
__reExport(index_exports, require("./local"), module.exports); __reExport(index_exports, require("./local"), module.exports);
__reExport(index_exports, require("./logger"), module.exports);
__reExport(index_exports, require("./logger"), module.exports);
__reExport(index_exports, require("./postgres"), module.exports); __reExport(index_exports, require("./postgres"), module.exports);
__reExport(index_exports, require("./testes-de-variaveis"), module.exports); __reExport(index_exports, require("./testes-de-variaveis"), module.exports);
__reExport(index_exports, require("./texto_busca"), module.exports); __reExport(index_exports, require("./texto_busca"), module.exports);
@ -47,8 +45,6 @@ __reExport(index_exports, require("./variaveisComuns"), module.exports);
...require("./extensoes"), ...require("./extensoes"),
...require("./graficosPilao"), ...require("./graficosPilao"),
...require("./local"), ...require("./local"),
...require("./logger"),
...require("./logger"),
...require("./postgres"), ...require("./postgres"),
...require("./testes-de-variaveis"), ...require("./testes-de-variaveis"),
...require("./texto_busca"), ...require("./texto_busca"),

View file

@ -22,7 +22,7 @@ __export(local_exports, {
}); });
module.exports = __toCommonJS(local_exports); module.exports = __toCommonJS(local_exports);
const localValor = (chave_, valor) => { const localValor = (chave_, valor) => {
const localStorage = globalThis.localStorage; const localStorage = "localStorage" in globalThis ? globalThis.localStorage : void 0;
if (typeof localStorage == "undefined") return null; if (typeof localStorage == "undefined") return null;
const chave = typeof chave_ === "string" ? chave_ : encodeURIComponent(JSON.stringify(chave_)); const chave = typeof chave_ === "string" ? chave_ : encodeURIComponent(JSON.stringify(chave_));
try { try {

View file

@ -1,106 +0,0 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var logger_exports = {};
__export(logger_exports, {
defineCwd: () => defineCwd,
logger: () => logger,
postLogger: () => postLogger
});
module.exports = __toCommonJS(logger_exports);
var import_cross_fetch = __toESM(require("cross-fetch"));
var import_variaveisComuns = require("./variaveisComuns");
const LOKI_BASE_URL = "https://log.idz.one";
const LOKI_ENDPOINT = "/loki/api/v1/push";
const postLogger = async ({
objeto
}) => {
const response = await (0, import_cross_fetch.default)(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(objeto)
}).catch((a) => a);
if (!response.ok) {
return [objeto, `Erro ${response.status}: ${await response?.text?.()}`];
}
return [objeto];
};
let cwd = "";
const defineCwd = (novoCwd) => {
cwd = novoCwd;
};
const logger = ({ app: app_e, eProducao, parametros: parametrosAmbiente }) => ({ inquilino, usuario, parametros: parametrosSessao }) => async (level, mensagem, op_tipoLog) => {
let {
__filename,
detalhes,
local,
parametros: parametrosLog
} = op_tipoLog || {};
const app = `${eProducao ? "" : "DEV-"}${app_e}`;
if (cwd && __filename) {
__filename = __filename.replace(cwd, "");
}
if (local) {
detalhes = [`${(0, import_variaveisComuns.nomeVariavel)({ local })}="${local}"`, ...detalhes || []];
}
if (__filename) {
detalhes = [
`${(0, import_variaveisComuns.nomeVariavel)({ __filename })}="${__filename}"`,
...detalhes || []
];
}
const timestamp = `${Date.now()}000000`;
const mainLog = detalhes?.length ? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" | ")}` : mensagem;
const payload = {
stream: {
app,
inquilino,
usuario,
level,
...parametrosAmbiente || {},
...parametrosSessao || {},
...parametrosLog || {}
},
values: [
[
timestamp,
mainLog
// Linha de log direta
]
]
};
const objeto = { streams: [payload] };
const response = await postLogger({ objeto });
return response;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defineCwd,
logger,
postLogger
});

View file

@ -56,9 +56,8 @@ class TipagemRotas {
** "http://localhost:3000/caminho?q=query" ** "http://localhost:3000/caminho?q=query"
*/ */
endereco(query, usarComoHash) { endereco(query, usarComoHash) {
const url = new URL( const win = typeof globalThis !== "undefined" && globalThis.window || void 0;
typeof window !== "undefined" ? window.location.href : "http://localhost" const url = new URL(win ? win.location.href : "http://localhost");
);
url.pathname = this.caminho; url.pathname = this.caminho;
url.search = ""; url.search = "";
const queryKeys = Object.entries(query); const queryKeys = Object.entries(query);
@ -80,8 +79,9 @@ class TipagemRotas {
if (this._acaoIr) { if (this._acaoIr) {
this._acaoIr(this.endereco({ ...query })); this._acaoIr(this.endereco({ ...query }));
} else { } else {
if (typeof window != "undefined") { const win = typeof globalThis !== "undefined" && globalThis.window || void 0;
window.location.href = this.endereco({ ...query }); if (win) {
win.location.href = this.endereco({ ...query });
} }
} }
} }
@ -91,7 +91,7 @@ class TipagemRotas {
*/ */
parametros(urlEntrada) { parametros(urlEntrada) {
const url = urlEntrada ? new URL(urlEntrada) : new URL( const url = urlEntrada ? new URL(urlEntrada) : new URL(
typeof window !== "undefined" ? window.location.href : "http://localhost" typeof globalThis !== "undefined" && globalThis.window ? globalThis.window.location.href : "http://localhost"
); );
const query = url.searchParams; const query = url.searchParams;
let queryObj = Object.fromEntries(query.entries()); let queryObj = Object.fromEntries(query.entries());

View file

@ -120,46 +120,6 @@ declare const graficos_pilao: {
*/ */
declare const localValor: <T>(chave_: string | any, valor?: T | null) => T | null; declare const localValor: <T>(chave_: string | any, valor?: T | null) => T | null;
type tipoLokiObjeto = {
streams: {
stream: {
[k: string]: string;
};
values: [string, string][];
}[];
};
declare const postLogger: ({ objeto, }: {
objeto: tipoLokiObjeto;
}) => Promise<[objeto: tipoLokiObjeto, erro?: string]>;
/** define a localização da pasta do projeto */
declare const defineCwd: (novoCwd: string) => void;
type tipoLevel = "info" | "warn" | "error";
type tipoOpSessao = {
inquilino: string;
usuario: string;
parametros?: {
[k: string]: string;
};
};
type tipoLog = {
detalhes?: unknown[];
__filename?: string;
local?: string;
parametros?: {
[k: string]: string;
};
};
type tipoLoggerLog = (level: tipoLevel, mensagem: string, op_tipoLog?: tipoLog) => Promise<[objeto: tipoLokiObjeto, erro?: string]>;
type TipoLoggerSessao = (sess: tipoOpSessao) => tipoLoggerLog;
type tipoLogger = (amb: {
app: string;
eProducao: boolean;
parametros?: {
[k: string]: string;
};
}) => TipoLoggerSessao;
declare const logger: tipoLogger;
/** /**
* Trata um objeto para ser imput para postgres * Trata um objeto para ser imput para postgres
* @param entrada * @param entrada
@ -311,4 +271,4 @@ declare const nomeVariavel: (v: {
[key: string]: any; [key: string]: any;
}) => string; }) => string;
export { TipagemRotas, type TipoLoggerSessao, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, cdn_carro_de_boi, dayjsbr, defineCwd, erUuid, esperar, extensoes, graficos_pilao, type interfaceConsulta, localValor, logger, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, postLogger, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoLogger, type tipoLoggerLog, type tipoLokiObjeto, tipoUsuarioResiduos, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zOperadores }; export { TipagemRotas, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, cdn_carro_de_boi, dayjsbr, erUuid, esperar, extensoes, graficos_pilao, type interfaceConsulta, localValor, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, tipoUsuarioResiduos, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zOperadores };

File diff suppressed because one or more lines are too long

6
package.json Normal file → Executable file
View file

@ -1,6 +1,6 @@
{ {
"name": "p-comuns", "name": "p-comuns",
"version": "0.292.0", "version": "0.297.0",
"description": "", "description": "",
"main": "./dist-front/index.mjs", "main": "./dist-front/index.mjs",
"module": "./dist-front/index.mjs", "module": "./dist-front/index.mjs",
@ -27,7 +27,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cross-fetch": "4.1.0", "cross-fetch": "4.1.0",
"dayjs": "^1.11.18", "dayjs": "1.11.13",
"uuid": "^11.1.0", "uuid": "^11.1.0",
"zod": "4.1.4" "zod": "4.1.4"
}, },
@ -41,7 +41,7 @@
}, },
"peerDependencies": { "peerDependencies": {
"cross-fetch": "4.1.0", "cross-fetch": "4.1.0",
"dayjs": "^1.11.18", "dayjs": "1.11.13",
"uuid": "^11.1.0", "uuid": "^11.1.0",
"zod": "4.1.4" "zod": "4.1.4"
} }

Binary file not shown.

10
pnpm-lock.yaml generated Normal file → Executable file
View file

@ -12,8 +12,8 @@ importers:
specifier: 4.1.0 specifier: 4.1.0
version: 4.1.0 version: 4.1.0
dayjs: dayjs:
specifier: ^1.11.18 specifier: 1.11.13
version: 1.11.18 version: 1.11.13
uuid: uuid:
specifier: ^11.1.0 specifier: ^11.1.0
version: 11.1.0 version: 11.1.0
@ -658,8 +658,8 @@ packages:
resolution: {integrity: sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==} resolution: {integrity: sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==}
engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'} engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'}
dayjs@1.11.18: dayjs@1.11.13:
resolution: {integrity: sha512-zFBQ7WFRvVRhKcWoUh+ZA1g2HVgUbsZm9sbddh8EC5iv93sui8DVVz1Npvz+r6meo9VKfa8NyLWBsQK1VvIKPA==} resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
debug@4.4.3: debug@4.4.3:
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
@ -1971,7 +1971,7 @@ snapshots:
dependencies: dependencies:
css-tree: 2.2.1 css-tree: 2.2.1
dayjs@1.11.18: {} dayjs@1.11.13: {}
debug@4.4.3: debug@4.4.3:
dependencies: dependencies:

0
requisicoes.rest Normal file → Executable file
View file

0
src/aleatorio.ts Normal file → Executable file
View file

0
src/cacheMemoria.ts Normal file → Executable file
View file

0
src/constantes.ts Normal file → Executable file
View file

0
src/consulta.ts Normal file → Executable file
View file

0
src/dayjs.ts Normal file → Executable file
View file

0
src/ecosistema/index.ts Normal file → Executable file
View file

0
src/ecosistema/urls.ts Normal file → Executable file
View file

0
src/extensoes.ts Normal file → Executable file
View file

0
src/graficosPilao.ts Normal file → Executable file
View file

2
src/index.ts Normal file → Executable file
View file

@ -8,8 +8,6 @@ export * from "./extensoes"
export * from "./extensoes" export * from "./extensoes"
export * from "./graficosPilao" export * from "./graficosPilao"
export * from "./local" export * from "./local"
export * from "./logger"
export * from "./logger"
export * from "./postgres" export * from "./postgres"
export * from "./testes-de-variaveis" export * from "./testes-de-variaveis"
export * from "./texto_busca" export * from "./texto_busca"

0
src/instalarAmbiente.ts Normal file → Executable file
View file

4
src/local/index.ts Normal file → Executable file
View file

@ -6,8 +6,8 @@ export const localValor = <T>(
chave_: string | any, chave_: string | any,
valor?: T | null, valor?: T | null,
): T | null => { ): T | null => {
const localStorage = globalThis.localStorage const localStorage =
"localStorage" in globalThis ? (globalThis as any).localStorage : undefined
if (typeof localStorage == "undefined") return null if (typeof localStorage == "undefined") return null
const chave = const chave =

View file

@ -1,126 +0,0 @@
import crossFetch from "cross-fetch"
import { nomeVariavel } from "./variaveisComuns"
const LOKI_BASE_URL = "https://log.idz.one"
const LOKI_ENDPOINT = "/loki/api/v1/push"
export type tipoLokiObjeto = {
streams: {
stream: {
[k: string]: string
}
values: [string, string][]
}[]
}
export const postLogger = async ({
objeto,
}: {
objeto: tipoLokiObjeto
}): Promise<[objeto: tipoLokiObjeto, erro?: string]> => {
const response = await crossFetch(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(objeto),
}).catch((a) => a)
if (!response.ok) {
return [objeto, `Erro ${response.status}: ${await response?.text?.()}`]
}
return [objeto]
}
let cwd = ""
/** define a localização da pasta do projeto */
export const defineCwd = (novoCwd: string) => {
cwd = novoCwd
}
type tipoLevel = "info" | "warn" | "error"
type tipoOpSessao = {
inquilino: string
usuario: string
parametros?: { [k: string]: string }
}
type tipoLog = {
detalhes?: unknown[]
__filename?: string
local?: string
parametros?: { [k: string]: string }
}
export type tipoLoggerLog = (
level: tipoLevel,
mensagem: string,
op_tipoLog?: tipoLog,
) => Promise<[objeto: tipoLokiObjeto, erro?: string]>
export type TipoLoggerSessao = (sess: tipoOpSessao) => tipoLoggerLog
export type tipoLogger = (amb: {
app: string
eProducao: boolean
parametros?: {
[k: string]: string
}
}) => TipoLoggerSessao
export const logger: tipoLogger =
({ app: app_e, eProducao, parametros: parametrosAmbiente }) =>
({ inquilino, usuario, parametros: parametrosSessao }) =>
async (level, mensagem, op_tipoLog) => {
let {
__filename,
detalhes,
local,
parametros: parametrosLog,
} = op_tipoLog || {}
const app = `${eProducao ? "" : "DEV-"}${app_e}`
if (cwd && __filename) {
__filename = __filename.replace(cwd, "")
}
if (local) {
detalhes = [`${nomeVariavel({ local })}="${local}"`, ...(detalhes || [])]
}
if (__filename) {
detalhes = [
`${nomeVariavel({ __filename })}="${__filename}"`,
...(detalhes || []),
]
}
const timestamp = `${Date.now()}000000`
const mainLog = detalhes?.length
? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" | ")}`
: mensagem
const payload: tipoLokiObjeto["streams"][number] = {
stream: {
app,
inquilino,
usuario,
level,
...(parametrosAmbiente || {}),
...(parametrosSessao || {}),
...(parametrosLog || {}),
},
values: [
[
timestamp,
mainLog, // Linha de log direta
],
],
}
const objeto: tipoLokiObjeto = { streams: [payload] }
const response = await postLogger({ objeto })
return response
}

0
src/postgres.ts Normal file → Executable file
View file

0
src/teste.ts Normal file → Executable file
View file

0
src/testes-de-variaveis/index.ts Normal file → Executable file
View file

0
src/testes-de-variaveis/umaFuncao.ts Normal file → Executable file
View file

0
src/testes-de-variaveis/umaVariavel.ts Normal file → Executable file
View file

0
src/testes/TipagemRotas.test.ts Normal file → Executable file
View file

0
src/texto_busca.ts Normal file → Executable file
View file

18
src/tipagemRotas.ts Normal file → Executable file
View file

@ -63,9 +63,10 @@ export class TipagemRotas<T extends { [q: string]: any }> {
*/ */
endereco(query: T, usarComoHash?: boolean) { endereco(query: T, usarComoHash?: boolean) {
const url = new URL( const win =
typeof window !== "undefined" ? window.location.href : "http://localhost", (typeof globalThis !== "undefined" && (globalThis as any).window) ||
) undefined
const url = new URL(win ? win.location.href : "http://localhost")
url.pathname = this.caminho url.pathname = this.caminho
@ -95,8 +96,11 @@ export class TipagemRotas<T extends { [q: string]: any }> {
if (this._acaoIr) { if (this._acaoIr) {
this._acaoIr(this.endereco({ ...query })) this._acaoIr(this.endereco({ ...query }))
} else { } else {
if (typeof window != "undefined") { const win =
window.location.href = this.endereco({ ...query }) (typeof globalThis !== "undefined" && (globalThis as any).window) ||
undefined
if (win) {
win.location.href = this.endereco({ ...query })
} }
} }
} }
@ -110,8 +114,8 @@ export class TipagemRotas<T extends { [q: string]: any }> {
const url = urlEntrada const url = urlEntrada
? new URL(urlEntrada) ? new URL(urlEntrada)
: new URL( : new URL(
typeof window !== "undefined" typeof globalThis !== "undefined" && (globalThis as any).window
? window.location.href ? (globalThis as any).window.location.href
: "http://localhost", : "http://localhost",
) )
const query = url.searchParams const query = url.searchParams

0
src/unidades_medida.ts Normal file → Executable file
View file

0
src/uuid.ts Normal file → Executable file
View file

0
src/variaveisComuns.ts Normal file → Executable file
View file

0
tsconfig-back.json Normal file → Executable file
View file

0
tsconfig-front.json Normal file → Executable file
View file

0
tsconfig.json Normal file → Executable file
View file

0
tsup/como usar.md Normal file → Executable file
View file

0
tsup/tsup.config.back.ts Normal file → Executable file
View file

0
tsup/tsup.config.front.interno.ts Normal file → Executable file
View file

0
tsup/tsup.config.front.ts Normal file → Executable file
View file

0
tsup/tsup.config.interno.ts Normal file → Executable file
View file

0
tsup/tsup.config.ts Normal file → Executable file
View file