buid
This commit is contained in:
parent
0cbe901499
commit
dbe0f66daf
51 changed files with 30 additions and 304 deletions
0
src/aleatorio.ts
Normal file → Executable file
0
src/aleatorio.ts
Normal file → Executable file
0
src/cacheMemoria.ts
Normal file → Executable file
0
src/cacheMemoria.ts
Normal file → Executable file
0
src/constantes.ts
Normal file → Executable file
0
src/constantes.ts
Normal file → Executable file
0
src/consulta.ts
Normal file → Executable file
0
src/consulta.ts
Normal file → Executable file
0
src/dayjs.ts
Normal file → Executable file
0
src/dayjs.ts
Normal file → Executable file
0
src/ecosistema/index.ts
Normal file → Executable file
0
src/ecosistema/index.ts
Normal file → Executable file
0
src/ecosistema/urls.ts
Normal file → Executable file
0
src/ecosistema/urls.ts
Normal file → Executable file
0
src/extensoes.ts
Normal file → Executable file
0
src/extensoes.ts
Normal file → Executable file
0
src/graficosPilao.ts
Normal file → Executable file
0
src/graficosPilao.ts
Normal file → Executable file
2
src/index.ts
Normal file → Executable file
2
src/index.ts
Normal file → Executable file
|
|
@ -8,8 +8,6 @@ export * from "./extensoes"
|
|||
export * from "./extensoes"
|
||||
export * from "./graficosPilao"
|
||||
export * from "./local"
|
||||
export * from "./logger"
|
||||
export * from "./logger"
|
||||
export * from "./postgres"
|
||||
export * from "./testes-de-variaveis"
|
||||
export * from "./texto_busca"
|
||||
|
|
|
|||
0
src/instalarAmbiente.ts
Normal file → Executable file
0
src/instalarAmbiente.ts
Normal file → Executable file
4
src/local/index.ts
Normal file → Executable file
4
src/local/index.ts
Normal file → Executable file
|
|
@ -6,8 +6,8 @@ export const localValor = <T>(
|
|||
chave_: string | any,
|
||||
valor?: T | null,
|
||||
): T | null => {
|
||||
const localStorage = globalThis.localStorage
|
||||
|
||||
const localStorage =
|
||||
"localStorage" in globalThis ? (globalThis as any).localStorage : undefined
|
||||
if (typeof localStorage == "undefined") return null
|
||||
|
||||
const chave =
|
||||
|
|
|
|||
126
src/logger.ts
126
src/logger.ts
|
|
@ -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
0
src/postgres.ts
Normal file → Executable file
0
src/teste.ts
Normal file → Executable file
0
src/teste.ts
Normal file → Executable file
0
src/testes-de-variaveis/index.ts
Normal file → Executable file
0
src/testes-de-variaveis/index.ts
Normal file → Executable file
0
src/testes-de-variaveis/umaFuncao.ts
Normal file → Executable file
0
src/testes-de-variaveis/umaFuncao.ts
Normal file → Executable file
0
src/testes-de-variaveis/umaVariavel.ts
Normal file → Executable file
0
src/testes-de-variaveis/umaVariavel.ts
Normal file → Executable file
0
src/testes/TipagemRotas.test.ts
Normal file → Executable file
0
src/testes/TipagemRotas.test.ts
Normal file → Executable file
0
src/texto_busca.ts
Normal file → Executable file
0
src/texto_busca.ts
Normal file → Executable file
18
src/tipagemRotas.ts
Normal file → Executable file
18
src/tipagemRotas.ts
Normal file → Executable file
|
|
@ -63,9 +63,10 @@ export class TipagemRotas<T extends { [q: string]: any }> {
|
|||
*/
|
||||
|
||||
endereco(query: T, usarComoHash?: boolean) {
|
||||
const url = new URL(
|
||||
typeof window !== "undefined" ? window.location.href : "http://localhost",
|
||||
)
|
||||
const win =
|
||||
(typeof globalThis !== "undefined" && (globalThis as any).window) ||
|
||||
undefined
|
||||
const url = new URL(win ? win.location.href : "http://localhost")
|
||||
|
||||
url.pathname = this.caminho
|
||||
|
||||
|
|
@ -95,8 +96,11 @@ export class TipagemRotas<T extends { [q: string]: any }> {
|
|||
if (this._acaoIr) {
|
||||
this._acaoIr(this.endereco({ ...query }))
|
||||
} else {
|
||||
if (typeof window != "undefined") {
|
||||
window.location.href = this.endereco({ ...query })
|
||||
const win =
|
||||
(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
|
||||
? new URL(urlEntrada)
|
||||
: new URL(
|
||||
typeof window !== "undefined"
|
||||
? window.location.href
|
||||
typeof globalThis !== "undefined" && (globalThis as any).window
|
||||
? (globalThis as any).window.location.href
|
||||
: "http://localhost",
|
||||
)
|
||||
const query = url.searchParams
|
||||
|
|
|
|||
0
src/unidades_medida.ts
Normal file → Executable file
0
src/unidades_medida.ts
Normal file → Executable file
0
src/uuid.ts
Normal file → Executable file
0
src/uuid.ts
Normal file → Executable file
0
src/variaveisComuns.ts
Normal file → Executable file
0
src/variaveisComuns.ts
Normal file → Executable file
Loading…
Add table
Add a link
Reference in a new issue