inciado filtro 26

This commit is contained in:
Luiz Silva 2026-02-17 08:38:20 -03:00
parent 92300c8e3b
commit fa8b8d6424
8 changed files with 221 additions and 19 deletions

View file

@ -31,6 +31,7 @@ __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);
__reExport(index_exports, require("./tipagemRotas"), module.exports); __reExport(index_exports, require("./tipagemRotas"), module.exports);
__reExport(index_exports, require("./tipagemRotas"), module.exports); __reExport(index_exports, require("./tipagemRotas"), module.exports);
__reExport(index_exports, require("./tipoFiltro.26"), module.exports);
__reExport(index_exports, require("./unidades_medida"), module.exports); __reExport(index_exports, require("./unidades_medida"), module.exports);
__reExport(index_exports, require("./uuid"), module.exports); __reExport(index_exports, require("./uuid"), module.exports);
__reExport(index_exports, require("./variaveisComuns"), module.exports); __reExport(index_exports, require("./variaveisComuns"), module.exports);
@ -52,6 +53,7 @@ __reExport(index_exports, require("./variaveisComuns"), module.exports);
...require("./texto_busca"), ...require("./texto_busca"),
...require("./tipagemRotas"), ...require("./tipagemRotas"),
...require("./tipagemRotas"), ...require("./tipagemRotas"),
...require("./tipoFiltro.26"),
...require("./unidades_medida"), ...require("./unidades_medida"),
...require("./uuid"), ...require("./uuid"),
...require("./variaveisComuns") ...require("./variaveisComuns")

View file

@ -0,0 +1,49 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tipoFiltro_26_exports = {};
__export(tipoFiltro_26_exports, {
zFiltro26: () => zFiltro26
});
module.exports = __toCommonJS(tipoFiltro_26_exports);
var import_zod = require("zod");
const zOperadores = import_zod.z.enum(["=", "!=", ">", ">=", "<", "<=", "like", "in"]);
const zValor = import_zod.z.any();
const zCondicao = import_zod.z.record(zOperadores, zValor);
const zFiltro26 = import_zod.z.lazy(
() => import_zod.z.object({
E: import_zod.z.array(zFiltro26).optional(),
OU: import_zod.z.array(zFiltro26).optional()
}).catchall(import_zod.z.union([zCondicao, zFiltro26]))
);
const _filtro = {
idade: { ">=": 18 },
OU: [
{ nome: { like: "%pa%" } },
{
E: [
{ carro: { ano: { "=": 2020 } } },
{ carro: { modelo: { in: ["Civic", "Corolla"] } } }
]
}
]
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
zFiltro26
});

View file

@ -1,4 +1,4 @@
import z from 'zod'; import z, { z as z$1 } from 'zod';
export { Dayjs, ManipulateType, default as dayjsbr } from 'dayjs'; export { Dayjs, ManipulateType, default as dayjsbr } from 'dayjs';
export { default as duration } from 'dayjs/plugin/duration'; export { default as duration } from 'dayjs/plugin/duration';
export { default as isSameOrAfter } from 'dayjs/plugin/isSameOrAfter'; export { default as isSameOrAfter } from 'dayjs/plugin/isSameOrAfter';
@ -259,6 +259,141 @@ declare class TipagemRotas<T extends {
parametros(urlEntrada?: string): Partial<T>; parametros(urlEntrada?: string): Partial<T>;
} }
/**
* =============================================================================
* tipoFiltro26<T>
* =============================================================================
*
* OBJETIVO
* -----------------------------------------------------------------------------
* Gerar automaticamente a tipagem de filtros compatíveis com operadores
* padrão do PostgreSQL, a partir de um tipo base T.
*
* Este tipo foi projetado para:
* - Construção de filtros dinâmicos
* - Geração posterior de WHERE (Knex / SQL)
* - Uso seguro por IA (evita filtros inválidos em nível de tipo)
*
*
* FORMATO DO FILTRO
* -----------------------------------------------------------------------------
* 1) Campos simples:
*
* {
* idade: { ">=": 18 }
* }
*
* 2) Campos aninhados:
*
* {
* carro: {
* ano: { "=": 2020 }
* }
* }
*
* 3) Operador E (AND):
*
* {
* E: [
* { idade: { ">=": 18 } },
* { nome: { like: "%pa%" } }
* ]
* }
*
* 4) Operador OU (OR):
*
* {
* OU: [
* { idade: { "<": 18 } },
* { idade: { ">=": 60 } }
* ]
* }
*
* 5) Combinação complexa:
*
* {
* idade: { ">=": 18 },
* OU: [
* { nome: { like: "%pa%" } },
* {
* E: [
* { carro: { ano: { "=": 2020 } } },
* { carro: { modelo: { in: ["Civic"] } } }
* ]
* }
* ]
* }
*
*
* REGRAS IMPORTANTES (PARA IA)
* -----------------------------------------------------------------------------
* - Apenas campos existentes em T podem ser usados.
* - Operadores são restritos por tipo do campo.
* - Objetos são tratados recursivamente.
* - Arrays NÃO são tratados como objeto recursivo.
* - Funções NÃO são consideradas campos filtráveis.
*
*
* OPERADORES SUPORTADOS
* -----------------------------------------------------------------------------
* number:
* =, !=, >, >=, <, <=, in
*
* string:
* =, !=, like, in
*
* boolean:
* =, !=, in
*
* Não suporte automático a:
* - null
* - date
* - jsonb
* - arrays
*
* Essas extensões devem ser adicionadas explicitamente.
*
* =============================================================================
*/
type PgOpsNumber = {
"="?: number;
"!="?: number;
">"?: number;
">="?: number;
"<"?: number;
"<="?: number;
in?: number[];
};
type PgOpsString = {
"="?: string;
"!="?: string;
like?: string;
in?: string[];
};
type PgOpsBoolean = {
"="?: boolean;
"!="?: boolean;
in?: boolean[];
};
type PgOpsFor<V> = V extends number ? PgOpsNumber : V extends string ? PgOpsString : V extends boolean ? PgOpsBoolean : never;
type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends readonly any[] ? false : true : false;
type FiltroCampos<T> = {
[K in keyof T]?: IsPlainObject<T[K]> extends true ? tipoFiltro26<T[K]> : PgOpsFor<T[K]>;
};
type tipoFiltro26<T> = FiltroCampos<T> & {
/**
* E => AND lógico
* Todos os filtros dentro do array devem ser verdadeiros.
*/
E?: tipoFiltro26<T>[];
/**
* OU => OR lógico
* Pelo menos um filtro dentro do array deve ser verdadeiro.
*/
OU?: tipoFiltro26<T>[];
};
declare const zFiltro26: z$1.ZodType<any>;
/** /**
* Essa variável se conecta a tabela_lidades * Essa variável se conecta a tabela_lidades
* *
@ -327,4 +462,4 @@ declare const nomeVariavel: (v: {
[key: string]: any; [key: string]: any;
}) => string; }) => string;
export { Produtos, TipagemRotas, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, erUuid, esperar, extensoes, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zOperadores }; export { Produtos, TipagemRotas, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, erUuid, esperar, extensoes, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoFiltro26, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zFiltro26, zOperadores };

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "p-comuns", "name": "p-comuns",
"version": "0.304.0", "version": "0.307.0",
"description": "", "description": "",
"main": "./dist-front/index.mjs", "main": "./dist-front/index.mjs",
"module": "./dist-front/index.mjs", "module": "./dist-front/index.mjs",

Binary file not shown.

View file

@ -14,6 +14,7 @@ export * from "./testes-de-variaveis"
export * from "./texto_busca" export * from "./texto_busca"
export * from "./tipagemRotas" export * from "./tipagemRotas"
export * from "./tipagemRotas" export * from "./tipagemRotas"
export * from "./tipoFiltro.26"
export * from "./unidades_medida" export * from "./unidades_medida"
export * from "./uuid" export * from "./uuid"
export * from "./variaveisComuns" export * from "./variaveisComuns"

View file

@ -1,3 +1,5 @@
import { z } from "zod"
/** /**
* ============================================================================= * =============================================================================
* tipoFiltro26<T> * tipoFiltro26<T>
@ -95,7 +97,6 @@
* ============================================================================= * =============================================================================
*/ */
/* ============================================================================= /* =============================================================================
OPERADORES POSTGRESQL POR TIPO OPERADORES POSTGRESQL POR TIPO
============================================================================= */ ============================================================================= */
@ -123,29 +124,29 @@ type PgOpsBoolean = {
in?: boolean[] in?: boolean[]
} }
/* ============================================================================= /* =============================================================================
SELEÇÃO AUTOMÁTICA DE OPERADORES BASEADA NO TIPO DO CAMPO SELEÇÃO AUTOMÁTICA DE OPERADORES BASEADA NO TIPO DO CAMPO
============================================================================= */ ============================================================================= */
type PgOpsFor<V> = type PgOpsFor<V> = V extends number
V extends number ? PgOpsNumber : ? PgOpsNumber
V extends string ? PgOpsString : : V extends string
V extends boolean ? PgOpsBoolean : ? PgOpsString
never : V extends boolean
? PgOpsBoolean
: never
/* ============================================================================= /* =============================================================================
UTILITÁRIO: DETECTAR OBJETO PLANO UTILITÁRIO: DETECTAR OBJETO PLANO
============================================================================= */ ============================================================================= */
type IsPlainObject<T> = type IsPlainObject<T> = T extends object
T extends object ? T extends Function
? T extends Function ? false ? false
: T extends readonly any[] ? false : T extends readonly any[]
? false
: true : true
: false : false
/* ============================================================================= /* =============================================================================
FILTRO RECURSIVO POR CAMPOS FILTRO RECURSIVO POR CAMPOS
@ -157,7 +158,6 @@ type FiltroCampos<T> = {
: PgOpsFor<T[K]> : PgOpsFor<T[K]>
} }
/* ============================================================================= /* =============================================================================
TIPO PRINCIPAL EXPORTADO TIPO PRINCIPAL EXPORTADO
============================================================================= */ ============================================================================= */
@ -176,7 +176,22 @@ export type tipoFiltro26<T> = FiltroCampos<T> & {
OU?: tipoFiltro26<T>[] OU?: tipoFiltro26<T>[]
} }
/* =============================================================================
VALIDAÇÃO ESTRUTURAL (ZOD)
============================================================================= */
const zOperadores = z.enum(["=", "!=", ">", ">=", "<", "<=", "like", "in"])
const zValor = z.any()
const zCondicao = z.record(zOperadores, zValor)
export const zFiltro26: z.ZodType<any> = z.lazy(() =>
z
.object({
E: z.array(zFiltro26).optional(),
OU: z.array(zFiltro26).optional(),
})
.catchall(z.union([zCondicao, zFiltro26])),
)
/* ============================================================================= /* =============================================================================
EXEMPLO DE USO EXEMPLO DE USO