kuzzle 2.31.0 → 2.32.0-beta.1

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.
Files changed (41) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/api/controllers/authController.d.ts +3 -2
  4. package/lib/api/funnel.js +2 -1
  5. package/lib/config/default.config.js +1 -0
  6. package/lib/core/backend/backendStorage.d.ts +3 -5
  7. package/lib/core/backend/backendStorage.js +8 -10
  8. package/lib/core/plugin/pluginContext.d.ts +2 -3
  9. package/lib/core/plugin/pluginContext.js +6 -4
  10. package/lib/core/security/tokenRepository.d.ts +1 -1
  11. package/lib/core/security/tokenRepository.js +1 -1
  12. package/lib/core/shared/ObjectRepository.d.ts +1 -1
  13. package/lib/core/storage/clientAdapter.js +6 -4
  14. package/lib/core/storage/storageEngine.js +4 -5
  15. package/lib/kerror/index.js +1 -1
  16. package/lib/kuzzle/event/KuzzleEventEmitter.d.ts +70 -0
  17. package/lib/kuzzle/event/KuzzleEventEmitter.js +328 -0
  18. package/lib/kuzzle/index.d.ts +3 -0
  19. package/lib/kuzzle/index.js +7 -4
  20. package/lib/kuzzle/kuzzle.d.ts +32 -19
  21. package/lib/kuzzle/kuzzle.js +31 -31
  22. package/lib/service/storage/{elasticsearch.d.ts → 7/elasticsearch.d.ts} +40 -22
  23. package/lib/service/storage/{elasticsearch.js → 7/elasticsearch.js} +24 -43
  24. package/lib/service/storage/{esWrapper.js → 7/esWrapper.js} +6 -4
  25. package/lib/service/storage/8/elasticsearch.d.ts +972 -0
  26. package/lib/service/storage/8/elasticsearch.js +2925 -0
  27. package/lib/service/storage/8/esWrapper.js +303 -0
  28. package/lib/service/storage/Elasticsearch.d.ts +9 -0
  29. package/lib/service/storage/Elasticsearch.js +48 -0
  30. package/lib/service/storage/commons/queryTranslator.d.ts +5 -0
  31. package/lib/service/storage/commons/queryTranslator.js +189 -0
  32. package/lib/types/EventHandler.d.ts +29 -1
  33. package/lib/types/config/KuzzleConfiguration.d.ts +2 -1
  34. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +6 -2
  35. package/lib/types/storage/{Elasticsearch.d.ts → 7/Elasticsearch.d.ts} +1 -1
  36. package/lib/types/storage/8/Elasticsearch.d.ts +59 -0
  37. package/lib/types/storage/8/Elasticsearch.js +3 -0
  38. package/package.json +7 -4
  39. package/lib/kuzzle/event/kuzzleEventEmitter.js +0 -405
  40. package/lib/service/storage/queryTranslator.js +0 -219
  41. /package/lib/types/storage/{Elasticsearch.js → 7/Elasticsearch.js} +0 -0
@@ -1,219 +0,0 @@
1
- /*
2
- * Kuzzle, a backend software, self-hostable and ready to use
3
- * to power modern apps
4
- *
5
- * Copyright 2015-2022 Kuzzle
6
- * mailto: support AT kuzzle.io
7
- * website: http://kuzzle.io
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License.
11
- * You may obtain a copy of the License at
12
- *
13
- * https://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software
16
- * distributed under the License is distributed on an "AS IS" BASIS,
17
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- * See the License for the specific language governing permissions and
19
- * limitations under the License.
20
- */
21
-
22
- "use strict";
23
-
24
- const kerror = require("../../kerror");
25
-
26
- 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
- }
34
- }
35
-
36
- const KONCORDE_OPERATORS = ["and", "or", "not", "bool"];
37
-
38
- /**
39
- * Parse the Koncorde path to extract the path and the value
40
- * path have the form "path.to.field[json_value]"
41
- *
42
- * @param {string} path
43
- * @returns
44
- */
45
- function parseKoncordePath(path) {
46
- const firstBracket = path.indexOf("[");
47
-
48
- if (firstBracket < 0) {
49
- return {
50
- path,
51
- };
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
- }
70
-
71
- 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,
96
- },
97
- },
98
- },
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,
138
- },
139
- }),
140
- missing: (field) => ({
141
- bool: {
142
- must_not: [{ exists: { field } }],
143
- },
144
- }),
145
- range: (content) => ({
146
- range: {
147
- ...content,
148
- },
149
- }),
150
- };
151
-
152
- 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],
171
- },
172
- }),
173
- };
174
-
175
- 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);
191
- }
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
- }
201
- }
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
- };
213
- }
214
-
215
- return converter(content);
216
- }
217
- }
218
-
219
- module.exports = QueryTranslator;