kuzzle 2.30.1-beta.1 → 2.31.0-elasticsearch-8.2
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/lib/api/controllers/authController.d.ts +3 -2
- package/lib/api/controllers/memoryStorageController.js +3 -11
- package/lib/config/default.config.js +1 -0
- package/lib/core/backend/backendStorage.d.ts +3 -5
- package/lib/core/backend/backendStorage.js +8 -10
- package/lib/core/plugin/pluginContext.d.ts +2 -3
- package/lib/core/plugin/pluginContext.js +6 -4
- package/lib/core/security/profileRepository.d.ts +14 -5
- package/lib/core/security/profileRepository.js +50 -17
- package/lib/core/security/roleRepository.js +1 -1
- package/lib/core/shared/ObjectRepository.js +1 -1
- package/lib/core/storage/clientAdapter.js +6 -4
- package/lib/core/storage/storageEngine.js +4 -5
- package/lib/kuzzle/kuzzle.js +1 -1
- package/lib/service/storage/{elasticsearch.d.ts → 7/elasticsearch.d.ts} +40 -22
- package/lib/service/storage/{elasticsearch.js → 7/elasticsearch.js} +23 -42
- package/lib/service/storage/{esWrapper.js → 7/esWrapper.js} +6 -4
- package/lib/service/storage/8/elasticsearch.d.ts +972 -0
- package/lib/service/storage/8/elasticsearch.js +2925 -0
- package/lib/service/storage/8/esWrapper.js +303 -0
- package/lib/service/storage/Elasticsearch.d.ts +9 -0
- package/lib/service/storage/Elasticsearch.js +48 -0
- package/lib/service/storage/{queryTranslator.js → commons/queryTranslator.js} +1 -1
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +6 -2
- package/lib/types/storage/{Elasticsearch.d.ts → 7/Elasticsearch.d.ts} +1 -1
- package/lib/types/storage/8/Elasticsearch.d.ts +59 -0
- package/lib/types/storage/8/Elasticsearch.js +3 -0
- package/package.json +6 -4
- /package/lib/types/storage/{Elasticsearch.js → 7/Elasticsearch.js} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Bluebird from "bluebird";
|
|
1
2
|
import { KuzzleRequest } from "../request";
|
|
2
3
|
import { NativeController } from "./baseController";
|
|
3
4
|
export declare class AuthController extends NativeController {
|
|
@@ -78,7 +79,7 @@ export declare class AuthController extends NativeController {
|
|
|
78
79
|
* @param {KuzzleRequest} request
|
|
79
80
|
* @returns {Promise<Object>}
|
|
80
81
|
*/
|
|
81
|
-
getCurrentUser(request: any): any
|
|
82
|
+
getCurrentUser(request: any): Bluebird<any>;
|
|
82
83
|
/**
|
|
83
84
|
* Returns the rights of the user identified by the given jwt token
|
|
84
85
|
*
|
|
@@ -115,7 +116,7 @@ export declare class AuthController extends NativeController {
|
|
|
115
116
|
*
|
|
116
117
|
* @returns {Promise.<string[]>}
|
|
117
118
|
*/
|
|
118
|
-
getStrategies(): any
|
|
119
|
+
getStrategies(): Bluebird<any>;
|
|
119
120
|
/**
|
|
120
121
|
* @param {KuzzleRequest} request
|
|
121
122
|
* @returns {Promise.<Object>}
|
|
@@ -267,15 +267,11 @@ function initMapping() {
|
|
|
267
267
|
kassert.assertBodyAttributeType(request, "entries", "array");
|
|
268
268
|
|
|
269
269
|
val.forEach((v) => {
|
|
270
|
-
if (
|
|
271
|
-
typeof v !== "object" ||
|
|
272
|
-
!v.field ||
|
|
273
|
-
(!v.value && v.value !== 0)
|
|
274
|
-
) {
|
|
270
|
+
if (typeof v !== "object" || !v.field || !v.value) {
|
|
275
271
|
throw kerror.get(
|
|
276
272
|
"invalid_argument",
|
|
277
273
|
"entries",
|
|
278
|
-
"<array of
|
|
274
|
+
"<array of object>",
|
|
279
275
|
);
|
|
280
276
|
}
|
|
281
277
|
|
|
@@ -352,11 +348,7 @@ function initMapping() {
|
|
|
352
348
|
kassert.assertBodyHasAttribute(request, "entries");
|
|
353
349
|
kassert.assertBodyAttributeType(request, "entries", "array");
|
|
354
350
|
val.forEach((entry) => {
|
|
355
|
-
if (
|
|
356
|
-
typeof entry !== "object" ||
|
|
357
|
-
!entry.key ||
|
|
358
|
-
(!entry.value && entry.value !== 0)
|
|
359
|
-
) {
|
|
351
|
+
if (typeof entry !== "object" || !entry.key || !entry.value) {
|
|
360
352
|
throw kerror.get(
|
|
361
353
|
"invalid_argument",
|
|
362
354
|
"entries",
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ApplicationManager, Backend } from "./index";
|
|
1
|
+
import { ApplicationManager } from "./index";
|
|
3
2
|
export declare class BackendStorage extends ApplicationManager {
|
|
4
3
|
private _client;
|
|
5
4
|
private _Client;
|
|
6
|
-
constructor(application: Backend);
|
|
7
5
|
/**
|
|
8
6
|
* Storage client constructor.
|
|
9
7
|
* (Currently Elasticsearch)
|
|
10
8
|
*
|
|
11
9
|
* @param clientConfig Overload configuration for the underlaying storage client
|
|
12
10
|
*/
|
|
13
|
-
get StorageClient(): new (clientConfig?: any) =>
|
|
11
|
+
get StorageClient(): new (clientConfig?: any) => any;
|
|
14
12
|
/**
|
|
15
13
|
* Access to the underlaying storage engine client.
|
|
16
14
|
* (Currently Elasticsearch)
|
|
17
15
|
*/
|
|
18
|
-
get storageClient():
|
|
16
|
+
get storageClient(): any;
|
|
19
17
|
}
|
|
@@ -19,16 +19,13 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
23
|
exports.BackendStorage = void 0;
|
|
27
|
-
const
|
|
24
|
+
const Elasticsearch_1 = require("../../service/storage/Elasticsearch");
|
|
28
25
|
const index_1 = require("./index");
|
|
29
26
|
class BackendStorage extends index_1.ApplicationManager {
|
|
30
|
-
constructor(
|
|
31
|
-
super(
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
32
29
|
this._client = null;
|
|
33
30
|
this._Client = null;
|
|
34
31
|
}
|
|
@@ -39,13 +36,13 @@ class BackendStorage extends index_1.ApplicationManager {
|
|
|
39
36
|
* @param clientConfig Overload configuration for the underlaying storage client
|
|
40
37
|
*/
|
|
41
38
|
get StorageClient() {
|
|
39
|
+
const kuzzle = this._kuzzle;
|
|
42
40
|
if (!this._Client) {
|
|
43
|
-
const kuzzle = this._kuzzle;
|
|
44
41
|
this._Client = function ESClient(clientConfig = {}) {
|
|
45
|
-
return
|
|
42
|
+
return Elasticsearch_1.Elasticsearch.buildClient({
|
|
46
43
|
...kuzzle.config.services.storageEngine.client,
|
|
47
44
|
...clientConfig,
|
|
48
|
-
});
|
|
45
|
+
}, kuzzle.config.services.storageEngine.majorVersion);
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
48
|
return this._Client;
|
|
@@ -55,8 +52,9 @@ class BackendStorage extends index_1.ApplicationManager {
|
|
|
55
52
|
* (Currently Elasticsearch)
|
|
56
53
|
*/
|
|
57
54
|
get storageClient() {
|
|
55
|
+
const kuzzle = this._kuzzle;
|
|
58
56
|
if (!this._client) {
|
|
59
|
-
this._client =
|
|
57
|
+
this._client = Elasticsearch_1.Elasticsearch.buildClient(kuzzle.config.services.storageEngine.client, kuzzle.config.services.storageEngine.majorVersion);
|
|
60
58
|
}
|
|
61
59
|
return this._client;
|
|
62
60
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Client } from "@elastic/elasticsearch";
|
|
2
|
-
import { JSONObject } from "kuzzle-sdk";
|
|
3
1
|
import { Koncorde } from "../shared/KoncordeWrapper";
|
|
2
|
+
import { JSONObject } from "kuzzle-sdk";
|
|
4
3
|
import { KuzzleRequest, RequestContext, RequestInput } from "../../../index";
|
|
5
4
|
import { Mutex } from "../../util/mutex";
|
|
6
5
|
import { BackendCluster } from "../backend";
|
|
@@ -122,7 +121,7 @@ export declare class PluginContext {
|
|
|
122
121
|
/**
|
|
123
122
|
* Constructor for Elasticsearch SDK Client
|
|
124
123
|
*/
|
|
125
|
-
ESClient:
|
|
124
|
+
ESClient: new () => any;
|
|
126
125
|
};
|
|
127
126
|
/**
|
|
128
127
|
* @deprecated import directly: `import { BadRequestError, ... } from 'kuzzle'`
|
|
@@ -52,7 +52,7 @@ const KoncordeWrapper_1 = require("../shared/KoncordeWrapper");
|
|
|
52
52
|
const index_1 = require("../../../index");
|
|
53
53
|
const kerror = __importStar(require("../../kerror"));
|
|
54
54
|
const errors_1 = require("../../kerror/errors");
|
|
55
|
-
const
|
|
55
|
+
const Elasticsearch_1 = require("../../service/storage/Elasticsearch");
|
|
56
56
|
const mutex_1 = require("../../util/mutex");
|
|
57
57
|
const promback_1 = __importDefault(require("../../util/promback"));
|
|
58
58
|
const safeObject_1 = require("../../util/safeObject");
|
|
@@ -111,9 +111,8 @@ class PluginContext {
|
|
|
111
111
|
update: (...args) => pluginRepository.update(...args),
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
// eslint-disable-next-line no-inner-declarations
|
|
115
114
|
function PluginContextESClient() {
|
|
116
|
-
return
|
|
115
|
+
return Elasticsearch_1.Elasticsearch.buildClient(global.kuzzle.config.services.storageEngine.client);
|
|
117
116
|
}
|
|
118
117
|
this.constructors = {
|
|
119
118
|
BaseValidationType: require("../validation/baseType"),
|
|
@@ -252,7 +251,10 @@ function instantiateRequest(request, data, options = {}) {
|
|
|
252
251
|
target.input.jwt = _request.input.jwt;
|
|
253
252
|
}
|
|
254
253
|
if (_data) {
|
|
255
|
-
target.input.volatile =
|
|
254
|
+
target.input.volatile = {
|
|
255
|
+
..._request.input.volatile,
|
|
256
|
+
..._data.volatile,
|
|
257
|
+
};
|
|
256
258
|
}
|
|
257
259
|
else {
|
|
258
260
|
target.input.volatile = _request.input.volatile;
|
|
@@ -29,6 +29,7 @@ type UpdateOptions = {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
31
31
|
private module;
|
|
32
|
+
private profiles;
|
|
32
33
|
/**
|
|
33
34
|
* @constructor
|
|
34
35
|
*/
|
|
@@ -41,9 +42,7 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
41
42
|
* @returns {Promise.<Promise>}
|
|
42
43
|
* @throws {NotFoundError} If the corresponding profile doesn't exist
|
|
43
44
|
*/
|
|
44
|
-
load(id: string
|
|
45
|
-
key?: string;
|
|
46
|
-
}): Promise<Profile>;
|
|
45
|
+
load(id: string): Promise<Profile>;
|
|
47
46
|
/**
|
|
48
47
|
* Loads a Profile object given its id.
|
|
49
48
|
* Stores the promise of the profile being loaded in the memcache
|
|
@@ -141,6 +140,16 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
141
140
|
* @returns {Promise<Profile>}
|
|
142
141
|
*/
|
|
143
142
|
fromDTO(dto: JSONObject): Promise<Profile>;
|
|
143
|
+
/**
|
|
144
|
+
* @override
|
|
145
|
+
*/
|
|
146
|
+
truncate(opts: JSONObject): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Invalidate the cache entries for the given profile. If none is provided,
|
|
149
|
+
* the entire cache is emptied.
|
|
150
|
+
* @param {string} [profileId]
|
|
151
|
+
*/
|
|
152
|
+
invalidate(profileId?: string): void;
|
|
144
153
|
/**
|
|
145
154
|
* Optimize each policy to get a O(1) index access time
|
|
146
155
|
* and a O(log(n)) collection search time.
|
|
@@ -159,8 +168,8 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
159
168
|
* @param policy
|
|
160
169
|
*/
|
|
161
170
|
private optimizePolicy;
|
|
162
|
-
toDTO(dto: Profile): JSONObject
|
|
163
|
-
deleteFromDatabase(id: string, options: JSONObject): any
|
|
171
|
+
toDTO(dto: Profile): Promise<JSONObject>;
|
|
172
|
+
deleteFromDatabase(id: string, options: JSONObject): Promise<any>;
|
|
164
173
|
search(searchBody: JSONObject, options: JSONObject): Promise<{
|
|
165
174
|
aggregations: any;
|
|
166
175
|
hits: any[];
|
|
@@ -51,6 +51,7 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
|
51
51
|
const lodash_1 = require("lodash");
|
|
52
52
|
const kerror = __importStar(require("../../kerror"));
|
|
53
53
|
const profile_1 = require("../../model/security/profile");
|
|
54
|
+
const cacheDbEnum_1 = require("../cache/cacheDbEnum");
|
|
54
55
|
const ObjectRepository_1 = require("../shared/ObjectRepository");
|
|
55
56
|
/**
|
|
56
57
|
* @class ProfileRepository
|
|
@@ -61,8 +62,12 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
61
62
|
* @constructor
|
|
62
63
|
*/
|
|
63
64
|
constructor(securityModule) {
|
|
64
|
-
super({
|
|
65
|
+
super({
|
|
66
|
+
cache: cacheDbEnum_1.cacheDbEnum.NONE,
|
|
67
|
+
store: global.kuzzle.internalIndex,
|
|
68
|
+
});
|
|
65
69
|
this.module = securityModule;
|
|
70
|
+
this.profiles = new Map();
|
|
66
71
|
this.collection = "profiles";
|
|
67
72
|
this.ObjectConstructor = profile_1.Profile;
|
|
68
73
|
}
|
|
@@ -106,7 +111,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
106
111
|
*
|
|
107
112
|
* @param {String} [id] - profile identifier
|
|
108
113
|
*/
|
|
109
|
-
global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.
|
|
114
|
+
global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.invalidate(id));
|
|
110
115
|
/**
|
|
111
116
|
* Gets multiple profiles
|
|
112
117
|
* @param {Array} ids
|
|
@@ -151,18 +156,13 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
151
156
|
* @returns {Promise.<Promise>}
|
|
152
157
|
* @throws {NotFoundError} If the corresponding profile doesn't exist
|
|
153
158
|
*/
|
|
154
|
-
async load(id
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const profileFromDatabase = await this.loadOneFromDatabase(id);
|
|
158
|
-
if (profileFromDatabase !== null) {
|
|
159
|
-
await this.persistToCache(profileFromDatabase);
|
|
160
|
-
profileFromDatabase.optimizedPolicies = this.optimizePolicies(profileFromDatabase.policies);
|
|
161
|
-
}
|
|
162
|
-
return profileFromDatabase;
|
|
159
|
+
async load(id) {
|
|
160
|
+
if (this.profiles.has(id)) {
|
|
161
|
+
return this.profiles.get(id);
|
|
163
162
|
}
|
|
163
|
+
const profile = await super.load(id);
|
|
164
164
|
profile.optimizedPolicies = this.optimizePolicies(profile.policies);
|
|
165
|
-
|
|
165
|
+
this.profiles.set(id, profile);
|
|
166
166
|
return profile;
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -185,7 +185,14 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
185
185
|
throw kerror.get("api", "assert", "invalid_type", "profileIds", "string[]");
|
|
186
186
|
}
|
|
187
187
|
for (const id of profileIds) {
|
|
188
|
-
|
|
188
|
+
let profile = this.profiles.get(id);
|
|
189
|
+
if (!profile) {
|
|
190
|
+
profile = this.loadOneFromDatabase(id).then((p) => {
|
|
191
|
+
p.optimizedPolicies = this.optimizePolicies(p.policies);
|
|
192
|
+
this.profiles.set(id, p);
|
|
193
|
+
return p;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
189
196
|
profiles.push(profile);
|
|
190
197
|
}
|
|
191
198
|
return bluebird_1.default.all(profiles);
|
|
@@ -335,7 +342,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
335
342
|
}
|
|
336
343
|
}
|
|
337
344
|
await this.deleteFromDatabase(profile._id, { refresh });
|
|
338
|
-
|
|
345
|
+
this.profiles.delete(profile._id);
|
|
339
346
|
}
|
|
340
347
|
/**
|
|
341
348
|
* From a Profile object, returns a serialized object ready to be persisted
|
|
@@ -377,9 +384,9 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
377
384
|
retryOnConflict,
|
|
378
385
|
});
|
|
379
386
|
const updatedProfile = await this.loadOneFromDatabase(profile._id);
|
|
380
|
-
await this.persistToCache(updatedProfile);
|
|
381
387
|
// Recompute optimized policies based on new policies
|
|
382
388
|
updatedProfile.optimizedPolicies = this.optimizePolicies(updatedProfile.policies);
|
|
389
|
+
this.profiles.set(profile._id, updatedProfile);
|
|
383
390
|
return updatedProfile;
|
|
384
391
|
}
|
|
385
392
|
/**
|
|
@@ -403,6 +410,32 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
403
410
|
}
|
|
404
411
|
return profile;
|
|
405
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* @override
|
|
415
|
+
*/
|
|
416
|
+
async truncate(opts) {
|
|
417
|
+
try {
|
|
418
|
+
await super.truncate(opts);
|
|
419
|
+
}
|
|
420
|
+
finally {
|
|
421
|
+
// always clear the RAM cache: even if truncate fails in the middle of it,
|
|
422
|
+
// some of the cached profiles might not be valid anymore
|
|
423
|
+
this.invalidate();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Invalidate the cache entries for the given profile. If none is provided,
|
|
428
|
+
* the entire cache is emptied.
|
|
429
|
+
* @param {string} [profileId]
|
|
430
|
+
*/
|
|
431
|
+
invalidate(profileId) {
|
|
432
|
+
if (!profileId) {
|
|
433
|
+
this.profiles.clear();
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
this.profiles.delete(profileId);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
406
439
|
/**
|
|
407
440
|
* Optimize each policy to get a O(1) index access time
|
|
408
441
|
* and a O(log(n)) collection search time.
|
|
@@ -463,10 +496,10 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
463
496
|
// Every method described after are for testing purpose only
|
|
464
497
|
// Otherwise we cannot stub them
|
|
465
498
|
// ============================================
|
|
466
|
-
toDTO(dto) {
|
|
499
|
+
async toDTO(dto) {
|
|
467
500
|
return super.toDTO(dto);
|
|
468
501
|
}
|
|
469
|
-
deleteFromDatabase(id, options) {
|
|
502
|
+
async deleteFromDatabase(id, options) {
|
|
470
503
|
return super.deleteFromDatabase(id, options);
|
|
471
504
|
}
|
|
472
505
|
async search(searchBody, options) {
|
|
@@ -127,7 +127,7 @@ class ObjectRepository {
|
|
|
127
127
|
let response;
|
|
128
128
|
try {
|
|
129
129
|
response = await global.kuzzle.ask(`core:cache:${this.cacheDb}:get`, key);
|
|
130
|
-
if (response === null
|
|
130
|
+
if (response === null) {
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
return await this.fromDTO({ ...JSON.parse(response) });
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
"use strict";
|
|
23
23
|
|
|
24
|
-
const Elasticsearch = require("../../service/storage/
|
|
24
|
+
const { Elasticsearch } = require("../../service/storage/Elasticsearch");
|
|
25
25
|
const { IndexCache } = require("./indexCache");
|
|
26
26
|
const { isPlainObject } = require("../../util/safeObject");
|
|
27
27
|
const kerror = require("../../kerror");
|
|
@@ -38,16 +38,17 @@ class ClientAdapter {
|
|
|
38
38
|
* @param {storeScopeEnum} scope
|
|
39
39
|
*/
|
|
40
40
|
constructor(scope) {
|
|
41
|
-
this.
|
|
41
|
+
this.es = new Elasticsearch(
|
|
42
42
|
global.kuzzle.config.services.storageEngine,
|
|
43
43
|
scope,
|
|
44
44
|
);
|
|
45
|
+
this.client = this.es.client;
|
|
45
46
|
this.scope = scope;
|
|
46
47
|
this.cache = new IndexCache();
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
async init() {
|
|
50
|
-
await this.
|
|
51
|
+
await this.es.init();
|
|
51
52
|
await this.populateCache();
|
|
52
53
|
|
|
53
54
|
this.registerCollectionEvents();
|
|
@@ -202,6 +203,7 @@ class ClientAdapter {
|
|
|
202
203
|
* @return {Promise}
|
|
203
204
|
* @throws
|
|
204
205
|
*/
|
|
206
|
+
|
|
205
207
|
global.kuzzle.onAsk(
|
|
206
208
|
`core:storage:${this.scope}:collection:create`,
|
|
207
209
|
(index, collection, opts, creationOptions) =>
|
|
@@ -454,7 +456,7 @@ class ClientAdapter {
|
|
|
454
456
|
* @param {string} collection
|
|
455
457
|
* @param {Object} query
|
|
456
458
|
* @param {Object} [opts] -- see Elasticsearch "deleteByQuery" options
|
|
457
|
-
* @returns {Promise.<{ documents, total, deleted, failures: [
|
|
459
|
+
* @returns {Promise.<{ documents, total, deleted, failures: [ id, reason ] }>}
|
|
458
460
|
*/
|
|
459
461
|
global.kuzzle.onAsk(
|
|
460
462
|
`core:storage:${this.scope}:document:deleteByQuery`,
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
|
|
22
22
|
"use strict";
|
|
23
23
|
|
|
24
|
-
const Bluebird = require("bluebird");
|
|
25
|
-
|
|
26
24
|
const kerror = require("../../kerror").wrap("services", "storage");
|
|
27
25
|
const ClientAdapter = require("./clientAdapter");
|
|
28
26
|
const { storeScopeEnum } = require("./storeScopeEnum");
|
|
@@ -42,11 +40,12 @@ class StorageEngine {
|
|
|
42
40
|
* @returns {Promise}
|
|
43
41
|
*/
|
|
44
42
|
async init() {
|
|
45
|
-
await
|
|
43
|
+
await Promise.all([this.public.init(), this.private.init()]);
|
|
46
44
|
|
|
47
|
-
const privateIndexes =
|
|
45
|
+
const privateIndexes = this.private.cache.listIndexes();
|
|
46
|
+
const publicIndexes = this.public.cache.listIndexes();
|
|
48
47
|
|
|
49
|
-
for (const publicIndex of
|
|
48
|
+
for (const publicIndex of publicIndexes) {
|
|
50
49
|
if (privateIndexes.includes(publicIndex)) {
|
|
51
50
|
throw kerror.get("index_already_exists", "public", publicIndex);
|
|
52
51
|
}
|
package/lib/kuzzle/kuzzle.js
CHANGED
|
@@ -240,7 +240,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
240
240
|
* @returns {Promise<void>}
|
|
241
241
|
*/
|
|
242
242
|
async install(installations) {
|
|
243
|
-
if (!installations
|
|
243
|
+
if (!installations?.length) {
|
|
244
244
|
return;
|
|
245
245
|
}
|
|
246
246
|
const mutex = new mutex_1.Mutex("backend:installations");
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import { RequestParams, Client
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { storeScopeEnum } from "../../core/storage/storeScopeEnum";
|
|
6
|
-
import Service from "../service";
|
|
2
|
+
import { RequestParams, Client } from "sdk-es7";
|
|
3
|
+
import { TypeMapping } from "sdk-es7/api/types";
|
|
4
|
+
import { JSONObject, KRequestBody, KRequestParams } from "../../../types/storage/7/Elasticsearch";
|
|
7
5
|
import ESWrapper from "./esWrapper";
|
|
8
|
-
import QueryTranslator from "
|
|
6
|
+
import QueryTranslator from "../commons/queryTranslator";
|
|
7
|
+
import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
|
|
9
8
|
/**
|
|
10
9
|
* @param {Kuzzle} kuzzle kuzzle instance
|
|
11
10
|
* @param {Object} config Service configuration
|
|
12
11
|
* @param {storeScopeEnum} scope
|
|
13
12
|
* @constructor
|
|
14
13
|
*/
|
|
15
|
-
export
|
|
16
|
-
_client:
|
|
14
|
+
export declare class ES7 {
|
|
15
|
+
_client: Client;
|
|
17
16
|
_scope: storeScopeEnum;
|
|
18
17
|
_indexPrefix: string;
|
|
19
18
|
_esWrapper: ESWrapper;
|
|
@@ -25,12 +24,6 @@ export default class ElasticSearch extends Service {
|
|
|
25
24
|
maxScrollDuration: number;
|
|
26
25
|
scrollTTL: number;
|
|
27
26
|
_config: any;
|
|
28
|
-
/**
|
|
29
|
-
* Returns a new elasticsearch client instance
|
|
30
|
-
*
|
|
31
|
-
* @returns {Object}
|
|
32
|
-
*/
|
|
33
|
-
static buildClient(config: any): StorageClient;
|
|
34
27
|
constructor(config: any, scope?: storeScopeEnum);
|
|
35
28
|
get scope(): storeScopeEnum;
|
|
36
29
|
/**
|
|
@@ -77,7 +70,15 @@ export default class ElasticSearch extends Service {
|
|
|
77
70
|
scrollTTL?: string;
|
|
78
71
|
}): Promise<{
|
|
79
72
|
aggregations: any;
|
|
80
|
-
hits:
|
|
73
|
+
hits: {
|
|
74
|
+
_id: any;
|
|
75
|
+
_score: any;
|
|
76
|
+
_source: any;
|
|
77
|
+
collection: any;
|
|
78
|
+
highlight: any;
|
|
79
|
+
index: any;
|
|
80
|
+
inner_hits: {};
|
|
81
|
+
}[];
|
|
81
82
|
remaining: any;
|
|
82
83
|
scrollId: any;
|
|
83
84
|
suggest: any;
|
|
@@ -104,7 +105,15 @@ export default class ElasticSearch extends Service {
|
|
|
104
105
|
scroll?: string;
|
|
105
106
|
}): Promise<{
|
|
106
107
|
aggregations: any;
|
|
107
|
-
hits:
|
|
108
|
+
hits: {
|
|
109
|
+
_id: any;
|
|
110
|
+
_score: any;
|
|
111
|
+
_source: any;
|
|
112
|
+
collection: any;
|
|
113
|
+
highlight: any;
|
|
114
|
+
index: any;
|
|
115
|
+
inner_hits: {};
|
|
116
|
+
}[];
|
|
108
117
|
remaining: any;
|
|
109
118
|
scrollId: any;
|
|
110
119
|
suggest: any;
|
|
@@ -119,7 +128,15 @@ export default class ElasticSearch extends Service {
|
|
|
119
128
|
_mapTargetsToAlias(targets: any): {};
|
|
120
129
|
_formatSearchResult(body: any, searchInfo?: any): Promise<{
|
|
121
130
|
aggregations: any;
|
|
122
|
-
hits:
|
|
131
|
+
hits: {
|
|
132
|
+
_id: any;
|
|
133
|
+
_score: any;
|
|
134
|
+
_source: any;
|
|
135
|
+
collection: any;
|
|
136
|
+
highlight: any;
|
|
137
|
+
index: any;
|
|
138
|
+
inner_hits: {};
|
|
139
|
+
}[];
|
|
123
140
|
remaining: any;
|
|
124
141
|
scrollId: any;
|
|
125
142
|
suggest: any;
|
|
@@ -187,7 +204,7 @@ export default class ElasticSearch extends Service {
|
|
|
187
204
|
_version: any;
|
|
188
205
|
}>;
|
|
189
206
|
/**
|
|
190
|
-
* Creates a new document to
|
|
207
|
+
* Creates a new document to Elasticsearch, or replace it if it already exist
|
|
191
208
|
*
|
|
192
209
|
* @param {String} index - Index name
|
|
193
210
|
* @param {String} collection - Collection name
|
|
@@ -253,7 +270,7 @@ export default class ElasticSearch extends Service {
|
|
|
253
270
|
created: boolean;
|
|
254
271
|
}>;
|
|
255
272
|
/**
|
|
256
|
-
* Replaces a document to
|
|
273
|
+
* Replaces a document to Elasticsearch
|
|
257
274
|
*
|
|
258
275
|
* @param {String} index - Index name
|
|
259
276
|
* @param {String} collection - Collection name
|
|
@@ -559,7 +576,7 @@ export default class ElasticSearch extends Service {
|
|
|
559
576
|
*
|
|
560
577
|
* @returns {Promise.<String[]>}
|
|
561
578
|
*/
|
|
562
|
-
deleteIndexes(indexes?: string[]): Promise<any>;
|
|
579
|
+
deleteIndexes(indexes?: string[]): Promise<any[]>;
|
|
563
580
|
/**
|
|
564
581
|
* Deletes an index
|
|
565
582
|
*
|
|
@@ -830,7 +847,7 @@ export default class ElasticSearch extends Service {
|
|
|
830
847
|
* @returns {String} Alias name (eg: '@&nepali.liia')
|
|
831
848
|
* @throws If there is not exactly one alias associated that is prefixed with @
|
|
832
849
|
*/
|
|
833
|
-
_getAliasFromIndice(indice:
|
|
850
|
+
_getAliasFromIndice(indice: string): Promise<string[]>;
|
|
834
851
|
/**
|
|
835
852
|
* Check for each indice whether it has an alias or not.
|
|
836
853
|
* When the latter is missing, create one based on the indice name.
|
|
@@ -870,7 +887,7 @@ export default class ElasticSearch extends Service {
|
|
|
870
887
|
*
|
|
871
888
|
* @returns {Object.<String, String[]>} Indexes as key and an array of their collections as value
|
|
872
889
|
*/
|
|
873
|
-
_extractSchema(aliases:
|
|
890
|
+
_extractSchema(aliases: string[], { includeHidden }?: {
|
|
874
891
|
includeHidden?: boolean;
|
|
875
892
|
}): {};
|
|
876
893
|
/**
|
|
@@ -953,4 +970,5 @@ export default class ElasticSearch extends Service {
|
|
|
953
970
|
_checkDynamicProperty(mappings: any): void;
|
|
954
971
|
_setLastActionToKuzzleMeta(esRequest: JSONObject, alias: string, kuzzleMeta: JSONObject): void;
|
|
955
972
|
_setLastActionToKuzzleMetaUpdate(item: JSONObject, kuzzleMeta: JSONObject): void;
|
|
973
|
+
_getRandomNumber(number: number): number;
|
|
956
974
|
}
|