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.
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/lib/api/controllers/authController.d.ts +3 -2
- package/lib/api/funnel.js +2 -1
- 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/tokenRepository.d.ts +1 -1
- package/lib/core/security/tokenRepository.js +1 -1
- package/lib/core/shared/ObjectRepository.d.ts +1 -1
- package/lib/core/storage/clientAdapter.js +6 -4
- package/lib/core/storage/storageEngine.js +4 -5
- package/lib/kerror/index.js +1 -1
- package/lib/kuzzle/event/KuzzleEventEmitter.d.ts +70 -0
- package/lib/kuzzle/event/KuzzleEventEmitter.js +328 -0
- package/lib/kuzzle/index.d.ts +3 -0
- package/lib/kuzzle/index.js +7 -4
- package/lib/kuzzle/kuzzle.d.ts +32 -19
- package/lib/kuzzle/kuzzle.js +31 -31
- package/lib/service/storage/{elasticsearch.d.ts → 7/elasticsearch.d.ts} +40 -22
- package/lib/service/storage/{elasticsearch.js → 7/elasticsearch.js} +24 -43
- 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/commons/queryTranslator.d.ts +5 -0
- package/lib/service/storage/commons/queryTranslator.js +189 -0
- package/lib/types/EventHandler.d.ts +29 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +2 -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 +7 -4
- package/lib/kuzzle/event/kuzzleEventEmitter.js +0 -405
- package/lib/service/storage/queryTranslator.js +0 -219
- /package/lib/types/storage/{Elasticsearch.js → 7/Elasticsearch.js} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { estypes } from "sdk-es8";
|
|
2
|
+
export type InfoResult = {
|
|
3
|
+
type: string;
|
|
4
|
+
version: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
lucene?: string;
|
|
7
|
+
spaceUsed?: estypes.ByteSize;
|
|
8
|
+
nodes?: estypes.ClusterStatsClusterNodes;
|
|
9
|
+
};
|
|
10
|
+
export type KUpdateResponse = {
|
|
11
|
+
_id: string;
|
|
12
|
+
_source: unknown;
|
|
13
|
+
_version: number;
|
|
14
|
+
};
|
|
15
|
+
export type KStatsIndexesCollection = {
|
|
16
|
+
documentCount: number;
|
|
17
|
+
name: string;
|
|
18
|
+
size: estypes.ByteSize;
|
|
19
|
+
};
|
|
20
|
+
export type KStatsIndex = {
|
|
21
|
+
collections: KStatsIndexesCollection[];
|
|
22
|
+
name: string;
|
|
23
|
+
size: estypes.ByteSize;
|
|
24
|
+
};
|
|
25
|
+
export type KStatsIndexes = {
|
|
26
|
+
[key: string]: KStatsIndex;
|
|
27
|
+
};
|
|
28
|
+
export type KStats = {
|
|
29
|
+
indexes: KStatsIndex[];
|
|
30
|
+
size: estypes.ByteSize;
|
|
31
|
+
};
|
|
32
|
+
export type KRequestBody<T> = T & {
|
|
33
|
+
_kuzzle_info?: {
|
|
34
|
+
author: string;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
updatedAt: number | null;
|
|
37
|
+
updater: string | null;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export interface JSONObject {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}
|
|
43
|
+
export type KImportError = {
|
|
44
|
+
_id: string;
|
|
45
|
+
status: string;
|
|
46
|
+
_source?: JSONObject;
|
|
47
|
+
error?: {
|
|
48
|
+
reason: string;
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export type KRequestParams = {
|
|
53
|
+
refresh?: boolean | "wait_for";
|
|
54
|
+
timeout?: string;
|
|
55
|
+
userId?: string;
|
|
56
|
+
injectKuzzleMeta?: boolean;
|
|
57
|
+
limits?: boolean;
|
|
58
|
+
source?: boolean;
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kuzzle",
|
|
3
3
|
"author": "The Kuzzle Team <support@kuzzle.io>",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.32.0-beta.1",
|
|
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": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dev": "ergol docker/scripts/start-kuzzle-dev.ts -c ./config/ergol.config.json",
|
|
13
13
|
"doc-error-codes": "node -r ts-node/register doc/build-error-codes",
|
|
14
14
|
"prepublishOnly": "npm run build",
|
|
15
|
-
"prettier": "prettier ./lib ./test ./
|
|
15
|
+
"prettier": "prettier ./lib ./test ./features ./plugins/available/functional-test-plugin --write",
|
|
16
16
|
"test:functional:http": "KUZZLE_PROTOCOL=http cucumber-js --profile http",
|
|
17
17
|
"test:functional:jest": "jest",
|
|
18
18
|
"test:functional:legacy:http": "cucumber-js --format progress-bar --profile http ./features-legacy",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"lib": "lib"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@elastic/elasticsearch": "https://github.com/elastic/elasticsearch-js/archive/refs/tags/v7.13.0.tar.gz",
|
|
33
32
|
"aedes": "0.46.3",
|
|
34
33
|
"bluebird": "3.7.2",
|
|
35
34
|
"cli-color": "2.0.3",
|
|
@@ -60,7 +59,9 @@
|
|
|
60
59
|
"passport": "0.7.0",
|
|
61
60
|
"protobufjs": "7.2.5",
|
|
62
61
|
"rc": "1.2.8",
|
|
63
|
-
"
|
|
62
|
+
"sdk-es7": "https://github.com/elastic/elasticsearch-js/archive/refs/tags/v7.13.0.tar.gz",
|
|
63
|
+
"sdk-es8": "npm:@elastic/elasticsearch@8.12.1",
|
|
64
|
+
"semver": "7.6.0",
|
|
64
65
|
"sorted-array": "2.0.4",
|
|
65
66
|
"uuid": "9.0.1",
|
|
66
67
|
"uWebSockets.js": "https://github.com/uNetworking/uWebSockets.js/archive/refs/tags/v20.34.0.tar.gz",
|
|
@@ -84,6 +85,8 @@
|
|
|
84
85
|
"@semantic-release/commit-analyzer": "^10.0.1",
|
|
85
86
|
"@semantic-release/git": "^10.0.1",
|
|
86
87
|
"@semantic-release/release-notes-generator": "^11.0.4",
|
|
88
|
+
"@types/bluebird": "^3.5.42",
|
|
89
|
+
"@types/cookie": "^0.6.0",
|
|
87
90
|
"@types/jest": "29.5.10",
|
|
88
91
|
"@types/js-yaml": "4.0.9",
|
|
89
92
|
"@types/lodash": "4.14.202",
|
|
@@ -1,405 +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
|
-
// Most of the functions exposed in this file should be viewed as
|
|
25
|
-
// critical section of code.
|
|
26
|
-
|
|
27
|
-
const assert = require("assert");
|
|
28
|
-
|
|
29
|
-
const EventEmitter = require("eventemitter3");
|
|
30
|
-
const Bluebird = require("bluebird");
|
|
31
|
-
const debug = require("debug")("kuzzle:events");
|
|
32
|
-
const { v4: uuidv4 } = require("uuid");
|
|
33
|
-
|
|
34
|
-
const Promback = require("../../util/promback");
|
|
35
|
-
const memoize = require("../../util/memoize");
|
|
36
|
-
const PipeRunner = require("./pipeRunner");
|
|
37
|
-
const kerror = require("../../kerror");
|
|
38
|
-
|
|
39
|
-
class PluginPipeDefinition {
|
|
40
|
-
constructor(event, handler, pipeId = null) {
|
|
41
|
-
this.event = event;
|
|
42
|
-
this.handler = handler;
|
|
43
|
-
|
|
44
|
-
this.pipeId = pipeId || uuidv4();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class KuzzleEventEmitter extends EventEmitter {
|
|
49
|
-
constructor(maxConcurrentPipes, pipesBufferSize) {
|
|
50
|
-
super();
|
|
51
|
-
this.superEmit = super.emit;
|
|
52
|
-
this.pipeRunner = new PipeRunner(maxConcurrentPipes, pipesBufferSize);
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Map of plugin pipe handler functions by event
|
|
56
|
-
*
|
|
57
|
-
* @type Map<string, Function[]>
|
|
58
|
-
*/
|
|
59
|
-
this.pluginPipes = new Map();
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Map of plugin pipe definitions by pipeId
|
|
63
|
-
*
|
|
64
|
-
* @type Map<string, PluginPipeDefinition>
|
|
65
|
-
*/
|
|
66
|
-
this.pluginPipeDefinitions = new Map();
|
|
67
|
-
|
|
68
|
-
this.corePipes = new Map();
|
|
69
|
-
this.coreAnswerers = new Map();
|
|
70
|
-
this.coreSyncedAnswerers = new Map();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Registers a core method on a pipe
|
|
75
|
-
* Note: core methods cannot listen to wildcarded events, only exact matching
|
|
76
|
-
* works here.
|
|
77
|
-
*
|
|
78
|
-
* @param {String} event
|
|
79
|
-
* @param {Function} fn
|
|
80
|
-
*/
|
|
81
|
-
onPipe(event, fn) {
|
|
82
|
-
assert(
|
|
83
|
-
typeof fn === "function",
|
|
84
|
-
`Cannot listen to pipe event ${event}: "${fn}" is not a function`,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (!this.corePipes.has(event)) {
|
|
88
|
-
this.corePipes.set(event, []);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.corePipes.get(event).push(fn);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Registers a core 'ask' event answerer
|
|
96
|
-
* There can only be 0 or 1 answerer per ask event.
|
|
97
|
-
*
|
|
98
|
-
* @param {String} event
|
|
99
|
-
* @param {Function} fn
|
|
100
|
-
*/
|
|
101
|
-
onAsk(event, fn) {
|
|
102
|
-
assert(
|
|
103
|
-
typeof fn === "function",
|
|
104
|
-
`Cannot listen to ask event "${event}": "${fn}" is not a function`,
|
|
105
|
-
);
|
|
106
|
-
assert(
|
|
107
|
-
!this.coreAnswerers.has(event),
|
|
108
|
-
`Cannot add a listener to the ask event "${event}": event has already an answerer`,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
this.coreAnswerers.set(event, fn);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Registers a core 'callback' answerer
|
|
116
|
-
* There can only be 0 or 1 answerer per callback event.
|
|
117
|
-
*
|
|
118
|
-
* @param {String} event
|
|
119
|
-
* @param {Function} fn
|
|
120
|
-
*/
|
|
121
|
-
onCall(event, fn) {
|
|
122
|
-
assert(
|
|
123
|
-
typeof fn === "function",
|
|
124
|
-
`Cannot register callback for event "${event}": "${fn}" is not a function`,
|
|
125
|
-
);
|
|
126
|
-
assert(
|
|
127
|
-
!this.coreSyncedAnswerers.has(event),
|
|
128
|
-
`Cannot register callback for event "${event}": a callback has already been registered`,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
this.coreSyncedAnswerers.set(event, fn);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Emits an event and all its wildcarded versions
|
|
136
|
-
*
|
|
137
|
-
* @warning Critical section of code
|
|
138
|
-
*
|
|
139
|
-
* @param {string} event
|
|
140
|
-
* @param {*} data
|
|
141
|
-
*/
|
|
142
|
-
emit(event, data) {
|
|
143
|
-
const events = getWildcardEvents(event);
|
|
144
|
-
debug('Triggering event "%s" with data: %o', event, data);
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < events.length; i++) {
|
|
147
|
-
super.emit(events[i], data);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Emits a pipe event, which triggers the following, in that order:
|
|
153
|
-
* 1. Plugin pipes are invoked one after another (waterfall). Each plugin must
|
|
154
|
-
* resolve the pipe (with a callback or a promise) with a similar payload
|
|
155
|
-
* than the one received
|
|
156
|
-
* 2. Core pipes are invoked in parallel. They are awaited for (promises-only)
|
|
157
|
-
* but their responses are neither evaluated nor used
|
|
158
|
-
* 3. Hooks are invoked in parallel. They are not awaited.
|
|
159
|
-
*
|
|
160
|
-
* Accepts a callback argument (to be used by pipes invoked before the funnel
|
|
161
|
-
* overload-protection mechanism). If a callback is provided, this method
|
|
162
|
-
* doesn't return a promise.
|
|
163
|
-
*
|
|
164
|
-
* @warning Critical section of code
|
|
165
|
-
*
|
|
166
|
-
* @param {string} event
|
|
167
|
-
* @param {*} payload
|
|
168
|
-
* @returns {Promise.<*>|null}
|
|
169
|
-
*/
|
|
170
|
-
pipe(event, ...payload) {
|
|
171
|
-
debug('Triggering pipe "%s" with payload: %o', event, payload);
|
|
172
|
-
|
|
173
|
-
let callback = null;
|
|
174
|
-
|
|
175
|
-
// safe: a pipe's payload can never contain functions
|
|
176
|
-
if (
|
|
177
|
-
payload.length > 0 &&
|
|
178
|
-
typeof payload[payload.length - 1] === "function"
|
|
179
|
-
) {
|
|
180
|
-
callback = payload.pop();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const events = getWildcardEvents(event);
|
|
184
|
-
const funcs = [];
|
|
185
|
-
|
|
186
|
-
for (let i = 0; i < events.length; i++) {
|
|
187
|
-
const targets = this.pluginPipes.get(events[i]);
|
|
188
|
-
|
|
189
|
-
if (targets) {
|
|
190
|
-
targets.forEach((t) => funcs.push(t));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Create a context for the emitPluginPipe callback
|
|
195
|
-
const promback = new Promback(callback);
|
|
196
|
-
const callbackContext = {
|
|
197
|
-
events,
|
|
198
|
-
instance: this,
|
|
199
|
-
promback,
|
|
200
|
-
targetEvent: event,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
if (funcs.length === 0) {
|
|
204
|
-
pipeCallback.call(callbackContext, null, ...payload);
|
|
205
|
-
} else {
|
|
206
|
-
this.pipeRunner.run(funcs, payload, pipeCallback, callbackContext);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return promback.deferred;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Emits an "ask" event to get information about the provided payload
|
|
214
|
-
*/
|
|
215
|
-
async ask(event, ...payload) {
|
|
216
|
-
debug('Triggering ask "%s" with payload: %o', event, payload);
|
|
217
|
-
|
|
218
|
-
const fn = this.coreAnswerers.get(event);
|
|
219
|
-
|
|
220
|
-
if (!fn) {
|
|
221
|
-
throw kerror.get(
|
|
222
|
-
"core",
|
|
223
|
-
"fatal",
|
|
224
|
-
"assertion_failed",
|
|
225
|
-
`the requested ask event '${event}' doesn't have an answerer`,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const response = await fn(...payload);
|
|
230
|
-
|
|
231
|
-
getWildcardEvents(event).forEach((ev) =>
|
|
232
|
-
super.emit(ev, {
|
|
233
|
-
args: payload,
|
|
234
|
-
response,
|
|
235
|
-
}),
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
return response;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Calls a callback to get information about the provided payload
|
|
243
|
-
*/
|
|
244
|
-
call(event, ...payload) {
|
|
245
|
-
debug('Triggering callback "%s" with payload: %o', event, payload);
|
|
246
|
-
|
|
247
|
-
const fn = this.coreSyncedAnswerers.get(event);
|
|
248
|
-
|
|
249
|
-
if (!fn) {
|
|
250
|
-
throw kerror.get(
|
|
251
|
-
"core",
|
|
252
|
-
"fatal",
|
|
253
|
-
"assertion_failed",
|
|
254
|
-
`the requested callback event '${event}' doesn't have an answerer`,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const response = fn(...payload);
|
|
259
|
-
|
|
260
|
-
getWildcardEvents(event).forEach((ev) =>
|
|
261
|
-
super.emit(ev, {
|
|
262
|
-
args: payload,
|
|
263
|
-
response,
|
|
264
|
-
}),
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
return response;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Registers a plugin hook.
|
|
272
|
-
* Catch any error in the handler and emit the hook:onError event.
|
|
273
|
-
*/
|
|
274
|
-
registerPluginHook(pluginName, event, fn) {
|
|
275
|
-
this.on(event, (...args) => {
|
|
276
|
-
try {
|
|
277
|
-
const ret = fn(...args, event);
|
|
278
|
-
|
|
279
|
-
if (typeof ret === "object" && typeof ret.catch === "function") {
|
|
280
|
-
ret.catch((error) => {
|
|
281
|
-
if (event !== "hook:onError") {
|
|
282
|
-
this.emit("hook:onError", { error, event, pluginName });
|
|
283
|
-
} else {
|
|
284
|
-
this.emit("plugin:hook:loop-error", { error, pluginName });
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
} catch (error) {
|
|
289
|
-
if (event !== "hook:onError") {
|
|
290
|
-
this.emit("hook:onError", { error, event, pluginName });
|
|
291
|
-
} else {
|
|
292
|
-
this.emit("plugin:hook:loop-error", { error, pluginName });
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
registerPluginPipe(event, handler) {
|
|
299
|
-
if (!this.pluginPipes.has(event)) {
|
|
300
|
-
this.pluginPipes.set(event, []);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
this.pluginPipes.get(event).push(handler);
|
|
304
|
-
|
|
305
|
-
const definition = new PluginPipeDefinition(event, handler);
|
|
306
|
-
|
|
307
|
-
this.pluginPipeDefinitions.set(definition.pipeId, definition);
|
|
308
|
-
|
|
309
|
-
return definition.pipeId;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
unregisterPluginPipe(pipeId) {
|
|
313
|
-
const definition = this.pluginPipeDefinitions.get(pipeId);
|
|
314
|
-
|
|
315
|
-
if (!definition) {
|
|
316
|
-
throw kerror.get("plugin", "runtime", "unknown_pipe", pipeId);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const handlers = this.pluginPipes.get(definition.event);
|
|
320
|
-
handlers.splice(handlers.indexOf(definition.handler), 1);
|
|
321
|
-
if (handlers.length > 0) {
|
|
322
|
-
this.pluginPipes.set(definition.event, handlers);
|
|
323
|
-
} else {
|
|
324
|
-
this.pluginPipes.delete(definition.event);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
this.pluginPipeDefinitions.delete(pipeId);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Checks if an ask event has an answerer
|
|
332
|
-
*
|
|
333
|
-
* @param {string} event
|
|
334
|
-
* @return {Boolean} [description]
|
|
335
|
-
*/
|
|
336
|
-
hasAskAnswerer(event) {
|
|
337
|
-
return this.coreAnswerers.has(event);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* We declare the callback used by Kuzzle.pipe one time instead
|
|
343
|
-
* of redeclaring a closure each time we want to run the pipes.
|
|
344
|
-
*
|
|
345
|
-
* The context of this callback must be bound to this following object:
|
|
346
|
-
* { instance: (kuzzle instance), promback, events }
|
|
347
|
-
*
|
|
348
|
-
* @warning Critical section of code
|
|
349
|
-
*/
|
|
350
|
-
async function pipeCallback(error, ...updated) {
|
|
351
|
-
/* eslint-disable no-invalid-this */
|
|
352
|
-
if (error) {
|
|
353
|
-
this.promback.reject(error);
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const corePipes = this.instance.corePipes.get(this.targetEvent);
|
|
358
|
-
|
|
359
|
-
if (corePipes) {
|
|
360
|
-
await Bluebird.map(corePipes, (fn) => fn(...updated));
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
for (let i = 0; i < this.events.length; i++) {
|
|
364
|
-
this.instance.superEmit(this.events[i], ...updated);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
this.promback.resolve(updated[0]);
|
|
368
|
-
/* eslint-enable no-invalid-this */
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* For a specific event, returns the event and all its wildcarded versions
|
|
373
|
-
* @example
|
|
374
|
-
* getWildcardEvents('data:create') // return ['data:create', 'data:*']
|
|
375
|
-
* getWildcardEvents('data:beforeCreate') // return ['data:beforeCreate',
|
|
376
|
-
* // 'data:*', 'data:before*']
|
|
377
|
-
*
|
|
378
|
-
* @warning Critical section of code
|
|
379
|
-
*
|
|
380
|
-
* @param {String} event
|
|
381
|
-
* @returns {Array<String>} wildcard events
|
|
382
|
-
*/
|
|
383
|
-
const getWildcardEvents = memoize((event) => {
|
|
384
|
-
const events = [event];
|
|
385
|
-
const delimIndex = event.lastIndexOf(":");
|
|
386
|
-
|
|
387
|
-
if (delimIndex === -1) {
|
|
388
|
-
return events;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const scope = event.slice(0, delimIndex);
|
|
392
|
-
const name = event.slice(delimIndex + 1);
|
|
393
|
-
|
|
394
|
-
["before", "after"].forEach((prefix) => {
|
|
395
|
-
if (name.startsWith(prefix)) {
|
|
396
|
-
events.push(`${scope}:${prefix}*`);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
events.push(`${scope}:*`);
|
|
401
|
-
|
|
402
|
-
return events;
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
module.exports = KuzzleEventEmitter;
|