Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 14 additions & 21 deletions packages/codec-url-simple/src/decoder/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {
} from '@rapiq/parser-simple';
import { parse } from 'qs';
import type {
Condition,
Fields,
Pagination,
Relations,
Sorts,
IFields,
IFilters,
IPagination,
IQuery,
IRelations,
ISorts,
} from '@rapiq/core';
import {
Query,
Expand All @@ -44,7 +45,7 @@ export class URLDecoder {
this.sort = new SimpleSortParser();
}

decode(input: string) : Query | null {
decode(input: string) : IQuery | null {
const parsed = parse(input);
if (!isObject(parsed)) {
return null;
Expand Down Expand Up @@ -75,7 +76,7 @@ export class URLDecoder {
return output;
}

decodeFields(input: string) : Fields | null {
decodeFields(input: string) : IFields | null {
const output = parse(input);
if (!isObject(output)) {
return null;
Expand All @@ -88,41 +89,33 @@ export class URLDecoder {
return this.fields.parse(output);
}

decodeFilters(input: string) : Condition | null {
decodeFilters(input: string) : IFilters | null {
const output = parse(input);
if (!isObject(output)) {
return null;
}

if (output[URLParameter.FILTERS]) {
if (isObject(output[URLParameter.FILTERS])) {
return this.filters.parse(output[URLParameter.FILTERS]);
}

return null;
return this.filters.parse(output[URLParameter.FILTERS]);
}

return this.filters.parse(output);
}

decodePagination(input: string) : Pagination | null {
decodePagination(input: string) : IPagination | null {
const output = parse(input);
if (!isObject(output)) {
return null;
}

if (output[URLParameter.PAGINATION]) {
if (isObject(output[URLParameter.PAGINATION])) {
return this.pagination.parse(output[URLParameter.PAGINATION]);
}

return null;
return this.pagination.parse(output[URLParameter.PAGINATION]);
}

return this.pagination.parse(output);
}

decodeRelations(input: string) : Relations | null {
decodeRelations(input: string) : IRelations | null {
const output = parse(input);
if (!isObject(output)) {
return null;
Expand All @@ -135,7 +128,7 @@ export class URLDecoder {
return this.relations.parse(output);
}

decodeSort(input: string) : Sorts | null {
decodeSort(input: string) : ISorts | null {
const output = parse(input);
if (!isObject(output)) {
return null;
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
},
"homepage": "https://github.com/Tada5hi/rapiq#readme",
"dependencies": {
"@ucast/core": "^1.10.2",
"pathtrace": "^1.1.0",
"smob": "^1.5.0"
},
Expand Down
23 changes: 6 additions & 17 deletions packages/core/src/parameter/fields/collection/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,33 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { IField } from '../record';
import { Field } from '../record';
import { FieldOperator } from '../../../schema';
import type { IFieldsVisitor } from './types';
import type { IFields, IFieldsVisitor } from './types';

type FieldsExecuteOptions = {
default: string[],
allowed: string[],
};

export class Fields {
readonly value : Field[];
export class Fields implements IFields {
readonly value : IField[];

constructor(value : Field[] = []) {
constructor(value : IField[] = []) {
this.value = value;
}

accept<R>(visitor: IFieldsVisitor<R>): R {
return visitor.visitFields(this);
}

mergeWith(input: Fields | Field) {
if (input instanceof Field) {
this.value.push(input);
}

if (input instanceof Fields) {
for (let i = 0; i < input.value.length; i++) {
this.value.push(input.value[i]);
}
}
}

/**
* Extract field set, with includes and excludes.
*
* @param options
*/
execute(options: FieldsExecuteOptions) : Fields {
execute(options: FieldsExecuteOptions) : IFields {
const includes : string[] = [];
const excludes : string[] = [];
const explicates : string[] = [];
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/parameter/fields/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { Fields } from './module';
import type { IField } from '../record';

export interface IFieldsVisitor<R> {
visitFields(expr: Fields): R;
visitFields(expr: IFields): R;
}

export interface IFields {
readonly value: IField[]

accept<R>(visitor: IFieldsVisitor<R>): R;
}
6 changes: 3 additions & 3 deletions packages/core/src/parameter/fields/record/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { IFieldVisitor } from './types';
import type { IField, IFieldVisitor } from './types';

export class Field {
name: string;
export class Field implements IField {
readonly name: string;

readonly operator: string | undefined;

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/parameter/fields/record/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ import type { Field } from './module';
export interface IFieldVisitor<R> {
visitField(expr: Field): R;
}

export interface IField {
readonly name: string;

readonly operator: string | undefined;

accept<R>(visitor: IFieldVisitor<R>): R;
}
22 changes: 22 additions & 0 deletions packages/core/src/parameter/filters/collection/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2026.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import type { ICondition } from '../condition';
import type { IFilters } from './types';

export function isFilters(
input: ICondition,
operator?: string,
) : input is IFilters {
if (!Array.isArray(input)) return false;

if (operator) {
return operator === input.operator;
}

return true;
Comment on lines +11 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical bug: Array.isArray(input) always returns false for ICondition/IFilters objects.

The ICondition and IFilters interfaces are objects with operator and value properties—they are not arrays themselves. The check Array.isArray(input) will always fail, making this type guard non-functional.

To distinguish IFilters from a plain ICondition or IFilter, consider checking for the presence of IFilters-specific properties (like whether value is an array) or methods.

🐛 Proposed fix
 export function isFilters(
     input: ICondition,
     operator?: string,
 ) : input is IFilters {
-    if (!Array.isArray(input)) return false;
+    if (!Array.isArray(input.value)) return false;

     if (operator) {
         return operator === input.operator;
     }

     return true;
 }

Note: This fix assumes IFilters is the only condition type with an array value. If IFilter or other condition types can also have array values, additional discrimination logic may be needed (e.g., checking for 'accept' in input or a dedicated type discriminator property).

🤖 Prompt for AI Agents
In `@packages/core/src/parameter/filters/collection/check.ts` around lines 11 -
21, The type-guard isFilters currently (in function isFilters) wrongly checks
Array.isArray(input); instead detect IFilters by verifying input is an object
with a value that is an array (e.g., ensure input && typeof input === 'object'
&& 'value' in input && Array.isArray((input as any).value)); keep the existing
operator comparison (operator === input.operator) when operator is provided;
update the function's initial checks to safely access input.value so the type
predicate (input is IFilters) works correctly.

}
2 changes: 2 additions & 0 deletions packages/core/src/parameter/filters/collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

export * from './check';
export * from './module';
export * from './types';
39 changes: 16 additions & 23 deletions packages/core/src/parameter/filters/collection/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
* view the LICENSE file that was distributed with this source code.
*/

import { CompoundCondition as BaseCompoundCondition } from '@ucast/core';

import type { Condition } from '../condition';
import type { IFiltersVisitor } from './types';
import type { Condition, ICondition } from '../condition';
import type { IFilters, IFiltersVisitor } from './types';
import { isFilters } from './check';

export class Filters<
T extends Condition = Condition,
> extends BaseCompoundCondition<T> {
> implements IFilters<T> {
readonly value: T[];

readonly operator: string;

constructor(operator: string, conditions: T[]) {
this.operator = operator;
this.value = conditions;
}

accept<R>(visitor: IFiltersVisitor<R>) : R {
return visitor.visitFilters(this);
}
Expand All @@ -27,7 +35,7 @@ export class Filters<
}
}

flatten(aggregatedResult?: T[]) : Filters<T> {
flatten(aggregatedResult?: T[]) : IFilters<T> {
// this.value.splice(0, this.value.length, ...next);

return new Filters(
Expand All @@ -36,7 +44,7 @@ export class Filters<
);
}

protected flattenInternal<F extends Condition>(
protected flattenInternal<F extends ICondition>(
conditions: F[],
operator: string,
aggregatedResult?: F[],
Expand All @@ -46,7 +54,7 @@ export class Filters<
for (let i = 0, { length } = conditions; i < length; i++) {
const currentNode = conditions[i];

if (Filters.check(currentNode, operator)) {
if (isFilters(currentNode, operator)) {
currentNode.flatten(flatConditions);
} else {
flatConditions.push(currentNode);
Expand All @@ -55,19 +63,4 @@ export class Filters<

return flatConditions;
}

static check(
condition: Condition,
operator?: string,
) : condition is Filters {
if (!(condition instanceof Filters)) {
return false;
}

if (operator) {
return operator === condition.operator;
}

return true;
}
}
20 changes: 18 additions & 2 deletions packages/core/src/parameter/filters/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { Filters } from './module';
import type { ICondition } from '../condition';

export interface IFiltersVisitor<R> {
visitFilters(expr: Filters): R;
visitFilters(expr: IFilters): R;
}
Comment on lines 10 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find and examine the clear() method in module.ts
find . -name "module.ts" -path "*/parameter/filters/collection/*" | head -5

Repository: tada5hi/rapiq

Length of output: 115


🏁 Script executed:

#!/bin/bash
# Search for the clear() method in the filters collection directory
rg "clear\s*\(" packages/core/src/parameter/filters/collection/ -A 5 -B 2

Repository: tada5hi/rapiq

Length of output: 1076


The clear() method in packages/core/src/parameter/filters/collection/module.ts has a critical bug in its loop condition.

The loop condition i === 0 should be i >= 0. The current code prevents the loop body from executing when the array has more than one element, making the method ineffective at clearing multi-element arrays.

Buggy code
clear() {
    for (let i = this.value.length - 1; i === 0; i--) {
        this.value.splice(i, 1);
    }
}

Change the condition to i >= 0 to properly iterate backward through all elements.

🤖 Prompt for AI Agents
In `@packages/core/src/parameter/filters/collection/types.ts` around lines 10 -
12, The clear() method in the collection module is using the wrong loop
condition so it never iterates through all elements; in the clear()
implementation (method name: clear on the collection class in
packages/core/src/parameter/filters/collection/module.ts) change the for-loop
condition from i === 0 to i >= 0 so the loop decrements from this.value.length -
1 down to 0 and splices each element, ensuring multi-element arrays are fully
cleared.


export interface IFilters<
T extends ICondition = ICondition,
> {
readonly operator: string;

readonly value : T[];

accept<R>(visitor: IFiltersVisitor<R>) : R;

add(child: T) : void;

clear() : void;

flatten(items?: T[]) : IFilters<T>;
}
18 changes: 16 additions & 2 deletions packages/core/src/parameter/filters/condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
* view the LICENSE file that was distributed with this source code.
*/

import { Condition as BaseCondition } from '@ucast/core';
export interface ICondition<
T = unknown,
> {
readonly operator: string;

readonly value: T;
}
export class Condition<
T = unknown,
> extends BaseCondition<T> {
> {
readonly operator: string;

readonly value: T;

constructor(operator: string, value: T) {
this.operator = operator;

this.value = value;
}
}
8 changes: 0 additions & 8 deletions packages/core/src/parameter/filters/helpers/index.ts

This file was deleted.

Loading