Skip to main content

SetterValidator

@webda/ql


Class: SetterValidator

Defined in: packages/ql/src/query.ts:1602

A query validator that operates in assignment mode

Instead of filtering objects, it assigns values to object properties. Only supports = (assignment) combined with AND. No comparisons, OR, or other operators.

Protects against prototype pollution by ignoring __proto__ attributes.

Example​

const target: any = {};
new SetterValidator('name = "John" AND age = 30').eval(target);
// target = { name: "John", age: 30 }

Throws​

if non-assignment operators or OR expressions are used

Extends​

Constructors​

Constructor​

new SetterValidator(sql): SetterValidator

Defined in: packages/ql/src/query.ts:1607

Parameters​

sql​

string

assignment expression (e.g. 'field = "value" AND other = 10')

Returns​

SetterValidator

Throws​

if the expression contains non-assignment operators

Overrides​

QueryValidator.constructor

Properties​

builder​

protected builder: ExpressionBuilder

Defined in: packages/ql/src/query.ts:1415

Inherited from​

QueryValidator.builder


lexer​

protected lexer: WebdaQLLexer

Defined in: packages/ql/src/query.ts:1412

Inherited from​

QueryValidator.lexer


query​

protected query: Query

Defined in: packages/ql/src/query.ts:1414

Inherited from​

QueryValidator.query


sql​

protected sql: string

Defined in: packages/ql/src/query.ts:1425

the query string to parse

Inherited from​

QueryValidator.sql


tree​

protected tree: WebdaqlContext

Defined in: packages/ql/src/query.ts:1413

Inherited from​

QueryValidator.tree

Methods​

assign()​

assign(target, expression): void

Defined in: packages/ql/src/query.ts:1633

Recursively walk the expression tree and apply assignments

Parameters​

target​

any

object to assign values to

expression​

Expression

must be an AndExpression or a = ComparisonExpression

Returns​

void

Throws​

if any non-assignment expression is encountered


displayTree()​

displayTree(tree?): string

Defined in: packages/ql/src/query.ts:1568

Display parse tree back as query

Parameters​

tree?​

ParseTree = ...

the parse tree to display

Returns​

string

the query string representation

Inherited from​

QueryValidator.displayTree


eval()​

eval(target): boolean

Defined in: packages/ql/src/query.ts:1619

Apply the assignments to the target object

Parameters​

target​

any

object to assign values to (mutated in place)

Returns​

boolean

always true

Overrides​

QueryValidator.eval


getExpression()​

getExpression(): Expression

Defined in: packages/ql/src/query.ts:1531

Get the filter expression (without LIMIT / OFFSET / ORDER BY)

Returns​

Expression

the filter expression

Inherited from​

QueryValidator.getExpression


getLimit()​

getLimit(): number

Defined in: packages/ql/src/query.ts:1523

Get parsed LIMIT value, defaulting to 1000

Returns​

number

the limit value

Inherited from​

QueryValidator.getLimit


getOffset()​

getOffset(): string

Defined in: packages/ql/src/query.ts:1440

Get parsed OFFSET continuation token, or empty string if none

Returns​

string

the offset token

Inherited from​

QueryValidator.getOffset


getQuery()​

getQuery(): Query

Defined in: packages/ql/src/query.ts:1539

Retrieve the full parsed query including filter, limit, offset, and orderBy

Returns​

Query

the full query object

Inherited from​

QueryValidator.getQuery


hasCondition()​

hasCondition(): boolean

Defined in: packages/ql/src/query.ts:1450

Check whether the query has a non-empty filter condition

An empty AND expression (no children) is considered to have no condition.

Returns​

boolean

true if there is a filter condition

Inherited from​

QueryValidator.hasCondition


isDynamic()​

isDynamic(): boolean

Defined in: packages/ql/src/query.ts:1559

Check whether this query's filter contains any dynamic values

Returns​

boolean

true if any child comparison holds a DynamicValue

Inherited from​

QueryValidator.isDynamic


merge()​

merge(query?, type?): this

Defined in: packages/ql/src/query.ts:1479

Merge another query string into this query

Filter expressions are combined using the specified logical operator. LIMIT, OFFSET, and ORDER BY from the merged query override existing values.

Parameters​

query?​

string = ""

query string to merge in

type?​

"AND" | "OR" = "AND"

logical operator to combine filters ("AND" or "OR")

Returns​

this

this for chaining

Inherited from​

QueryValidator.merge


toString()​

toString(): string

Defined in: packages/ql/src/query.ts:1465

Reconstruct the query string from the parsed AST

Includes filter, ORDER BY, LIMIT, and OFFSET clauses.

Returns​

string

the reconstructed query string

Inherited from​

QueryValidator.toString