Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export default tseslint.config(
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-null': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/filename-case': [
'error',
{
cases: {
kebabCase: true,
},
ignore: [/.*__fixtures__.*/],
},
],
},
},
);
9,226 changes: 3,411 additions & 5,815 deletions package-lock.json

Large diffs are not rendered by default.

47 changes: 24 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
}
},
"files": [
Expand All @@ -57,29 +57,30 @@
"prepare": "husky"
},
"devDependencies": {
"@codspeed/vitest-plugin": "^4.0.0",
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@eslint/js": "^9.23.0",
"@codspeed/vitest-plugin": "^5.5.0",
"@commitlint/cli": "^21.0.2",
"@commitlint/config-conventional": "^21.0.2",
"@eslint/js": "^10.0.1",
"@semantic-release/commit-analyzer": "^13.0.1",
"@semantic-release/github": "^11.0.1",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.3",
"@types/node": "^24.0.14",
"@vitest/coverage-v8": "^3.0.9",
"@vitest/ui": "^3.0.9",
"eslint": "^9.23.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unicorn": "^60.0.0",
"globals": "^16.0.0",
"@semantic-release/github": "^12.0.8",
"@semantic-release/npm": "^13.1.5",
"@semantic-release/release-notes-generator": "^14.1.1",
"@types/node": "^25.9.2",
"@vitest/coverage-v8": "^4.1.8",
"@vitest/ui": "^4.1.8",
"eslint": "^10.4.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.6",
"eslint-plugin-unicorn": "^65.0.0",
"globals": "^17.6.0",
"husky": "^9.1.7",
"prettier": "3.6.2",
"semantic-release": "^24.2.3",
"peggy": "^3.0.2",
"prettier": "^3.8.3",
"semantic-release": "^25.0.3",
"ts-pegjs": "^4.2.1",
"tsup": "^8.4.0",
"typescript": "^5.8.2",
"typescript-eslint": "^8.27.0",
"vitest": "^3.0.9"
"tsup": "^8.5.1",
"typescript": "^6.0.3",
"typescript-eslint": "^8.60.1",
"vitest": "^4.1.8"
}
}
4 changes: 2 additions & 2 deletions src/filter/test-value.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RangeOperator } from '../types/ast';
import { FlatType } from '../types/data';
import { isWildCardString } from '../types/guards';
import { isWildcardString } from '../types/guards';

const MAX_TIMESTAMP = 8.64e15;

Expand Down Expand Up @@ -85,7 +85,7 @@ export function testRangeNode(operator?: RangeOperator, value?: FlatType, filter
function compareValues(a: FlatType, b: FlatType, falseValue: number): number {
if (typeof a === 'number') {
return a - Number(b);
} else if (typeof b === 'string' && isWildCardString(b)) {
} else if (typeof b === 'string' && isWildcardString(b)) {
return testWildcard(a, b) ? 0 : -1;
} else if (a instanceof Date) {
return a.getTime() - new Date(b == Infinity ? MAX_TIMESTAMP : String(b)).getTime();
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ASTEvaluator {
result.push(...(subResult.filter((r) => !result.includes(r as never)) as never[]));
}

return result.sort((a, b) => data.indexOf(a) - data.indexOf(b));
return result.toSorted((a, b) => data.indexOf(a) - data.indexOf(b));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export type FunctionResolverReturnType<T> =
* a callback function for resolving functions, taking a function node and filtered data,
* and returning the resolved value or an object containing resolved value and filtered data.
*/
export type FunctionResolverCallBack<T> = (node: FunctionNode, data: T) => FunctionResolverReturnType<T>;
export type FunctionResolverCallback<T> = (node: FunctionNode, data: T) => FunctionResolverReturnType<T>;

/**
* a function resolver, a mapping from function names to resolver callback functions.
*/
export type FunctionResolver = {
[name: string]: FunctionResolverCallBack<any>;
[name: string]: FunctionResolverCallback<any>;
};

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class ReferenceResolver {
* @param resolver The callback function for resolving the function.
* @returns The ReferenceResolver instance for chaining.
*/
addFunctionResolver(name: string, resolver: FunctionResolverCallBack<any>): this {
addFunctionResolver(name: string, resolver: FunctionResolverCallback<any>): this {
this.functionResolver[name] = resolver;
return this;
}
Expand Down
3 changes: 1 addition & 2 deletions src/tests/__fixtures__/filter/field-group-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ const testFieldGroupQueries: TestFilterQuery[] = [
difficulty: 'nested',
desc: 'Nested Test 2',
query: 'gender:(Male OR Female) AND (age:(20 OR 25) OR age:(30 OR 35))',
expected: (p) =>
(p.gender === 'Male' || p.gender === 'Female') && (p.age === 20 || p.age === 25 || p.age === 30 || p.age === 35),
expected: (p) => ['Male', 'Female'].includes(p.gender) && [20, 25, 30, 35].includes(p.age),
resultLen: (len) => expect(len).toMatchInlineSnapshot(`7`),
},
];
Expand Down
4 changes: 2 additions & 2 deletions src/tests/__fixtures__/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FunctionResolver, VariableResolver } from '../../../handlers/resolver';
import testVariableQueries from './variable-queries';
import testFunctionQueries from './function-queries';
import testRangeQueries from './range-queries';
import testWildCardQueries from './wilcard-queries';
import testWildcardQueries from './wilcard-queries';
import testRegexQueries from './regex-queries';
import testFieldGroupQueries from './field-group-queries';
import testLogicalQueries from './logical-queries';
Expand All @@ -23,7 +23,7 @@ const testFilterQueries: TestFilterQuery[] = [
...testLogicalQueries,
...testFieldGroupQueries,
...testRegexQueries,
...testWildCardQueries,
...testWildcardQueries,
...testRangeQueries,
...testVariableQueries,
...testFunctionQueries,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/__fixtures__/filter/wilcard-queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'vitest';
import { TestFilterQuery } from '.';

const testWildCardQueries: TestFilterQuery[] = [
const testWildcardQueries: TestFilterQuery[] = [
{
group: 'wildcard',
difficulty: 'simple',
Expand Down Expand Up @@ -52,4 +52,4 @@ const testWildCardQueries: TestFilterQuery[] = [
},
];

export default testWildCardQueries;
export default testWildcardQueries;
4 changes: 2 additions & 2 deletions src/types/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ export function isVariableNode(node: i.Node): node is i.VariableNode {
return isTerm(node) && node?.value?.type == 'variable';
}

export function isWildCardString(term) {
export function isWildcardString(term) {
if (typeof term !== 'string') return false;
if (term.includes('*') || term.includes('?')) return true;
return false;
}

/* export function isWildcardField(node: i.Node): boolean {
return !!(node && isWildCardString((node as any).field));
return !!(node && isWildcardString((node as any).field));
} */

export function isTerm(node: i.Node): node is i.Term {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/iterate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-for-in-array */
import { testWildcard } from '../filter/test-value';
import { isWildCardString } from '../types/guards';
import { isWildcardString } from '../types/guards';
import { IteratorConfig } from '../types/iterator';

type AnyObject = { [key: string]: any };
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function* iterate(
const currentField = splittedFields[currentPath.length]; // Get the current field to match
const lastField = splittedFields.length > 0 ? splittedFields.at(-1) : ''; // Get the last field in the pattern
const isTrailingWildcard = lastField?.endsWith('*') && !currentField; // Check if it's a trailing wildcard pattern
const isWildcard = isWildCardString(currentField); // Check if the current field is a wildcard
const isWildcard = isWildcardString(currentField); // Check if the current field is a wildcard

// Check if the object is iterable and not in the NOT_ITERABLE list
if (typeof obj === 'object' && obj !== null && !NOT_ITERABLE.some((cls) => obj instanceof cls)) {
Expand Down Expand Up @@ -66,7 +66,7 @@ export default function* iterate(
// If the key starts with _, it shouldn't work for wildcard, if not explicity specified
if (checkPrivate && isPrivateField(key) && privateFieldName(key) != currentField) continue;
if (Object.prototype.hasOwnProperty.call(obj, key)) {
let objKeyWithCurrentField = '';
let objKeyWithCurrentField: string;
// Match properties based on the field or wildcard pattern
if (
!field ||
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"noImplicitAny": false,
"target": "esnext",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"skipLibCheck": true,
"strictNullChecks": true,
"types": ["node"],
"experimentalDecorators": true,
"removeComments": false
},
Expand Down
1 change: 1 addition & 0 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import codspeedPlugin from '@codspeed/vitest-plugin';
export default defineConfig({
plugins: [codspeedPlugin()],
test: {
exclude: ['node_modules', 'dist'],
coverage: {
exclude: ['scripts/**', 'src/benchmark/**', 'src/xlucene/lucene.ts', 'commitlint.config.js'],
},
Expand Down
Loading