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
82 changes: 10 additions & 72 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,79 +1,17 @@
{
"plugins": ["kuzzle"],
"extends": ["plugin:kuzzle/default", "plugin:kuzzle/node"],
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"consistent-return": 0,
"curly": 2,
"dot-notation": 2,
"eqeqeq": 2,
"func-names": ["error", "always"],
"guard-for-in": 2,
"indent": [2, 2, {"SwitchCase": 1}],
"linebreak-style": [2, "unix"],
"new-cap": 1,
"no-caller": 2,
"no-catch-shadow": 2,
"no-console": 2,
"no-else-return": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-eval": 2,
"no-implicit-coercion": 2,
"no-implied-eval": 2,
"no-invalid-this": 2,
"no-irregular-whitespace": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 1,
"no-loop-func": 2,
"no-multi-spaces": 1,
"no-multiple-empty-lines": 1,
"no-native-reassign": 2,
"no-nested-ternary": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-throw-literal": 2,
"no-undef": 2,
"no-undef-init": 1,
"no-unreachable": 2,
"no-unused-expressions": [2, {"allowShortCircuit": true}],
"no-useless-call": 2,
"no-with": 2,
"quotes": [2, "single"],
"require-atomic-updates": 0,
"semi": [2, "always"],
"space-before-blocks": 2,
"strict": [2, "global"],
"vars-on-top": 2,
"yoda": [2, "never"],
"sort-keys": ["error", "asc"]
"sort-keys": "off",
"kuzzle/array-foreach": "off"
},
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"sort-keys": "off"
}
"files": ["*.ts"],
"extends": ["plugin:kuzzle/typescript"]
}
],
"env": {
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"ecmaFeatures": {
"impliedStrict": false
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": "eslint:recommended"
]
}
8 changes: 4 additions & 4 deletions .github/workflows/pull_request.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on: [pull_request]
jobs:
lint:
name: Lint
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["16", "18", "20", "22"]
node-version: ["20", "22", "24"]
steps:
- uses: actions/checkout@v4

Expand All @@ -23,10 +23,10 @@ jobs:
unit-tests:
name: Unit Tests - Node.js v${{ matrix.node-version }}
needs: [lint]
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["16", "18", "20", "22"]
node-version: ["20", "22", "24"]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_branches.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
name: Release process
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
Expand Down
6 changes: 0 additions & 6 deletions .husky/commit-msg

This file was deleted.

6 changes: 0 additions & 6 deletions .husky/pre-commit

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

END OF TERMS AND CONDITIONS

Copyright 2015-2017 Kuzzle
Copyright 2015-2025 Kuzzle SAS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -188,4 +188,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
58 changes: 29 additions & 29 deletions lib/engine/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/*
* Kuzzle, a backend software, self-hostable and ready to use
* to power modern apps
Expand All @@ -19,22 +21,22 @@
* limitations under the License.
*/

const { OperandsStorage } = require('./storeOperands');
const OperandsRemoval = require('./removeOperands');
const Filter = require('./objects/filter');
const Subfilter = require('./objects/subfilter');
const Condition = require('./objects/condition');
const FieldOperand = require('./objects/fieldOperand');
const Matcher = require('./matcher');
const { hash } = require('../util/hash');
const { OperandsStorage } = require("./storeOperands");
const OperandsRemoval = require("./removeOperands");
const Filter = require("./objects/filter");
const Subfilter = require("./objects/subfilter");
const Condition = require("./objects/condition");
const FieldOperand = require("./objects/fieldOperand");
const Matcher = require("./matcher");
const { hash } = require("../util/hash");

/**
* Real-time engine
*
* @class Engine
*/
class Engine {
constructor (config) {
constructor(config) {
this.seed = config.seed;
this.storeOperand = new OperandsStorage(config);
this.removeOperand = new OperandsRemoval(config);
Expand Down Expand Up @@ -80,7 +82,7 @@ class Engine {
* @param {string} filterId
* @param {Number}
*/
remove (filterId) {
remove(filterId) {
const filter = this.filters.get(filterId);

if (!filter) {
Expand All @@ -93,19 +95,18 @@ class Engine {
this.removeOperand[condition.keyword](
this.foPairs,
subfilter,
condition);
condition,
);

if (condition.subfilters.size === 1) {
this.conditions.delete(condition.id);
}
else {
} else {
condition.subfilters.delete(subfilter);
}
}

this.subfilters.delete(subfilter.id);
}
else {
} else {
subfilter.filters.delete(filter);
}
}
Expand All @@ -120,23 +121,23 @@ class Engine {
*
* @param {NormalizedFilter} normalized
*/
store (normalized) {
store(normalized) {
if (this.filters.has(normalized.id)) {
return;
}

const filter = new Filter(normalized.id, normalized.filter);
this.filters.set(normalized.id, filter);

for(let i = 0; i < normalized.filter.length; i++) {
for (let i = 0; i < normalized.filter.length; i++) {
const sf = normalized.filter[i];
const sfResult = this._addSubfilter(filter, sf);

if (sfResult.created) {
const subfilter = this.subfilters.get(sfResult.id);
const addedConditions = this._addConditions(subfilter, sf);

for(let j = 0; j < addedConditions.length; j++) {
for (let j = 0; j < addedConditions.length; j++) {
const cond = addedConditions[j];
let operand = this.foPairs.get(cond.keyword);

Expand All @@ -157,7 +158,7 @@ class Engine {
* @param {Object} data
* @return {Array.<String>}
*/
match (data) {
match(data) {
return this.matcher.match(this.foPairs, data);
}

Expand All @@ -172,7 +173,7 @@ class Engine {
* @param {Array} subfilter
* @return {{created: Boolean, id: String}}
*/
_addSubfilter (filter, subfilter) {
_addSubfilter(filter, subfilter) {
const sfId = hash(this.seed, subfilter);
const sfRef = this.subfilters.get(sfId);
let created = true;
Expand All @@ -181,8 +182,7 @@ class Engine {
created = false;
sfRef.filters.add(filter);
filter.subfilters.add(sfRef);
}
else {
} else {
const sfObj = new Subfilter(sfId, filter);
this.subfilters.set(sfId, sfObj);
filter.subfilters.add(sfObj);
Expand All @@ -202,10 +202,10 @@ class Engine {
* @param {Array} conditions - array of conditions
* @return {Array}
*/
_addConditions (subfilter, conditions) {
_addConditions(subfilter, conditions) {
const diff = [];

for(let i = 0; i < conditions.length; i++) {
for (let i = 0; i < conditions.length; i++) {
const cond = conditions[i];
const cId = hash(this.seed, cond);
const condLink = this.conditions.get(cId);
Expand All @@ -216,14 +216,14 @@ class Engine {
subfilter.conditions.add(condLink);
diff.push(condLink);
}
}
else {
const keyword = Object.keys(cond).filter(k => k !== 'not')[0];
} else {
const keyword = Object.keys(cond).filter((k) => k !== "not")[0];
const condObj = new Condition(
cId,
subfilter,
cond.not ? 'not' + keyword : keyword,
cond[keyword]);
cond.not ? "not" + keyword : keyword,
cond[keyword],
);

this.conditions.set(cId, condObj);
subfilter.conditions.add(condObj);
Expand Down
34 changes: 18 additions & 16 deletions lib/engine/matcher/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/*
* Kuzzle, a backend software, self-hostable and ready to use
* to power modern apps
Expand All @@ -19,7 +21,7 @@
* limitations under the License.
*/

const TestTables = require('./testTables');
const TestTables = require("./testTables");

/**
* Matches documents or messages against stored subscriptions
Expand All @@ -30,20 +32,20 @@ const TestTables = require('./testTables');
class Matcher {
constructor() {
this.matchers = {
equals: require('./matchEquals'),
everything: require('./matchEverything'),
exists: require('./matchExists'),
geospatial: require('./matchGeospatial'),
match: require('./matchMatch').MatchMatch,
notequals: require('./matchNotEquals'),
notexists: require('./matchNotExists'),
notgeospatial: require('./matchNotGeospatial'),
notmatch: require('./matchNotMatch').MatchNotMatch,
notrange: require('./matchNotRange'),
notregexp: require('./matchNotRegexp'),
range: require('./matchRange'),
regexp: require('./matchRegexp'),
select: require('./matchSelect').MatchSelect,
equals: require("./matchEquals"),
everything: require("./matchEverything"),
exists: require("./matchExists"),
geospatial: require("./matchGeospatial"),
match: require("./matchMatch").MatchMatch,
notequals: require("./matchNotEquals"),
notexists: require("./matchNotExists"),
notgeospatial: require("./matchNotGeospatial"),
notmatch: require("./matchNotMatch").MatchNotMatch,
notrange: require("./matchNotRange"),
notregexp: require("./matchNotRegexp"),
range: require("./matchRange"),
regexp: require("./matchRegexp"),
select: require("./matchSelect").MatchSelect,
};
}

Expand All @@ -57,7 +59,7 @@ class Matcher {
match(foPairs, data) {
const testTables = new TestTables();

for (const [ key, operand ] of foPairs) {
for (const [key, operand] of foPairs) {
if (this.matchers[key]) {
this.matchers[key](operand, testTables, data);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/engine/matcher/matchEquals.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/*
* Kuzzle, a backend software, self-hostable and ready to use
* to power modern apps
Expand Down Expand Up @@ -27,7 +29,7 @@
* @param {object} testTables - test tables to update when a filter matches the document
* @param {object} document
*/
function MatchEquals (operand, testTables, document) {
function MatchEquals(operand, testTables, document) {
for (const [key, value] of operand.fields.entries()) {
const subfilters = value.get(document[key]);

Expand Down
Loading