remoção do filtro 26 por filtro delta
This commit is contained in:
parent
98a531dbd3
commit
b0b76562b7
12 changed files with 348 additions and 542 deletions
109
dist-back/filtroDelta.js
Normal file
109
dist-back/filtroDelta.js
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
"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 filtroDelta_exports = {};
|
||||
__export(filtroDelta_exports, {
|
||||
zColunaFiltroDelta: () => zColunaFiltroDelta,
|
||||
zCondicaoFiltroDelta: () => zCondicaoFiltroDelta,
|
||||
zFiltroDelta: () => zFiltroDelta,
|
||||
zOperadorFiltroDelta: () => zOperadorFiltroDelta
|
||||
});
|
||||
module.exports = __toCommonJS(filtroDelta_exports);
|
||||
var import_zod = __toESM(require("zod"));
|
||||
const zOperadorFiltroDelta = import_zod.default.enum([">", "<", ">=", "<=", "=", "!=", "in", "like"]);
|
||||
const regexIdCondicaoFiltroDelta = /^\{[\w:]+\}$/;
|
||||
const regexColunaFiltroDelta = /^\w+(\.\w+)*$/;
|
||||
const zColunaFiltroDelta = import_zod.default.string().regex(regexColunaFiltroDelta, "Coluna inv\xE1lida").describe("nome da coluna ou caminho aninhado do jsonb");
|
||||
const zCondicaoFiltroDelta = import_zod.default.object({
|
||||
/**
|
||||
* Identificador único da condição.
|
||||
*
|
||||
* Exemplo:
|
||||
* {1}
|
||||
*/
|
||||
id: import_zod.default.string().describe("id da condi\xE7\xE3o do filtro").regex(regexIdCondicaoFiltroDelta, "O id deve seguir o formato {identificador}"),
|
||||
/**
|
||||
* Nome da coluna ou caminho jsonb.
|
||||
*/
|
||||
coluna: zColunaFiltroDelta,
|
||||
/**
|
||||
* Operador da comparação.
|
||||
*/
|
||||
operador: zOperadorFiltroDelta,
|
||||
/**
|
||||
* Valor utilizado na comparação.
|
||||
*/
|
||||
valor: import_zod.default.any().describe("valor de compara\xE7\xE3o")
|
||||
});
|
||||
const formulaFiltroDeltaValida = (formula) => {
|
||||
const tokensPermitidos = formula.match(/\{[\w:]+\}|\bNAO\b|\bE\b|\bOU\b|\(|\)/g) || [];
|
||||
const formulaReconstruida = tokensPermitidos.join("");
|
||||
const formulaOriginalSemEspacos = formula.replace(/\s+/g, "");
|
||||
const formulaReconstruidaSemEspacos = formulaReconstruida.replace(/\s+/g, "");
|
||||
if (formulaOriginalSemEspacos !== formulaReconstruidaSemEspacos) {
|
||||
return false;
|
||||
}
|
||||
const expressaoLogica = formula.replace(/\{[\w:]+\}/g, "true").replace(/\bNAO\b/g, "!").replace(/\bE\b/g, "&&").replace(/\bOU\b/g, "||");
|
||||
try {
|
||||
new Function(`return (${expressaoLogica})`)();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const zFiltroDelta = import_zod.default.object({
|
||||
/**
|
||||
* Lista de condições disponíveis.
|
||||
*/
|
||||
condicoes: import_zod.default.array(zCondicaoFiltroDelta),
|
||||
/**
|
||||
* Fórmula lógica que combina as condições.
|
||||
*/
|
||||
formula: import_zod.default.string().refine(formulaFiltroDeltaValida, {
|
||||
message: "F\xF3rmula inv\xE1lida. Use apenas refer\xEAncias de condi\xE7\xF5es {id} ou {id:sufixo}, operadores E/OU/NAO e par\xEAnteses."
|
||||
})
|
||||
}).superRefine((value, ctx) => {
|
||||
const idsCondicoes = new Set(value.condicoes.map((condicao) => condicao.id));
|
||||
const referenciasFormula = value.formula.match(/\{[\w:]+\}/g) || [];
|
||||
for (const referencia of referenciasFormula) {
|
||||
if (!idsCondicoes.has(referencia)) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
path: ["formula"],
|
||||
message: `A refer\xEAncia ${referencia} n\xE3o existe em condicoes.`
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
zColunaFiltroDelta,
|
||||
zCondicaoFiltroDelta,
|
||||
zFiltroDelta,
|
||||
zOperadorFiltroDelta
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue