inciado filtro 26
This commit is contained in:
parent
92300c8e3b
commit
fa8b8d6424
8 changed files with 221 additions and 19 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { z } from "zod"
|
||||
|
||||
/**
|
||||
* =============================================================================
|
||||
* tipoFiltro26<T>
|
||||
|
|
@ -95,7 +97,6 @@
|
|||
* =============================================================================
|
||||
*/
|
||||
|
||||
|
||||
/* =============================================================================
|
||||
OPERADORES POSTGRESQL POR TIPO
|
||||
============================================================================= */
|
||||
|
|
@ -123,29 +124,29 @@ type PgOpsBoolean = {
|
|||
in?: boolean[]
|
||||
}
|
||||
|
||||
|
||||
/* =============================================================================
|
||||
SELEÇÃO AUTOMÁTICA DE OPERADORES BASEADA NO TIPO DO CAMPO
|
||||
============================================================================= */
|
||||
|
||||
type PgOpsFor<V> =
|
||||
V extends number ? PgOpsNumber :
|
||||
V extends string ? PgOpsString :
|
||||
V extends boolean ? PgOpsBoolean :
|
||||
never
|
||||
|
||||
type PgOpsFor<V> = V extends number
|
||||
? PgOpsNumber
|
||||
: V extends string
|
||||
? PgOpsString
|
||||
: V extends boolean
|
||||
? PgOpsBoolean
|
||||
: never
|
||||
|
||||
/* =============================================================================
|
||||
UTILITÁRIO: DETECTAR OBJETO PLANO
|
||||
============================================================================= */
|
||||
|
||||
type IsPlainObject<T> =
|
||||
T extends object
|
||||
? T extends Function ? false
|
||||
: T extends readonly any[] ? false
|
||||
type IsPlainObject<T> = T extends object
|
||||
? T extends Function
|
||||
? false
|
||||
: T extends readonly any[]
|
||||
? false
|
||||
: true
|
||||
: false
|
||||
|
||||
: false
|
||||
|
||||
/* =============================================================================
|
||||
FILTRO RECURSIVO POR CAMPOS
|
||||
|
|
@ -157,7 +158,6 @@ type FiltroCampos<T> = {
|
|||
: PgOpsFor<T[K]>
|
||||
}
|
||||
|
||||
|
||||
/* =============================================================================
|
||||
TIPO PRINCIPAL EXPORTADO
|
||||
============================================================================= */
|
||||
|
|
@ -176,7 +176,22 @@ export type tipoFiltro26<T> = FiltroCampos<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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue