kuzzle 2.19.2 → 2.19.3
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/adminController.js +94 -80
- package/lib/api/controllers/authController.js +239 -212
- package/lib/api/controllers/baseController.js +89 -51
- package/lib/api/controllers/bulkController.js +62 -49
- package/lib/api/controllers/clusterController.js +6 -8
- package/lib/api/controllers/collectionController.js +140 -129
- package/lib/api/controllers/debugController.d.ts +2 -2
- package/lib/api/controllers/debugController.js +33 -31
- package/lib/api/controllers/documentController.js +365 -274
- package/lib/api/controllers/index.js +13 -13
- package/lib/api/controllers/indexController.js +46 -50
- package/lib/api/controllers/memoryStorageController.js +410 -360
- package/lib/api/controllers/realtimeController.js +37 -36
- package/lib/api/controllers/securityController.js +553 -412
- package/lib/api/controllers/serverController.js +111 -104
- package/lib/api/documentExtractor.js +75 -68
- package/lib/api/funnel.js +411 -312
- package/lib/api/httpRoutes.js +1493 -324
- package/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/lib/api/openapi/OpenApiManager.js +22 -22
- package/lib/api/openapi/components/document/count.yaml +1 -1
- package/lib/api/openapi/components/document/create.yaml +2 -2
- package/lib/api/openapi/components/document/delete.yaml +1 -1
- package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
- package/lib/api/openapi/components/document/exists.yaml +1 -1
- package/lib/api/openapi/components/document/get.yaml +2 -2
- package/lib/api/openapi/components/document/index.js +12 -12
- package/lib/api/openapi/components/document/replace.yaml +1 -1
- package/lib/api/openapi/components/document/scroll.yaml +1 -1
- package/lib/api/openapi/components/document/validate.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +2 -2
- package/lib/api/openapi/components/index.js +1 -1
- package/lib/api/openapi/components/security/index.js +1 -1
- package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
- package/lib/api/openapi/index.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.js +7 -7
- package/lib/api/rateLimiter.js +12 -13
- package/lib/api/request/index.d.ts +4 -4
- package/lib/api/request/kuzzleRequest.d.ts +9 -9
- package/lib/api/request/kuzzleRequest.js +89 -87
- package/lib/api/request/requestContext.d.ts +2 -2
- package/lib/api/request/requestContext.js +17 -17
- package/lib/api/request/requestInput.d.ts +1 -1
- package/lib/api/request/requestInput.js +19 -19
- package/lib/api/request/requestResponse.d.ts +4 -4
- package/lib/api/request/requestResponse.js +31 -33
- package/lib/cluster/command.js +48 -44
- package/lib/cluster/idCardHandler.d.ts +1 -1
- package/lib/cluster/idCardHandler.js +15 -15
- package/lib/cluster/index.js +2 -2
- package/lib/cluster/node.js +301 -269
- package/lib/cluster/publisher.js +45 -46
- package/lib/cluster/state.d.ts +5 -5
- package/lib/cluster/state.js +8 -8
- package/lib/cluster/subscriber.js +163 -113
- package/lib/cluster/workers/IDCardRenewer.js +33 -32
- package/lib/config/default.config.d.ts +1 -1
- package/lib/config/default.config.js +212 -171
- package/lib/config/documentEventAliases.js +6 -6
- package/lib/config/index.js +161 -98
- package/lib/config/sdkCompatibility.json +8 -8
- package/lib/core/auth/formatProcessing.js +7 -7
- package/lib/core/auth/passportResponse.js +7 -7
- package/lib/core/auth/passportWrapper.js +34 -30
- package/lib/core/auth/tokenManager.d.ts +2 -2
- package/lib/core/auth/tokenManager.js +11 -10
- package/lib/core/backend/applicationManager.d.ts +1 -1
- package/lib/core/backend/applicationManager.js +2 -2
- package/lib/core/backend/backend.d.ts +3 -3
- package/lib/core/backend/backend.js +34 -31
- package/lib/core/backend/backendCluster.d.ts +2 -2
- package/lib/core/backend/backendCluster.js +5 -5
- package/lib/core/backend/backendConfig.d.ts +2 -2
- package/lib/core/backend/backendConfig.js +3 -3
- package/lib/core/backend/backendController.d.ts +2 -2
- package/lib/core/backend/backendController.js +9 -10
- package/lib/core/backend/backendErrors.d.ts +3 -3
- package/lib/core/backend/backendErrors.js +2 -1
- package/lib/core/backend/backendHook.d.ts +2 -2
- package/lib/core/backend/backendHook.js +5 -5
- package/lib/core/backend/backendImport.d.ts +3 -3
- package/lib/core/backend/backendImport.js +23 -23
- package/lib/core/backend/backendOpenApi.d.ts +2 -2
- package/lib/core/backend/backendOpenApi.js +16 -16
- package/lib/core/backend/backendPipe.d.ts +2 -2
- package/lib/core/backend/backendPipe.js +6 -6
- package/lib/core/backend/backendPlugin.d.ts +4 -4
- package/lib/core/backend/backendPlugin.js +14 -14
- package/lib/core/backend/backendStorage.d.ts +2 -2
- package/lib/core/backend/backendStorage.js +1 -2
- package/lib/core/backend/backendVault.d.ts +2 -2
- package/lib/core/backend/backendVault.js +3 -3
- package/lib/core/backend/index.d.ts +14 -14
- package/lib/core/backend/internalLogger.d.ts +1 -1
- package/lib/core/backend/internalLogger.js +5 -5
- package/lib/core/cache/cacheDbEnum.js +4 -4
- package/lib/core/cache/cacheEngine.js +79 -85
- package/lib/core/network/accessLogger.js +126 -120
- package/lib/core/network/clientConnection.js +5 -5
- package/lib/core/network/context.js +8 -8
- package/lib/core/network/entryPoint.js +100 -85
- package/lib/core/network/httpRouter/index.js +63 -60
- package/lib/core/network/httpRouter/routeHandler.js +18 -19
- package/lib/core/network/httpRouter/routePart.js +23 -19
- package/lib/core/network/protocolManifest.js +3 -3
- package/lib/core/network/protocols/httpMessage.js +8 -10
- package/lib/core/network/protocols/httpwsProtocol.js +305 -250
- package/lib/core/network/protocols/internalProtocol.js +27 -24
- package/lib/core/network/protocols/mqttProtocol.js +106 -96
- package/lib/core/network/protocols/protocol.js +20 -17
- package/lib/core/network/router.js +56 -46
- package/lib/core/plugin/plugin.js +151 -120
- package/lib/core/plugin/pluginContext.d.ts +7 -7
- package/lib/core/plugin/pluginContext.js +48 -44
- package/lib/core/plugin/pluginManifest.js +13 -12
- package/lib/core/plugin/pluginRepository.js +26 -27
- package/lib/core/plugin/pluginsManager.js +425 -304
- package/lib/core/plugin/privilegedContext.js +3 -3
- package/lib/core/realtime/actionEnum.js +1 -1
- package/lib/core/realtime/channel.d.ts +1 -1
- package/lib/core/realtime/channel.js +22 -22
- package/lib/core/realtime/connectionRooms.d.ts +1 -1
- package/lib/core/realtime/hotelClerk.d.ts +2 -2
- package/lib/core/realtime/hotelClerk.js +53 -50
- package/lib/core/realtime/index.js +5 -5
- package/lib/core/realtime/notification/document.js +25 -25
- package/lib/core/realtime/notification/index.js +4 -4
- package/lib/core/realtime/notification/server.js +3 -3
- package/lib/core/realtime/notification/user.js +4 -4
- package/lib/core/realtime/notifier.js +113 -75
- package/lib/core/realtime/room.d.ts +1 -1
- package/lib/core/realtime/subscription.d.ts +1 -1
- package/lib/core/realtime/subscription.js +1 -1
- package/lib/core/security/index.js +8 -8
- package/lib/core/security/profileRepository.d.ts +6 -6
- package/lib/core/security/profileRepository.js +48 -45
- package/lib/core/security/roleRepository.js +127 -115
- package/lib/core/security/securityLoader.js +70 -63
- package/lib/core/security/tokenRepository.js +132 -118
- package/lib/core/security/userRepository.js +104 -88
- package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/lib/core/shared/KoncordeWrapper.js +3 -1
- package/lib/core/shared/abstractManifest.js +22 -23
- package/lib/core/shared/repository.js +69 -67
- package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
- package/lib/core/shared/sdk/embeddedSdk.js +36 -32
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
- package/lib/core/shared/sdk/funnelProtocol.js +11 -11
- package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
- package/lib/core/shared/store.js +127 -32
- package/lib/core/statistics/index.js +2 -2
- package/lib/core/statistics/statistics.js +99 -85
- package/lib/core/storage/clientAdapter.js +219 -136
- package/lib/core/storage/indexCache.js +3 -3
- package/lib/core/storage/storageEngine.js +10 -13
- package/lib/core/storage/storeScopeEnum.js +3 -3
- package/lib/core/validation/baseType.js +12 -10
- package/lib/core/validation/index.js +2 -2
- package/lib/core/validation/types/anything.js +4 -4
- package/lib/core/validation/types/boolean.js +7 -7
- package/lib/core/validation/types/date.js +165 -131
- package/lib/core/validation/types/email.js +18 -21
- package/lib/core/validation/types/enum.js +34 -21
- package/lib/core/validation/types/geoPoint.js +7 -7
- package/lib/core/validation/types/geoShape.js +148 -125
- package/lib/core/validation/types/integer.js +9 -9
- package/lib/core/validation/types/ipAddress.js +17 -19
- package/lib/core/validation/types/numeric.js +36 -29
- package/lib/core/validation/types/object.js +19 -19
- package/lib/core/validation/types/string.js +36 -29
- package/lib/core/validation/types/url.js +17 -19
- package/lib/core/validation/validation.js +422 -378
- package/lib/kerror/codes/1-services.json +7 -1
- package/lib/kerror/codes/4-plugin.json +2 -2
- package/lib/kerror/codes/index.js +85 -63
- package/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/lib/kerror/errors/index.d.ts +15 -15
- package/lib/kerror/errors/internalError.d.ts +1 -1
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +1 -1
- package/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/lib/kerror/errors/partialError.d.ts +1 -1
- package/lib/kerror/errors/partialError.js +1 -1
- package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
- package/lib/kerror/errors/pluginImplementationError.js +2 -1
- package/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/lib/kerror/index.d.ts +3 -3
- package/lib/kerror/index.js +17 -16
- package/lib/kuzzle/dumpGenerator.js +130 -114
- package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
- package/lib/kuzzle/event/pipeRunner.js +25 -24
- package/lib/kuzzle/event/waterfall.js +13 -15
- package/lib/kuzzle/index.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +80 -59
- package/lib/kuzzle/kuzzle.js +99 -99
- package/lib/kuzzle/kuzzleStateEnum.js +1 -1
- package/lib/kuzzle/log.js +23 -18
- package/lib/kuzzle/vault.js +34 -19
- package/lib/model/security/profile.d.ts +3 -3
- package/lib/model/security/profile.js +38 -37
- package/lib/model/security/rights.js +5 -5
- package/lib/model/security/role.d.ts +3 -3
- package/lib/model/security/role.js +25 -26
- package/lib/model/security/token.d.ts +1 -1
- package/lib/model/security/token.js +4 -4
- package/lib/model/security/user.d.ts +2 -2
- package/lib/model/security/user.js +9 -9
- package/lib/model/storage/apiKey.js +43 -33
- package/lib/model/storage/baseModel.js +49 -45
- package/lib/service/cache/redis.js +60 -55
- package/lib/service/service.js +17 -17
- package/lib/service/storage/elasticsearch.js +839 -755
- package/lib/service/storage/esWrapper.js +103 -86
- package/lib/service/storage/queryTranslator.js +52 -59
- package/lib/types/Controller.d.ts +3 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/DebugModule.d.ts +2 -2
- package/lib/types/DebugModule.js +1 -1
- package/lib/types/Global.d.ts +1 -1
- package/lib/types/HttpStream.d.ts +2 -1
- package/lib/types/HttpStream.js +7 -5
- package/lib/types/Kuzzle.d.ts +1 -1
- package/lib/types/KuzzleDocument.d.ts +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -1
- package/lib/types/PasswordPolicy.d.ts +1 -1
- package/lib/types/Plugin.d.ts +6 -6
- package/lib/types/Plugin.js +2 -2
- package/lib/types/Policy.d.ts +1 -1
- package/lib/types/RequestPayload.d.ts +1 -1
- package/lib/types/ResponsePayload.d.ts +1 -1
- package/lib/types/Token.d.ts +1 -1
- package/lib/types/User.d.ts +1 -1
- package/lib/types/config/DumpConfiguration.d.ts +8 -8
- package/lib/types/config/HttpConfiguration.d.ts +1 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
- package/lib/types/config/LimitsConfiguration.d.ts +8 -8
- package/lib/types/config/PluginsConfiguration.d.ts +4 -4
- package/lib/types/config/SecurityConfiguration.d.ts +62 -62
- package/lib/types/config/ServerConfiguration.d.ts +55 -55
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
- package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
- package/lib/types/errors/ErrorDefinition.d.ts +1 -1
- package/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/lib/types/index.d.ts +38 -38
- package/lib/types/realtime/RealtimeScope.d.ts +1 -1
- package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
- package/lib/util/assertType.js +13 -11
- package/lib/util/async.d.ts +1 -0
- package/lib/util/async.js +61 -0
- package/lib/util/asyncStore.js +19 -21
- package/lib/util/bufferedPassThrough.d.ts +2 -2
- package/lib/util/bufferedPassThrough.js +4 -4
- package/lib/util/bytes.js +9 -13
- package/lib/util/crypto.js +1 -1
- package/lib/util/debug.js +5 -5
- package/lib/util/deprecate.js +24 -21
- package/lib/util/didYouMean.js +7 -7
- package/lib/util/dump-collection.d.ts +2 -2
- package/lib/util/dump-collection.js +26 -26
- package/lib/util/esRequest.d.ts +1 -0
- package/lib/util/esRequest.js +62 -0
- package/lib/util/extractFields.js +24 -25
- package/lib/util/inflector.js +5 -5
- package/lib/util/koncordeCompat.d.ts +2 -2
- package/lib/util/koncordeCompat.js +5 -5
- package/lib/util/memoize.js +3 -5
- package/lib/util/mutex.d.ts +19 -1
- package/lib/util/mutex.js +39 -12
- package/lib/util/name-generator.js +1331 -1331
- package/lib/util/promback.js +8 -10
- package/lib/util/readYamlFile.d.ts +1 -1
- package/lib/util/readYamlFile.js +1 -1
- package/lib/util/requestAssertions.js +34 -34
- package/lib/util/safeObject.js +5 -5
- package/lib/util/stackTrace.js +20 -22
- package/lib/util/wildcard.js +15 -15
- package/package.json +6 -6
- package/npm-shrinkwrap.json +0 -19422
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const Elasticsearch = require(
|
|
25
|
-
const { IndexCache } = require(
|
|
26
|
-
const { isPlainObject } = require(
|
|
27
|
-
const kerror = require(
|
|
28
|
-
const { Mutex } = require(
|
|
24
|
+
const Elasticsearch = require("../../service/storage/elasticsearch");
|
|
25
|
+
const { IndexCache } = require("./indexCache");
|
|
26
|
+
const { isPlainObject } = require("../../util/safeObject");
|
|
27
|
+
const kerror = require("../../kerror");
|
|
28
|
+
const { Mutex } = require("../../util/mutex");
|
|
29
29
|
|
|
30
|
-
const servicesError = kerror.wrap(
|
|
30
|
+
const servicesError = kerror.wrap("services", "storage");
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Storage client adapter to perform validation on index/collection existence
|
|
@@ -37,15 +37,16 @@ class ClientAdapter {
|
|
|
37
37
|
/**
|
|
38
38
|
* @param {storeScopeEnum} scope
|
|
39
39
|
*/
|
|
40
|
-
constructor
|
|
40
|
+
constructor(scope) {
|
|
41
41
|
this.client = new Elasticsearch(
|
|
42
42
|
global.kuzzle.config.services.storageEngine,
|
|
43
|
-
scope
|
|
43
|
+
scope
|
|
44
|
+
);
|
|
44
45
|
this.scope = scope;
|
|
45
46
|
this.cache = new IndexCache();
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
async init
|
|
49
|
+
async init() {
|
|
49
50
|
await this.client.init();
|
|
50
51
|
await this.populateCache();
|
|
51
52
|
|
|
@@ -60,17 +61,17 @@ class ClientAdapter {
|
|
|
60
61
|
/**
|
|
61
62
|
* Manually refresh the index cache (e.g. after alias creation)
|
|
62
63
|
*/
|
|
63
|
-
global.kuzzle.onAsk(
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:cache:refresh`, () =>
|
|
65
|
+
this.populateCache()
|
|
66
|
+
);
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* Return information about the instantiated ES service
|
|
69
70
|
* @returns {Promise.<Object>}
|
|
70
71
|
*/
|
|
71
|
-
global.kuzzle.onAsk(
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:info:get`, () =>
|
|
73
|
+
this.client.info()
|
|
74
|
+
);
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
77
|
* Translate Koncorde filters to Elasticsearch query
|
|
@@ -78,45 +79,44 @@ class ClientAdapter {
|
|
|
78
79
|
* @param {Object} koncordeFilters - Set of valid Koncorde filters
|
|
79
80
|
* @returns {Object} Equivalent Elasticsearch query
|
|
80
81
|
*/
|
|
81
|
-
global.kuzzle.onAsk(`core:storage:${this.scope}:translate`, filters =>
|
|
82
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:translate`, (filters) =>
|
|
82
83
|
this.client.translateKoncordeFilters(filters)
|
|
83
|
-
)
|
|
84
|
+
);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
async createIndex
|
|
87
|
+
async createIndex(index, { indexCacheOnly = false, propagate = true } = {}) {
|
|
87
88
|
if (this.cache.hasIndex(index)) {
|
|
88
|
-
throw servicesError.get(
|
|
89
|
+
throw servicesError.get("index_already_exists", this.scope, index);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
if (!
|
|
92
|
+
if (!indexCacheOnly) {
|
|
92
93
|
await this.client.createIndex(index);
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
this.cache.addIndex(index);
|
|
96
97
|
|
|
97
98
|
if (propagate) {
|
|
98
|
-
global.kuzzle.emit(
|
|
99
|
+
global.kuzzle.emit("core:storage:index:create:after", {
|
|
99
100
|
index,
|
|
100
101
|
scope: this.scope,
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
async createCollection
|
|
106
|
+
async createCollection(
|
|
106
107
|
index,
|
|
107
108
|
collection,
|
|
108
109
|
opts,
|
|
109
|
-
{ indexCacheOnly = false, propagate = true } = {}
|
|
110
|
+
{ indexCacheOnly = false, propagate = true } = {}
|
|
110
111
|
) {
|
|
111
|
-
|
|
112
|
-
if (! indexCacheOnly) {
|
|
112
|
+
if (!indexCacheOnly) {
|
|
113
113
|
await this.client.createCollection(index, collection, opts);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
this.cache.addCollection(index, collection);
|
|
117
117
|
|
|
118
118
|
if (propagate) {
|
|
119
|
-
global.kuzzle.emit(
|
|
119
|
+
global.kuzzle.emit("core:storage:collection:create:after", {
|
|
120
120
|
collection,
|
|
121
121
|
index,
|
|
122
122
|
scope: this.scope,
|
|
@@ -124,20 +124,20 @@ class ClientAdapter {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
async deleteIndex
|
|
127
|
+
async deleteIndex(index) {
|
|
128
128
|
this.cache.assertIndexExists(index);
|
|
129
129
|
|
|
130
130
|
await this.client.deleteIndex(index);
|
|
131
131
|
|
|
132
132
|
this.cache.removeIndex(index);
|
|
133
133
|
|
|
134
|
-
global.kuzzle.emit(
|
|
134
|
+
global.kuzzle.emit("core:storage:index:delete:after", {
|
|
135
135
|
index,
|
|
136
136
|
scope: this.scope,
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
async deleteIndexes
|
|
140
|
+
async deleteIndexes(indexes) {
|
|
141
141
|
for (const index of indexes) {
|
|
142
142
|
this.cache.assertIndexExists(index);
|
|
143
143
|
}
|
|
@@ -149,7 +149,7 @@ class ClientAdapter {
|
|
|
149
149
|
this.cache.removeIndex(index);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
global.kuzzle.emit(
|
|
152
|
+
global.kuzzle.emit("core:storage:index:mDelete:after", {
|
|
153
153
|
indexes: deleted,
|
|
154
154
|
scope: this.scope,
|
|
155
155
|
});
|
|
@@ -158,14 +158,14 @@ class ClientAdapter {
|
|
|
158
158
|
return deleted;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
async deleteCollection
|
|
161
|
+
async deleteCollection(index, collection) {
|
|
162
162
|
this.cache.assertCollectionExists(index, collection);
|
|
163
163
|
|
|
164
164
|
await this.client.deleteCollection(index, collection);
|
|
165
165
|
|
|
166
166
|
this.cache.removeCollection(index, collection);
|
|
167
167
|
|
|
168
|
-
global.kuzzle.emit(
|
|
168
|
+
global.kuzzle.emit("core:storage:collection:delete:after", {
|
|
169
169
|
collection,
|
|
170
170
|
index,
|
|
171
171
|
scope: this.scope,
|
|
@@ -178,7 +178,7 @@ class ClientAdapter {
|
|
|
178
178
|
*
|
|
179
179
|
* @returns {Promise}
|
|
180
180
|
*/
|
|
181
|
-
async populateCache
|
|
181
|
+
async populateCache() {
|
|
182
182
|
const schema = await this.client.getSchema();
|
|
183
183
|
|
|
184
184
|
for (const [index, collections] of Object.entries(schema)) {
|
|
@@ -190,7 +190,7 @@ class ClientAdapter {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
registerCollectionEvents
|
|
193
|
+
registerCollectionEvents() {
|
|
194
194
|
/**
|
|
195
195
|
* Create a new collection in a given index, and optionally configure it
|
|
196
196
|
* @param {string} index
|
|
@@ -202,7 +202,9 @@ class ClientAdapter {
|
|
|
202
202
|
*/
|
|
203
203
|
global.kuzzle.onAsk(
|
|
204
204
|
`core:storage:${this.scope}:collection:create`,
|
|
205
|
-
(index, collection, opts, creationOptions) =>
|
|
205
|
+
(index, collection, opts, creationOptions) =>
|
|
206
|
+
this.createCollection(index, collection, opts, creationOptions)
|
|
207
|
+
);
|
|
206
208
|
|
|
207
209
|
/**
|
|
208
210
|
* Delete a collection
|
|
@@ -213,7 +215,21 @@ class ClientAdapter {
|
|
|
213
215
|
*/
|
|
214
216
|
global.kuzzle.onAsk(
|
|
215
217
|
`core:storage:${this.scope}:collection:delete`,
|
|
216
|
-
(index, collection) => this.deleteCollection(index, collection)
|
|
218
|
+
(index, collection) => this.deleteCollection(index, collection)
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get settings of a collection
|
|
223
|
+
* @param {string} index
|
|
224
|
+
* @param {string} collection
|
|
225
|
+
*/
|
|
226
|
+
global.kuzzle.onAsk(
|
|
227
|
+
`core:storage:${this.scope}:collection:settings:get`,
|
|
228
|
+
(index, collection) => {
|
|
229
|
+
this.cache.assertCollectionExists(index, collection);
|
|
230
|
+
return this.client.getSettings(index, collection);
|
|
231
|
+
}
|
|
232
|
+
);
|
|
217
233
|
|
|
218
234
|
/**
|
|
219
235
|
* Check a collection existence
|
|
@@ -222,16 +238,17 @@ class ClientAdapter {
|
|
|
222
238
|
*/
|
|
223
239
|
global.kuzzle.onAsk(
|
|
224
240
|
`core:storage:${this.scope}:collection:exist`,
|
|
225
|
-
(index, collection) => this.cache.hasCollection(index, collection)
|
|
241
|
+
(index, collection) => this.cache.hasCollection(index, collection)
|
|
242
|
+
);
|
|
226
243
|
|
|
227
244
|
/**
|
|
228
245
|
* Return a list of an index' collections within this adapter's scope
|
|
229
246
|
* @param {string} index
|
|
230
247
|
* @returns {Promise.<string[]>}
|
|
231
248
|
*/
|
|
232
|
-
global.kuzzle.onAsk(
|
|
233
|
-
|
|
234
|
-
|
|
249
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:collection:list`, (index) =>
|
|
250
|
+
this.cache.listCollections(index)
|
|
251
|
+
);
|
|
235
252
|
|
|
236
253
|
/**
|
|
237
254
|
* Refresh a collection
|
|
@@ -244,7 +261,8 @@ class ClientAdapter {
|
|
|
244
261
|
(index, collection) => {
|
|
245
262
|
this.cache.assertCollectionExists(index, collection);
|
|
246
263
|
return this.client.refreshCollection(index, collection);
|
|
247
|
-
}
|
|
264
|
+
}
|
|
265
|
+
);
|
|
248
266
|
|
|
249
267
|
/**
|
|
250
268
|
* Remove all documents from an existing collection
|
|
@@ -257,7 +275,8 @@ class ClientAdapter {
|
|
|
257
275
|
(index, collection) => {
|
|
258
276
|
this.cache.assertCollectionExists(index, collection);
|
|
259
277
|
return this.client.truncateCollection(index, collection);
|
|
260
|
-
}
|
|
278
|
+
}
|
|
279
|
+
);
|
|
261
280
|
|
|
262
281
|
/**
|
|
263
282
|
* Update a collection settings and mappings
|
|
@@ -271,10 +290,11 @@ class ClientAdapter {
|
|
|
271
290
|
(index, collection, changes) => {
|
|
272
291
|
this.cache.assertCollectionExists(index, collection);
|
|
273
292
|
return this.client.updateCollection(index, collection, changes);
|
|
274
|
-
}
|
|
293
|
+
}
|
|
294
|
+
);
|
|
275
295
|
}
|
|
276
296
|
|
|
277
|
-
registerIndexEvents
|
|
297
|
+
registerIndexEvents() {
|
|
278
298
|
/**
|
|
279
299
|
* Create a new index within this adapter scope
|
|
280
300
|
* @param {string} index
|
|
@@ -284,7 +304,8 @@ class ClientAdapter {
|
|
|
284
304
|
*/
|
|
285
305
|
global.kuzzle.onAsk(
|
|
286
306
|
`core:storage:${this.scope}:index:create`,
|
|
287
|
-
(index, options) => this.createIndex(index, options)
|
|
307
|
+
(index, options) => this.createIndex(index, options)
|
|
308
|
+
);
|
|
288
309
|
|
|
289
310
|
/**
|
|
290
311
|
* Delete an index
|
|
@@ -292,26 +313,26 @@ class ClientAdapter {
|
|
|
292
313
|
* @return {Promise}
|
|
293
314
|
* @throws If the index does not exist
|
|
294
315
|
*/
|
|
295
|
-
global.kuzzle.onAsk(
|
|
296
|
-
|
|
297
|
-
|
|
316
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:index:delete`, (index) =>
|
|
317
|
+
this.deleteIndex(index)
|
|
318
|
+
);
|
|
298
319
|
|
|
299
320
|
/**
|
|
300
321
|
* Check an index existence
|
|
301
322
|
* @param {string} index
|
|
302
323
|
* @return {Promise.<boolean>}
|
|
303
324
|
*/
|
|
304
|
-
global.kuzzle.onAsk(
|
|
305
|
-
|
|
306
|
-
|
|
325
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:index:exist`, (index) =>
|
|
326
|
+
this.cache.hasIndex(index)
|
|
327
|
+
);
|
|
307
328
|
|
|
308
329
|
/**
|
|
309
330
|
* Return a list of all indexes within this adapter's scope
|
|
310
331
|
* @returns {string[]}
|
|
311
332
|
*/
|
|
312
|
-
global.kuzzle.onAsk(
|
|
313
|
-
|
|
314
|
-
|
|
333
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:index:list`, () =>
|
|
334
|
+
this.cache.listIndexes()
|
|
335
|
+
);
|
|
315
336
|
|
|
316
337
|
/**
|
|
317
338
|
* Delete multiple indexes
|
|
@@ -319,21 +340,20 @@ class ClientAdapter {
|
|
|
319
340
|
* @return {Promise}
|
|
320
341
|
* @throws If at least one index does not exist
|
|
321
342
|
*/
|
|
322
|
-
global.kuzzle.onAsk(
|
|
323
|
-
|
|
324
|
-
|
|
343
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:index:mDelete`, (indexes) =>
|
|
344
|
+
this.deleteIndexes(indexes)
|
|
345
|
+
);
|
|
325
346
|
|
|
326
347
|
/**
|
|
327
348
|
* Return detailed storage stats within this adapter's scope
|
|
328
349
|
* @returns {Promise.<Object>}
|
|
329
350
|
*/
|
|
330
|
-
global.kuzzle.onAsk(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
351
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:index:stats`, () =>
|
|
352
|
+
this.client.stats()
|
|
353
|
+
);
|
|
334
354
|
}
|
|
335
355
|
|
|
336
|
-
registerDocumentEvents
|
|
356
|
+
registerDocumentEvents() {
|
|
337
357
|
/**
|
|
338
358
|
* Execute actions on documents in bulk
|
|
339
359
|
*
|
|
@@ -348,7 +368,8 @@ class ClientAdapter {
|
|
|
348
368
|
(index, collection, bulk, opts) => {
|
|
349
369
|
this.cache.assertCollectionExists(index, collection);
|
|
350
370
|
return this.client.import(index, collection, bulk, opts);
|
|
351
|
-
}
|
|
371
|
+
}
|
|
372
|
+
);
|
|
352
373
|
|
|
353
374
|
/**
|
|
354
375
|
* Count how many documents match the provided query
|
|
@@ -363,7 +384,8 @@ class ClientAdapter {
|
|
|
363
384
|
(index, collection, query) => {
|
|
364
385
|
this.cache.assertCollectionExists(index, collection);
|
|
365
386
|
return this.client.count(index, collection, query);
|
|
366
|
-
}
|
|
387
|
+
}
|
|
388
|
+
);
|
|
367
389
|
|
|
368
390
|
/**
|
|
369
391
|
* Create a document
|
|
@@ -379,7 +401,8 @@ class ClientAdapter {
|
|
|
379
401
|
(index, collection, content, opts) => {
|
|
380
402
|
this.cache.assertCollectionExists(index, collection);
|
|
381
403
|
return this.client.create(index, collection, content, opts);
|
|
382
|
-
}
|
|
404
|
+
}
|
|
405
|
+
);
|
|
383
406
|
|
|
384
407
|
/**
|
|
385
408
|
* Create or replace a document
|
|
@@ -395,8 +418,15 @@ class ClientAdapter {
|
|
|
395
418
|
`core:storage:${this.scope}:document:createOrReplace`,
|
|
396
419
|
(index, collection, id, content, opts) => {
|
|
397
420
|
this.cache.assertCollectionExists(index, collection);
|
|
398
|
-
return this.client.createOrReplace(
|
|
399
|
-
|
|
421
|
+
return this.client.createOrReplace(
|
|
422
|
+
index,
|
|
423
|
+
collection,
|
|
424
|
+
id,
|
|
425
|
+
content,
|
|
426
|
+
opts
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
);
|
|
400
430
|
|
|
401
431
|
/**
|
|
402
432
|
* Delete a document
|
|
@@ -412,7 +442,8 @@ class ClientAdapter {
|
|
|
412
442
|
(index, collection, id, opts) => {
|
|
413
443
|
this.cache.assertCollectionExists(index, collection);
|
|
414
444
|
return this.client.delete(index, collection, id, opts);
|
|
415
|
-
}
|
|
445
|
+
}
|
|
446
|
+
);
|
|
416
447
|
|
|
417
448
|
/**
|
|
418
449
|
* Delete all documents matching the provided search query
|
|
@@ -428,24 +459,26 @@ class ClientAdapter {
|
|
|
428
459
|
(index, collection, query, opts) => {
|
|
429
460
|
this.cache.assertCollectionExists(index, collection);
|
|
430
461
|
return this.client.deleteByQuery(index, collection, query, opts);
|
|
431
|
-
}
|
|
462
|
+
}
|
|
463
|
+
);
|
|
432
464
|
|
|
433
465
|
/**
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
466
|
+
* Delete fields of a document
|
|
467
|
+
*
|
|
468
|
+
* @param {string} index
|
|
469
|
+
* @param {string} collection
|
|
470
|
+
* @param {string} id
|
|
471
|
+
* @param {Array} fields -- fields to delete
|
|
472
|
+
* @param {Object} [opts] -- see Elasticsearch "deleteFields" options
|
|
473
|
+
* @returns {Promise.<{ _id, _version, _source }>}
|
|
474
|
+
*/
|
|
443
475
|
global.kuzzle.onAsk(
|
|
444
476
|
`core:storage:${this.scope}:document:deleteFields`,
|
|
445
477
|
(index, collection, id, fields, opts) => {
|
|
446
478
|
this.cache.assertCollectionExists(index, collection);
|
|
447
479
|
return this.client.deleteFields(index, collection, id, fields, opts);
|
|
448
|
-
}
|
|
480
|
+
}
|
|
481
|
+
);
|
|
449
482
|
|
|
450
483
|
/**
|
|
451
484
|
* Check if a document exists
|
|
@@ -460,7 +493,8 @@ class ClientAdapter {
|
|
|
460
493
|
(index, collection, id) => {
|
|
461
494
|
this.cache.assertCollectionExists(index, collection);
|
|
462
495
|
return this.client.exists(index, collection, id);
|
|
463
|
-
}
|
|
496
|
+
}
|
|
497
|
+
);
|
|
464
498
|
|
|
465
499
|
/**
|
|
466
500
|
* Check if a document multiple document Exists
|
|
@@ -475,7 +509,8 @@ class ClientAdapter {
|
|
|
475
509
|
(index, collection, ids) => {
|
|
476
510
|
this.cache.assertCollectionExists(index, collection);
|
|
477
511
|
return this.client.mExists(index, collection, ids);
|
|
478
|
-
}
|
|
512
|
+
}
|
|
513
|
+
);
|
|
479
514
|
|
|
480
515
|
/**
|
|
481
516
|
* Get a document using its unique id
|
|
@@ -490,7 +525,8 @@ class ClientAdapter {
|
|
|
490
525
|
(index, collection, id) => {
|
|
491
526
|
this.cache.assertCollectionExists(index, collection);
|
|
492
527
|
return this.client.get(index, collection, id);
|
|
493
|
-
}
|
|
528
|
+
}
|
|
529
|
+
);
|
|
494
530
|
|
|
495
531
|
/**
|
|
496
532
|
* Import documents as fixtures
|
|
@@ -499,7 +535,8 @@ class ClientAdapter {
|
|
|
499
535
|
*/
|
|
500
536
|
global.kuzzle.onAsk(
|
|
501
537
|
`core:storage:${this.scope}:document:import`,
|
|
502
|
-
(fixtures, options) => this.loadFixtures(fixtures, options)
|
|
538
|
+
(fixtures, options) => this.loadFixtures(fixtures, options)
|
|
539
|
+
);
|
|
503
540
|
|
|
504
541
|
/**
|
|
505
542
|
* Create multiple documents
|
|
@@ -515,7 +552,8 @@ class ClientAdapter {
|
|
|
515
552
|
(index, collection, documents, opts) => {
|
|
516
553
|
this.cache.assertCollectionExists(index, collection);
|
|
517
554
|
return this.client.mCreate(index, collection, documents, opts);
|
|
518
|
-
}
|
|
555
|
+
}
|
|
556
|
+
);
|
|
519
557
|
|
|
520
558
|
/**
|
|
521
559
|
* Create or replace multiple documents
|
|
@@ -531,7 +569,8 @@ class ClientAdapter {
|
|
|
531
569
|
(index, collection, documents, opts) => {
|
|
532
570
|
this.cache.assertCollectionExists(index, collection);
|
|
533
571
|
return this.client.mCreateOrReplace(index, collection, documents, opts);
|
|
534
|
-
}
|
|
572
|
+
}
|
|
573
|
+
);
|
|
535
574
|
|
|
536
575
|
/**
|
|
537
576
|
* Delete multiple documents
|
|
@@ -547,7 +586,8 @@ class ClientAdapter {
|
|
|
547
586
|
(index, collection, ids, opts) => {
|
|
548
587
|
this.cache.assertCollectionExists(index, collection);
|
|
549
588
|
return this.client.mDelete(index, collection, ids, opts);
|
|
550
|
-
}
|
|
589
|
+
}
|
|
590
|
+
);
|
|
551
591
|
|
|
552
592
|
/**
|
|
553
593
|
* Replace multiple documents
|
|
@@ -563,7 +603,8 @@ class ClientAdapter {
|
|
|
563
603
|
(index, collection, documents, opts) => {
|
|
564
604
|
this.cache.assertCollectionExists(index, collection);
|
|
565
605
|
return this.client.mReplace(index, collection, documents, opts);
|
|
566
|
-
}
|
|
606
|
+
}
|
|
607
|
+
);
|
|
567
608
|
|
|
568
609
|
/**
|
|
569
610
|
* Update multiple documents
|
|
@@ -579,11 +620,12 @@ class ClientAdapter {
|
|
|
579
620
|
(index, collection, documents, opts) => {
|
|
580
621
|
this.cache.assertCollectionExists(index, collection);
|
|
581
622
|
return this.client.mUpdate(index, collection, documents, opts);
|
|
582
|
-
}
|
|
623
|
+
}
|
|
624
|
+
);
|
|
583
625
|
|
|
584
626
|
/**
|
|
585
|
-
|
|
586
|
-
|
|
627
|
+
* Applies a partial update to documents provided in the body.
|
|
628
|
+
* If some of the documents don't already exist, they will be created.
|
|
587
629
|
*
|
|
588
630
|
* @param {string} index
|
|
589
631
|
* @param {string} collection
|
|
@@ -596,7 +638,8 @@ class ClientAdapter {
|
|
|
596
638
|
(index, collection, documents, opts) => {
|
|
597
639
|
this.cache.assertCollectionExists(index, collection);
|
|
598
640
|
return this.client.mUpsert(index, collection, documents, opts);
|
|
599
|
-
}
|
|
641
|
+
}
|
|
642
|
+
);
|
|
600
643
|
|
|
601
644
|
/**
|
|
602
645
|
* Apply the provided callback to all documents matching a search query
|
|
@@ -613,7 +656,8 @@ class ClientAdapter {
|
|
|
613
656
|
(index, collection, query, callback, opts) => {
|
|
614
657
|
this.cache.assertCollectionExists(index, collection);
|
|
615
658
|
return this.client.mExecute(index, collection, query, callback, opts);
|
|
616
|
-
}
|
|
659
|
+
}
|
|
660
|
+
);
|
|
617
661
|
|
|
618
662
|
/**
|
|
619
663
|
* Get multiple documents using their ids
|
|
@@ -628,7 +672,8 @@ class ClientAdapter {
|
|
|
628
672
|
(index, collection, ids) => {
|
|
629
673
|
this.cache.assertCollectionExists(index, collection);
|
|
630
674
|
return this.client.mGet(index, collection, ids);
|
|
631
|
-
}
|
|
675
|
+
}
|
|
676
|
+
);
|
|
632
677
|
|
|
633
678
|
/**
|
|
634
679
|
* Replace the content of a document
|
|
@@ -645,7 +690,8 @@ class ClientAdapter {
|
|
|
645
690
|
(index, collection, id, content, opts) => {
|
|
646
691
|
this.cache.assertCollectionExists(index, collection);
|
|
647
692
|
return this.client.replace(index, collection, id, content, opts);
|
|
648
|
-
}
|
|
693
|
+
}
|
|
694
|
+
);
|
|
649
695
|
|
|
650
696
|
/**
|
|
651
697
|
* Fetch the next page of results of a search query
|
|
@@ -656,7 +702,8 @@ class ClientAdapter {
|
|
|
656
702
|
*/
|
|
657
703
|
global.kuzzle.onAsk(
|
|
658
704
|
`core:storage:${this.scope}:document:scroll`,
|
|
659
|
-
(scrollId, opts) => this.client.scroll(scrollId, opts)
|
|
705
|
+
(scrollId, opts) => this.client.scroll(scrollId, opts)
|
|
706
|
+
);
|
|
660
707
|
|
|
661
708
|
/**
|
|
662
709
|
* Search for documents
|
|
@@ -672,7 +719,8 @@ class ClientAdapter {
|
|
|
672
719
|
(index, collection, searchBody, opts) => {
|
|
673
720
|
this.cache.assertCollectionExists(index, collection);
|
|
674
721
|
return this.client.search({ collection, index, searchBody }, opts);
|
|
675
|
-
}
|
|
722
|
+
}
|
|
723
|
+
);
|
|
676
724
|
|
|
677
725
|
/**
|
|
678
726
|
* Search for multiples documents
|
|
@@ -692,7 +740,8 @@ class ClientAdapter {
|
|
|
692
740
|
}
|
|
693
741
|
|
|
694
742
|
return this.client.search({ searchBody, targets }, opts);
|
|
695
|
-
}
|
|
743
|
+
}
|
|
744
|
+
);
|
|
696
745
|
|
|
697
746
|
/**
|
|
698
747
|
* Update a document
|
|
@@ -709,7 +758,8 @@ class ClientAdapter {
|
|
|
709
758
|
(index, collection, id, content, opts) => {
|
|
710
759
|
this.cache.assertCollectionExists(index, collection);
|
|
711
760
|
return this.client.update(index, collection, id, content, opts);
|
|
712
|
-
}
|
|
761
|
+
}
|
|
762
|
+
);
|
|
713
763
|
|
|
714
764
|
/**
|
|
715
765
|
* Update all documents matching the search query, by applying the same
|
|
@@ -726,8 +776,15 @@ class ClientAdapter {
|
|
|
726
776
|
`core:storage:${this.scope}:document:updateByQuery`,
|
|
727
777
|
(index, collection, query, changes, opts) => {
|
|
728
778
|
this.cache.assertCollectionExists(index, collection);
|
|
729
|
-
return this.client.updateByQuery(
|
|
730
|
-
|
|
779
|
+
return this.client.updateByQuery(
|
|
780
|
+
index,
|
|
781
|
+
collection,
|
|
782
|
+
query,
|
|
783
|
+
changes,
|
|
784
|
+
opts
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
);
|
|
731
788
|
|
|
732
789
|
/**
|
|
733
790
|
* Directly Update all documents matching the search query (without regards
|
|
@@ -744,8 +801,15 @@ class ClientAdapter {
|
|
|
744
801
|
`core:storage:${this.scope}:bulk:updateByQuery`,
|
|
745
802
|
(index, collection, query, changes, opts) => {
|
|
746
803
|
this.cache.assertCollectionExists(index, collection);
|
|
747
|
-
return this.client.bulkUpdateByQuery(
|
|
748
|
-
|
|
804
|
+
return this.client.bulkUpdateByQuery(
|
|
805
|
+
index,
|
|
806
|
+
collection,
|
|
807
|
+
query,
|
|
808
|
+
changes,
|
|
809
|
+
opts
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
);
|
|
749
813
|
|
|
750
814
|
/**
|
|
751
815
|
* Applies a partial update to an existing document.
|
|
@@ -763,10 +827,11 @@ class ClientAdapter {
|
|
|
763
827
|
(index, collection, id, content, opts) => {
|
|
764
828
|
this.cache.assertCollectionExists(index, collection);
|
|
765
829
|
return this.client.upsert(index, collection, id, content, opts);
|
|
766
|
-
}
|
|
830
|
+
}
|
|
831
|
+
);
|
|
767
832
|
}
|
|
768
833
|
|
|
769
|
-
registerMappingEvents
|
|
834
|
+
registerMappingEvents() {
|
|
770
835
|
/**
|
|
771
836
|
* Return a collection's mapping
|
|
772
837
|
*
|
|
@@ -781,7 +846,8 @@ class ClientAdapter {
|
|
|
781
846
|
(index, collection, opts) => {
|
|
782
847
|
this.cache.assertCollectionExists(index, collection);
|
|
783
848
|
return this.client.getMapping(index, collection, opts);
|
|
784
|
-
}
|
|
849
|
+
}
|
|
850
|
+
);
|
|
785
851
|
|
|
786
852
|
/**
|
|
787
853
|
* Import mappings as fixtures. Create non-existing indexes and collections
|
|
@@ -793,7 +859,8 @@ class ClientAdapter {
|
|
|
793
859
|
*/
|
|
794
860
|
global.kuzzle.onAsk(
|
|
795
861
|
`core:storage:${this.scope}:mappings:import`,
|
|
796
|
-
(fixtures, options) => this.loadMappings(fixtures, options)
|
|
862
|
+
(fixtures, options) => this.loadMappings(fixtures, options)
|
|
863
|
+
);
|
|
797
864
|
|
|
798
865
|
/**
|
|
799
866
|
* Update a collection mappings
|
|
@@ -808,21 +875,22 @@ class ClientAdapter {
|
|
|
808
875
|
(index, collection, mappings) => {
|
|
809
876
|
this.cache.assertCollectionExists(index, collection);
|
|
810
877
|
return this.client.updateMapping(index, collection, mappings);
|
|
811
|
-
}
|
|
878
|
+
}
|
|
879
|
+
);
|
|
812
880
|
}
|
|
813
881
|
|
|
814
882
|
/**
|
|
815
883
|
* Cache update operations. These events trigger neither any actual change
|
|
816
884
|
* in the storage layer, nor kuzzle events.
|
|
817
885
|
*/
|
|
818
|
-
registerCacheEvents
|
|
886
|
+
registerCacheEvents() {
|
|
819
887
|
/**
|
|
820
888
|
* Adds a new index to the cache
|
|
821
889
|
* @param {string} index
|
|
822
890
|
*/
|
|
823
|
-
global.kuzzle.onAsk(
|
|
824
|
-
|
|
825
|
-
|
|
891
|
+
global.kuzzle.onAsk(`core:storage:${this.scope}:cache:addIndex`, (index) =>
|
|
892
|
+
this.cache.addIndex(index)
|
|
893
|
+
);
|
|
826
894
|
|
|
827
895
|
/**
|
|
828
896
|
* Adds a new collection to the cache
|
|
@@ -831,7 +899,8 @@ class ClientAdapter {
|
|
|
831
899
|
*/
|
|
832
900
|
global.kuzzle.onAsk(
|
|
833
901
|
`core:storage:${this.scope}:cache:addCollection`,
|
|
834
|
-
(index, collection) => this.cache.addCollection(index, collection)
|
|
902
|
+
(index, collection) => this.cache.addCollection(index, collection)
|
|
903
|
+
);
|
|
835
904
|
|
|
836
905
|
/**
|
|
837
906
|
* Removes indexes from the cache
|
|
@@ -839,11 +908,12 @@ class ClientAdapter {
|
|
|
839
908
|
*/
|
|
840
909
|
global.kuzzle.onAsk(
|
|
841
910
|
`core:storage:${this.scope}:cache:removeIndexes`,
|
|
842
|
-
indexes => {
|
|
911
|
+
(indexes) => {
|
|
843
912
|
for (const index of indexes) {
|
|
844
913
|
this.cache.removeIndex(index);
|
|
845
914
|
}
|
|
846
|
-
}
|
|
915
|
+
}
|
|
916
|
+
);
|
|
847
917
|
|
|
848
918
|
/**
|
|
849
919
|
* Removes a collection from the cache
|
|
@@ -852,7 +922,8 @@ class ClientAdapter {
|
|
|
852
922
|
*/
|
|
853
923
|
global.kuzzle.onAsk(
|
|
854
924
|
`core:storage:${this.scope}:cache:removeCollection`,
|
|
855
|
-
(index, collection) => this.cache.removeCollection(index, collection)
|
|
925
|
+
(index, collection) => this.cache.removeCollection(index, collection)
|
|
926
|
+
);
|
|
856
927
|
}
|
|
857
928
|
|
|
858
929
|
/**
|
|
@@ -861,14 +932,20 @@ class ClientAdapter {
|
|
|
861
932
|
* @param {String} fixturesId
|
|
862
933
|
* @returns {Promise}
|
|
863
934
|
*/
|
|
864
|
-
async loadFixtures
|
|
865
|
-
if (!
|
|
866
|
-
throw kerror.get(
|
|
935
|
+
async loadFixtures(fixtures = {}, { refresh = "wait_for" } = {}) {
|
|
936
|
+
if (!isPlainObject(fixtures)) {
|
|
937
|
+
throw kerror.get("api", "assert", "invalid_argument", fixtures, "object");
|
|
867
938
|
}
|
|
868
939
|
|
|
869
940
|
for (const index of Object.keys(fixtures)) {
|
|
870
|
-
if (!
|
|
871
|
-
throw kerror.get(
|
|
941
|
+
if (!isPlainObject(fixtures[index])) {
|
|
942
|
+
throw kerror.get(
|
|
943
|
+
"api",
|
|
944
|
+
"assert",
|
|
945
|
+
"invalid_argument",
|
|
946
|
+
fixtures[index],
|
|
947
|
+
"object"
|
|
948
|
+
);
|
|
872
949
|
}
|
|
873
950
|
|
|
874
951
|
for (const [collection, payload] of Object.entries(fixtures[index])) {
|
|
@@ -878,10 +955,11 @@ class ClientAdapter {
|
|
|
878
955
|
index,
|
|
879
956
|
collection,
|
|
880
957
|
payload,
|
|
881
|
-
{ refresh }
|
|
958
|
+
{ refresh }
|
|
959
|
+
);
|
|
882
960
|
|
|
883
961
|
if (errors.length > 0) {
|
|
884
|
-
throw servicesError.get(
|
|
962
|
+
throw servicesError.get("import_failed", errors);
|
|
885
963
|
}
|
|
886
964
|
}
|
|
887
965
|
}
|
|
@@ -896,7 +974,7 @@ class ClientAdapter {
|
|
|
896
974
|
* - indexCacheOnly (false): only update the cache, don't update the database
|
|
897
975
|
* @returns {Promise}
|
|
898
976
|
*/
|
|
899
|
-
async loadMappings
|
|
977
|
+
async loadMappings(
|
|
900
978
|
fixtures = {},
|
|
901
979
|
options = {
|
|
902
980
|
indexCacheOnly: false,
|
|
@@ -905,18 +983,24 @@ class ClientAdapter {
|
|
|
905
983
|
refresh: false,
|
|
906
984
|
}
|
|
907
985
|
) {
|
|
908
|
-
if (!
|
|
909
|
-
throw kerror.get(
|
|
986
|
+
if (!isPlainObject(fixtures)) {
|
|
987
|
+
throw kerror.get("api", "assert", "invalid_argument", fixtures, "object");
|
|
910
988
|
}
|
|
911
989
|
|
|
912
|
-
const mutex = new Mutex(
|
|
990
|
+
const mutex = new Mutex("loadMappings", { timeout: -1, ttl: 60000 });
|
|
913
991
|
|
|
914
992
|
await mutex.lock();
|
|
915
993
|
|
|
916
994
|
try {
|
|
917
995
|
for (const index of Object.keys(fixtures)) {
|
|
918
|
-
if (!
|
|
919
|
-
throw kerror.get(
|
|
996
|
+
if (!isPlainObject(fixtures[index])) {
|
|
997
|
+
throw kerror.get(
|
|
998
|
+
"api",
|
|
999
|
+
"assert",
|
|
1000
|
+
"invalid_argument",
|
|
1001
|
+
fixtures[index],
|
|
1002
|
+
"object"
|
|
1003
|
+
);
|
|
920
1004
|
}
|
|
921
1005
|
|
|
922
1006
|
for (const [collection, mappings] of Object.entries(fixtures[index])) {
|
|
@@ -925,11 +1009,10 @@ class ClientAdapter {
|
|
|
925
1009
|
indexCacheOnly: options.indexCacheOnly,
|
|
926
1010
|
propagate: options.propagate,
|
|
927
1011
|
});
|
|
928
|
-
}
|
|
929
|
-
catch (error) {
|
|
1012
|
+
} catch (error) {
|
|
930
1013
|
// @cluster: ignore if the index already exists to prevent race
|
|
931
1014
|
// conditions with index cache propagation
|
|
932
|
-
if (error.id !==
|
|
1015
|
+
if (error.id !== "services.storage.index_already_exists") {
|
|
933
1016
|
throw error;
|
|
934
1017
|
}
|
|
935
1018
|
}
|
|
@@ -941,15 +1024,15 @@ class ClientAdapter {
|
|
|
941
1024
|
{
|
|
942
1025
|
indexCacheOnly: options.indexCacheOnly,
|
|
943
1026
|
propagate: options.propagate,
|
|
944
|
-
}
|
|
1027
|
+
}
|
|
1028
|
+
);
|
|
945
1029
|
|
|
946
|
-
if (options.refresh && !
|
|
1030
|
+
if (options.refresh && !options.indexCacheOnly) {
|
|
947
1031
|
await this.client.refreshCollection(index, collection);
|
|
948
1032
|
}
|
|
949
1033
|
}
|
|
950
1034
|
}
|
|
951
|
-
}
|
|
952
|
-
finally {
|
|
1035
|
+
} finally {
|
|
953
1036
|
await mutex.unlock();
|
|
954
1037
|
}
|
|
955
1038
|
}
|