Skip to main content

SetterValidator

@webda/ql


Class: SetterValidator

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

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:1101

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:915

Inherited from​

QueryValidator.builder


lexer​

protected lexer: WebdaQLLexer

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

Inherited from​

QueryValidator.lexer


query​

protected query: Query

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

Inherited from​

QueryValidator.query


sql​

protected sql: string

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

the query string to parse

Inherited from​

QueryValidator.sql


tree​

protected tree: WebdaqlContext

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

Inherited from​

QueryValidator.tree

Methods​

assign()​

assign(target, expression): void

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

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:1062

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:1113

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:1032

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:1024

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:940

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:1040

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:950

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


merge()​

merge(query, type?): this

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

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"

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:965

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