kuzzle 2.32.0-elasticsearch-8.1 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,9 +4,6 @@
4
4
  <p align="center">
5
5
  <img alt="GitHub branch checks state" src="https://img.shields.io/github/checks-status/kuzzleio/kuzzle/master">
6
6
  <img alt="Sonarcloud" src="https://sonarcloud.io/api/project_badges/measure?project=kuzzleio_kuzzle&metric=alert_status&branch=master">
7
- <a href="https://codecov.io/gh/kuzzleio/kuzzle">
8
- <img src="https://codecov.io/gh/kuzzleio/kuzzle/branch/master/graph/badge.svg?token=jOrGhzslSM"/>
9
- </a>
10
7
  <a href="https://lgtm.com/projects/g/kuzzleio/kuzzle/context:javascript">
11
8
  <img src="https://img.shields.io/lgtm/grade/javascript/g/kuzzleio/kuzzle.svg?logo=lgtm&logoWidth=18" />
12
9
  </a>
package/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from "./lib/core/shared/ObjectRepository";
13
13
  export * from "./lib/core/shared/store";
14
14
  export * from "./lib/core/cache/cacheDbEnum";
15
15
  export * from "./lib/core/storage/storeScopeEnum";
16
+ export * from "./lib/service/storage/commons/queryTranslator";
package/index.js CHANGED
@@ -31,4 +31,5 @@ __exportStar(require("./lib/core/shared/ObjectRepository"), exports);
31
31
  __exportStar(require("./lib/core/shared/store"), exports);
32
32
  __exportStar(require("./lib/core/cache/cacheDbEnum"), exports);
33
33
  __exportStar(require("./lib/core/storage/storeScopeEnum"), exports);
34
+ __exportStar(require("./lib/service/storage/commons/queryTranslator"), exports);
34
35
  //# sourceMappingURL=index.js.map
@@ -169,7 +169,7 @@ function rawGetFrom(domains, source, domain, subdomain, error, ...placeholders)
169
169
  const derivedError = rawGet(domains, domain, subdomain, error, ...placeholders);
170
170
  // If a stacktrace is present, we need to modify the first line because it
171
171
  // still contains the original error message
172
- if (derivedError.stack && derivedError.stack.length && source.stack) {
172
+ if (derivedError?.stack?.length && source?.stack) {
173
173
  const stackArray = source.stack.split("\n");
174
174
  stackArray.shift();
175
175
  derivedError.stack = [
@@ -3,7 +3,7 @@ import { RequestParams, Client } from "sdk-es7";
3
3
  import { TypeMapping } from "sdk-es7/api/types";
4
4
  import { JSONObject, KRequestBody, KRequestParams } from "../../../types/storage/7/Elasticsearch";
5
5
  import ESWrapper from "./esWrapper";
6
- import QueryTranslator from "../commons/queryTranslator";
6
+ import { QueryTranslator } from "../commons/queryTranslator";
7
7
  import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
8
8
  /**
9
9
  * @param {Kuzzle} kuzzle kuzzle instance
@@ -55,7 +55,7 @@ const ms_1 = __importDefault(require("ms"));
55
55
  const semver_1 = __importDefault(require("semver"));
56
56
  const debug_1 = __importDefault(require("../../../util/debug"));
57
57
  const esWrapper_1 = __importDefault(require("./esWrapper"));
58
- const queryTranslator_1 = __importDefault(require("../commons/queryTranslator"));
58
+ const queryTranslator_1 = require("../commons/queryTranslator");
59
59
  const didYouMean_1 = __importDefault(require("../../../util/didYouMean"));
60
60
  const kerror = __importStar(require("../../../kerror"));
61
61
  const requestAssertions_1 = require("../../../util/requestAssertions");
@@ -106,7 +106,7 @@ class ES7 {
106
106
  this._client = null;
107
107
  this._esWrapper = null;
108
108
  this._esVersion = null;
109
- this._translator = new queryTranslator_1.default();
109
+ this._translator = new queryTranslator_1.QueryTranslator();
110
110
  // Allowed root key of a search query
111
111
  this.searchBodyKeys = [
112
112
  "aggregations",
@@ -2,7 +2,7 @@ import _ from "lodash";
2
2
  import { Client, estypes } from "sdk-es8";
3
3
  import { InfoResult, JSONObject, KRequestBody, KRequestParams, KStats, KUpdateResponse } from "../../../types/storage/8/Elasticsearch";
4
4
  import ESWrapper from "./esWrapper";
5
- import QueryTranslator from "../commons/queryTranslator";
5
+ import { QueryTranslator } from "../commons/queryTranslator";
6
6
  import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
7
7
  /**
8
8
  * @param {Kuzzle} kuzzle kuzzle instance
@@ -55,7 +55,7 @@ const bluebird_1 = __importDefault(require("bluebird"));
55
55
  const semver_1 = __importDefault(require("semver"));
56
56
  const debug_1 = __importDefault(require("../../../util/debug"));
57
57
  const esWrapper_1 = __importDefault(require("./esWrapper"));
58
- const queryTranslator_1 = __importDefault(require("../commons/queryTranslator"));
58
+ const queryTranslator_1 = require("../commons/queryTranslator");
59
59
  const didYouMean_1 = __importDefault(require("../../../util/didYouMean"));
60
60
  const kerror = __importStar(require("../../../kerror"));
61
61
  const requestAssertions_1 = require("../../../util/requestAssertions");
@@ -106,7 +106,7 @@ class ES8 {
106
106
  this._client = null;
107
107
  this._esWrapper = null;
108
108
  this._esVersion = null;
109
- this._translator = new queryTranslator_1.default();
109
+ this._translator = new queryTranslator_1.QueryTranslator();
110
110
  // Allowed root key of a search query
111
111
  this.searchBodyKeys = [
112
112
  "aggregations",
@@ -0,0 +1,5 @@
1
+ export declare class QueryTranslator {
2
+ translate(filters: any): any;
3
+ _translateOperator(operator: any, operands: any): any;
4
+ _translateClause(clause: any, content: any): any;
5
+ }
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryTranslator = void 0;
1
4
  /*
2
5
  * Kuzzle, a backend software, self-hostable and ready to use
3
6
  * to power modern apps
@@ -18,23 +21,14 @@
18
21
  * See the License for the specific language governing permissions and
19
22
  * limitations under the License.
20
23
  */
21
-
22
- "use strict";
23
-
24
- const kerror = require("../../../kerror");
25
-
24
+ const kerror_1 = require("../../../kerror");
26
25
  class KeywordError extends Error {
27
- constructor(type, name) {
28
- super(
29
- `The ${type} "${name}" of Koncorde DSL is not supported for search queries.`,
30
- );
31
-
32
- this.keyword = { name, type };
33
- }
26
+ constructor(type, name) {
27
+ super(`The ${type} "${name}" of Koncorde DSL is not supported for search queries.`);
28
+ this.keyword = { name, type };
29
+ }
34
30
  }
35
-
36
31
  const KONCORDE_OPERATORS = ["and", "or", "not", "bool"];
37
-
38
32
  /**
39
33
  * Parse the Koncorde path to extract the path and the value
40
34
  * path have the form "path.to.field[json_value]"
@@ -43,177 +37,153 @@ const KONCORDE_OPERATORS = ["and", "or", "not", "bool"];
43
37
  * @returns
44
38
  */
45
39
  function parseKoncordePath(path) {
46
- const firstBracket = path.indexOf("[");
47
-
48
- if (firstBracket < 0) {
40
+ const firstBracket = path.indexOf("[");
41
+ if (firstBracket < 0) {
42
+ return {
43
+ path,
44
+ };
45
+ }
46
+ const lastBracket = path.lastIndexOf("]");
47
+ if (lastBracket < 0) {
48
+ throw (0, kerror_1.get)("services", "koncorde", "elastic_translation_error", `Invalid exists path "${path}": missing closing bracket`);
49
+ }
49
50
  return {
50
- path,
51
+ path: path.slice(0, firstBracket),
52
+ value: JSON.parse(path.slice(firstBracket + 1, lastBracket)),
51
53
  };
52
- }
53
-
54
- const lastBracket = path.lastIndexOf("]");
55
-
56
- if (lastBracket < 0) {
57
- throw kerror.get(
58
- "services",
59
- "koncorde",
60
- "elastic_translation_error",
61
- `Invalid exists path "${path}": missing closing bracket`,
62
- );
63
- }
64
-
65
- return {
66
- path: path.slice(0, firstBracket),
67
- value: JSON.parse(path.slice(firstBracket + 1, lastBracket)),
68
- };
69
54
  }
70
-
71
55
  const KONCORDE_CLAUSES_TO_ES = {
72
- equals: (content) => ({
73
- term: {
74
- ...content,
75
- },
76
- }),
77
- exists: (field) => {
78
- // Support old syntax { exists: { field: "path" } } and { exists: "path" }
79
- const parsedInfo = parseKoncordePath(field.field || field);
80
-
81
- // If we have a value, we need to use a range query to be sure that the value is the same
82
- if (parsedInfo.value) {
83
- return {
84
- bool: {
85
- filter: [
86
- {
87
- exists: {
88
- field: parsedInfo.path,
89
- },
90
- },
91
- {
92
- range: {
93
- [parsedInfo.path]: {
94
- gte: parsedInfo.value,
95
- lte: parsedInfo.value,
56
+ equals: (content) => ({
57
+ term: {
58
+ ...content,
59
+ },
60
+ }),
61
+ exists: (field) => {
62
+ // Support old syntax { exists: { field: "path" } } and { exists: "path" }
63
+ const parsedInfo = parseKoncordePath(field.field || field);
64
+ // If we have a value, we need to use a range query to be sure that the value is the same
65
+ if (parsedInfo.value) {
66
+ return {
67
+ bool: {
68
+ filter: [
69
+ {
70
+ exists: {
71
+ field: parsedInfo.path,
72
+ },
73
+ },
74
+ {
75
+ range: {
76
+ [parsedInfo.path]: {
77
+ gte: parsedInfo.value,
78
+ lte: parsedInfo.value,
79
+ },
80
+ },
81
+ },
82
+ ],
96
83
  },
97
- },
84
+ };
85
+ }
86
+ return {
87
+ exists: {
88
+ field: parsedInfo.path,
98
89
  },
99
- ],
100
- },
101
- };
102
- }
103
-
104
- return {
105
- exists: {
106
- field: parsedInfo.path,
107
- },
108
- };
109
- },
110
- geoBoundingBox: (content) => ({
111
- geo_bounding_box: {
112
- ...content,
113
- },
114
- }),
115
- geoDistance: (content) => ({
116
- geo_distance: {
117
- ...content,
118
- },
119
- }),
120
- geoDistanceRange: (content) => ({
121
- geo_distance_range: {
122
- ...content,
123
- },
124
- }),
125
- geoPolygon: (content) => ({
126
- geo_polygon: {
127
- ...content,
128
- },
129
- }),
130
- ids: (content) => ({
131
- ids: {
132
- ...content,
133
- },
134
- }),
135
- in: (content) => ({
136
- terms: {
137
- ...content,
90
+ };
138
91
  },
139
- }),
140
- missing: (field) => ({
141
- bool: {
142
- must_not: [{ exists: { field } }],
143
- },
144
- }),
145
- range: (content) => ({
146
- range: {
147
- ...content,
148
- },
149
- }),
92
+ geoBoundingBox: (content) => ({
93
+ geo_bounding_box: {
94
+ ...content,
95
+ },
96
+ }),
97
+ geoDistance: (content) => ({
98
+ geo_distance: {
99
+ ...content,
100
+ },
101
+ }),
102
+ geoDistanceRange: (content) => ({
103
+ geo_distance_range: {
104
+ ...content,
105
+ },
106
+ }),
107
+ geoPolygon: (content) => ({
108
+ geo_polygon: {
109
+ ...content,
110
+ },
111
+ }),
112
+ ids: (content) => ({
113
+ ids: {
114
+ ...content,
115
+ },
116
+ }),
117
+ in: (content) => ({
118
+ terms: {
119
+ ...content,
120
+ },
121
+ }),
122
+ missing: (field) => ({
123
+ bool: {
124
+ must_not: [{ exists: { field } }],
125
+ },
126
+ }),
127
+ range: (content) => ({
128
+ range: {
129
+ ...content,
130
+ },
131
+ }),
150
132
  };
151
-
152
133
  const KONCORDE_OPERATORS_TO_ES = {
153
- and: (content) => ({
154
- bool: {
155
- filter: [...content],
156
- },
157
- }),
158
- bool: undefined,
159
- not: (content) => {
160
- const [name, value] = Object.entries(content[0])[0];
161
-
162
- return {
163
- bool: {
164
- must_not: [{ [name]: value }],
165
- },
166
- };
167
- },
168
- or: (content) => ({
169
- bool: {
170
- should: [...content],
134
+ and: (content) => ({
135
+ bool: {
136
+ filter: [...content],
137
+ },
138
+ }),
139
+ bool: undefined,
140
+ not: (content) => {
141
+ const [name, value] = Object.entries(content[0])[0];
142
+ return {
143
+ bool: {
144
+ must_not: [{ [name]: value }],
145
+ },
146
+ };
171
147
  },
172
- }),
148
+ or: (content) => ({
149
+ bool: {
150
+ should: [...content],
151
+ },
152
+ }),
173
153
  };
174
-
175
154
  class QueryTranslator {
176
- translate(filters) {
177
- const [name, value] = Object.entries(filters)[0];
178
-
179
- if (KONCORDE_OPERATORS.includes(name)) {
180
- return this._translateOperator(name, value);
181
- }
182
-
183
- return this._translateClause(name, value);
184
- }
185
-
186
- _translateOperator(operator, operands) {
187
- const converter = KONCORDE_OPERATORS_TO_ES[operator];
188
-
189
- if (converter === undefined) {
190
- throw new KeywordError("operator", operator);
155
+ translate(filters) {
156
+ const [name, value] = Object.entries(filters)[0];
157
+ if (KONCORDE_OPERATORS.includes(name)) {
158
+ return this._translateOperator(name, value);
159
+ }
160
+ return this._translateClause(name, value);
191
161
  }
192
-
193
- const esOperands = [];
194
-
195
- if (operator === "not") {
196
- esOperands.push(this.translate(operands));
197
- } else {
198
- for (const operand of operands) {
199
- esOperands.push(this.translate(operand));
200
- }
162
+ _translateOperator(operator, operands) {
163
+ const converter = KONCORDE_OPERATORS_TO_ES[operator];
164
+ if (converter === undefined) {
165
+ throw new KeywordError("operator", operator);
166
+ }
167
+ const esOperands = [];
168
+ if (operator === "not") {
169
+ esOperands.push(this.translate(operands));
170
+ }
171
+ else {
172
+ for (const operand of operands) {
173
+ esOperands.push(this.translate(operand));
174
+ }
175
+ }
176
+ return converter(esOperands);
201
177
  }
202
-
203
- return converter(esOperands);
204
- }
205
-
206
- _translateClause(clause, content) {
207
- const converter = KONCORDE_CLAUSES_TO_ES[clause];
208
-
209
- if (converter === undefined) {
210
- return {
211
- [clause]: content,
212
- };
178
+ _translateClause(clause, content) {
179
+ const converter = KONCORDE_CLAUSES_TO_ES[clause];
180
+ if (converter === undefined) {
181
+ return {
182
+ [clause]: content,
183
+ };
184
+ }
185
+ return converter(content);
213
186
  }
214
-
215
- return converter(content);
216
- }
217
187
  }
218
-
219
- module.exports = QueryTranslator;
188
+ exports.QueryTranslator = QueryTranslator;
189
+ //# sourceMappingURL=queryTranslator.js.map
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.32.0-elasticsearch-8.1",
4
+ "version": "2.32.0",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "bin": "bin/start-kuzzle-server",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "clean": "touch index.ts && npm run build | grep TSFILE | cut -d' ' -f 2 | xargs rm",
10
- "codecov": "codecov",
11
10
  "cucumber": "cucumber.js --fail-fast",
12
11
  "dev": "ergol docker/scripts/start-kuzzle-dev.ts -c ./config/ergol.config.json",
13
12
  "doc-error-codes": "node -r ts-node/register doc/build-error-codes",
@@ -45,7 +44,7 @@
45
44
  "json2yaml": "1.1.0",
46
45
  "jsonwebtoken": "9.0.2",
47
46
  "koncorde": "4.3.0",
48
- "kuzzle-plugin-auth-passport-local": "6.4.0",
47
+ "kuzzle-plugin-auth-passport-local": "6.4.1",
49
48
  "kuzzle-plugin-logger": "3.0.3",
50
49
  "kuzzle-sdk": "^7.11.3",
51
50
  "kuzzle-vault": "2.0.4",
@@ -92,7 +91,6 @@
92
91
  "@types/lodash": "4.14.202",
93
92
  "async": "3.2.5",
94
93
  "chokidar": "3.5.3",
95
- "codecov": "3.8.3",
96
94
  "cucumber": "6.0.5",
97
95
  "cz-conventional-changelog": "^3.3.0",
98
96
  "ergol": "1.0.2",