kuzzle 2.29.0 → 2.29.1-beta.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/httpRoutes.js +0 -29
- package/lib/api/openapi/OpenApiManager.js +0 -32
- package/lib/api/openapi/openApiGenerator.js +1 -1
- package/lib/config/default.config.js +13 -0
- package/lib/core/backend/backendOpenApi.js +1 -13
- package/lib/kuzzle/kuzzle.d.ts +133 -0
- package/lib/kuzzle/kuzzle.js +62 -14
- package/lib/types/Global.d.ts +9 -7
- package/lib/types/Global.js +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -14
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +20 -0
- package/package.json +1 -1
- package/lib/api/openapi/components/document/count.yaml +0 -47
- package/lib/api/openapi/components/document/create.yaml +0 -46
- package/lib/api/openapi/components/document/createOrReplace.yaml +0 -61
- package/lib/api/openapi/components/document/delete.yaml +0 -67
- package/lib/api/openapi/components/document/deleteByQuery.yaml +0 -90
- package/lib/api/openapi/components/document/exists.yaml +0 -35
- package/lib/api/openapi/components/document/get.yaml +0 -68
- package/lib/api/openapi/components/document/index.d.ts +0 -24
- package/lib/api/openapi/components/document/index.js +0 -65
- package/lib/api/openapi/components/document/mCreateOrReplace.yaml +0 -93
- package/lib/api/openapi/components/document/replace.yaml +0 -66
- package/lib/api/openapi/components/document/scroll.yaml +0 -49
- package/lib/api/openapi/components/document/update.yaml +0 -78
- package/lib/api/openapi/components/document/validate.yaml +0 -42
- package/lib/api/openapi/components/index.d.ts +0 -3
- package/lib/api/openapi/components/index.js +0 -23
- package/lib/api/openapi/components/payloads.yaml +0 -32
- package/lib/api/openapi/components/security/index.d.ts +0 -2
- package/lib/api/openapi/components/security/index.js +0 -10
- package/lib/api/openapi/components/security/upsertUser.yaml +0 -58
package/lib/api/httpRoutes.js
CHANGED
|
@@ -23,22 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
"use strict";
|
|
25
25
|
|
|
26
|
-
const {
|
|
27
|
-
OpenApiDocumentCount,
|
|
28
|
-
OpenApiDocumentDeleteByQuery,
|
|
29
|
-
OpenApiDocumentDelete,
|
|
30
|
-
OpenApiDocumentScroll,
|
|
31
|
-
OpenApiDocumentExists,
|
|
32
|
-
OpenApiDocumentUpdate,
|
|
33
|
-
OpenApiDocumentReplace,
|
|
34
|
-
OpenApiDocumentGet,
|
|
35
|
-
OpenApiDocumentCreate,
|
|
36
|
-
OpenApiDocumentCreateOrReplace,
|
|
37
|
-
OpenApiDocumentValidate,
|
|
38
|
-
OpenApiSecurityUpsertUser,
|
|
39
|
-
OpenApiDocumentmCreateOrReplace,
|
|
40
|
-
} = require("./openapi/components");
|
|
41
|
-
|
|
42
26
|
const routes = [
|
|
43
27
|
// GET (idempotent)
|
|
44
28
|
{ verb: "get", path: "/_me", controller: "auth", action: "getCurrentUser" },
|
|
@@ -242,7 +226,6 @@ const routes = [
|
|
|
242
226
|
path: "/:index/:collection/:_id",
|
|
243
227
|
controller: "document",
|
|
244
228
|
action: "get",
|
|
245
|
-
openapi: OpenApiDocumentGet,
|
|
246
229
|
},
|
|
247
230
|
{
|
|
248
231
|
verb: "get",
|
|
@@ -255,7 +238,6 @@ const routes = [
|
|
|
255
238
|
path: "/:index/:collection/:_id/_exists",
|
|
256
239
|
controller: "document",
|
|
257
240
|
action: "exists",
|
|
258
|
-
openapi: OpenApiDocumentExists,
|
|
259
241
|
},
|
|
260
242
|
{
|
|
261
243
|
verb: "post",
|
|
@@ -268,7 +250,6 @@ const routes = [
|
|
|
268
250
|
path: "/_scroll/:scrollId",
|
|
269
251
|
controller: "document",
|
|
270
252
|
action: "scroll",
|
|
271
|
-
openapi: OpenApiDocumentScroll,
|
|
272
253
|
},
|
|
273
254
|
|
|
274
255
|
{
|
|
@@ -770,14 +751,12 @@ const routes = [
|
|
|
770
751
|
path: "/:index/:collection/_count",
|
|
771
752
|
controller: "document",
|
|
772
753
|
action: "count",
|
|
773
|
-
openapi: OpenApiDocumentCount,
|
|
774
754
|
},
|
|
775
755
|
{
|
|
776
756
|
verb: "post",
|
|
777
757
|
path: "/:index/:collection/_create",
|
|
778
758
|
controller: "document",
|
|
779
759
|
action: "create",
|
|
780
|
-
openapi: OpenApiDocumentCreate,
|
|
781
760
|
},
|
|
782
761
|
{
|
|
783
762
|
verb: "post",
|
|
@@ -832,7 +811,6 @@ const routes = [
|
|
|
832
811
|
path: "/:index/:collection/_validate",
|
|
833
812
|
controller: "document",
|
|
834
813
|
action: "validate",
|
|
835
|
-
openapi: OpenApiDocumentValidate,
|
|
836
814
|
},
|
|
837
815
|
|
|
838
816
|
{
|
|
@@ -955,7 +933,6 @@ const routes = [
|
|
|
955
933
|
path: "/users/:_id/_upsert",
|
|
956
934
|
controller: "security",
|
|
957
935
|
action: "upsertUser",
|
|
958
|
-
openapi: OpenApiSecurityUpsertUser,
|
|
959
936
|
},
|
|
960
937
|
{
|
|
961
938
|
verb: "post",
|
|
@@ -1241,7 +1218,6 @@ const routes = [
|
|
|
1241
1218
|
path: "/:index/:collection/:_id",
|
|
1242
1219
|
controller: "document",
|
|
1243
1220
|
action: "delete",
|
|
1244
|
-
openapi: OpenApiDocumentDelete,
|
|
1245
1221
|
},
|
|
1246
1222
|
{
|
|
1247
1223
|
verb: "delete",
|
|
@@ -1254,7 +1230,6 @@ const routes = [
|
|
|
1254
1230
|
path: "/:index/:collection/_query",
|
|
1255
1231
|
controller: "document",
|
|
1256
1232
|
action: "deleteByQuery",
|
|
1257
|
-
openapi: OpenApiDocumentDeleteByQuery,
|
|
1258
1233
|
},
|
|
1259
1234
|
{
|
|
1260
1235
|
verb: "delete",
|
|
@@ -1421,21 +1396,18 @@ const routes = [
|
|
|
1421
1396
|
path: "/:index/:collection/:_id",
|
|
1422
1397
|
controller: "document",
|
|
1423
1398
|
action: "createOrReplace",
|
|
1424
|
-
openapi: OpenApiDocumentCreateOrReplace,
|
|
1425
1399
|
},
|
|
1426
1400
|
{
|
|
1427
1401
|
verb: "put",
|
|
1428
1402
|
path: "/:index/:collection/_mCreateOrReplace",
|
|
1429
1403
|
controller: "document",
|
|
1430
1404
|
action: "mCreateOrReplace",
|
|
1431
|
-
openapi: OpenApiDocumentmCreateOrReplace,
|
|
1432
1405
|
},
|
|
1433
1406
|
{
|
|
1434
1407
|
verb: "put",
|
|
1435
1408
|
path: "/:index/:collection/:_id/_replace",
|
|
1436
1409
|
controller: "document",
|
|
1437
1410
|
action: "replace",
|
|
1438
|
-
openapi: OpenApiDocumentReplace,
|
|
1439
1411
|
},
|
|
1440
1412
|
{
|
|
1441
1413
|
verb: "put",
|
|
@@ -1458,7 +1430,6 @@ const routes = [
|
|
|
1458
1430
|
path: "/:index/:collection/:_id/_update",
|
|
1459
1431
|
controller: "document",
|
|
1460
1432
|
action: "update",
|
|
1461
|
-
openapi: OpenApiDocumentUpdate,
|
|
1462
1433
|
deprecated: {
|
|
1463
1434
|
since: "2.11.0",
|
|
1464
1435
|
message: 'Use "document:update" route with PATCH instead of PUT',
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.OpenApiManager = void 0;
|
|
24
|
-
const components_1 = require("./components");
|
|
25
24
|
const package_json_1 = require("../../../package.json");
|
|
26
25
|
const openApiGenerator_1 = require("./openApiGenerator");
|
|
27
26
|
class OpenApiManager {
|
|
@@ -40,7 +39,6 @@ class OpenApiManager {
|
|
|
40
39
|
name: "Kuzzle team",
|
|
41
40
|
url: "https://kuzzle.io",
|
|
42
41
|
email: "support@kuzzle.io",
|
|
43
|
-
discord: "http://join.discord.kuzzle.io",
|
|
44
42
|
},
|
|
45
43
|
license: {
|
|
46
44
|
name: "Apache 2",
|
|
@@ -52,39 +50,9 @@ class OpenApiManager {
|
|
|
52
50
|
description: "Kuzzle API Documentation",
|
|
53
51
|
url: "https://docs.kuzzle.io/core/2/api/",
|
|
54
52
|
},
|
|
55
|
-
servers: [
|
|
56
|
-
{
|
|
57
|
-
url: "https://{baseUrl}:{port}",
|
|
58
|
-
description: "Kuzzle Base Url",
|
|
59
|
-
variables: {
|
|
60
|
-
baseUrl: { default: "localhost" },
|
|
61
|
-
port: { default: 7512 },
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
53
|
tags: [],
|
|
66
54
|
schemes: ["https", "http"],
|
|
67
55
|
paths: {},
|
|
68
|
-
components: {
|
|
69
|
-
...components_1.OpenApiPayloadsDefinitions,
|
|
70
|
-
document: {
|
|
71
|
-
...components_1.OpenApiDocumentCountComponent,
|
|
72
|
-
...components_1.OpenApiDocumentDeleteByQueryComponent,
|
|
73
|
-
...components_1.OpenApiDocumentDeleteComponent,
|
|
74
|
-
...components_1.OpenApiDocumentScrollComponent,
|
|
75
|
-
...components_1.OpenApiDocumentExistsComponent,
|
|
76
|
-
...components_1.OpenApiDocumentUpdateComponent,
|
|
77
|
-
...components_1.OpenApiDocumentReplaceComponent,
|
|
78
|
-
...components_1.OpenApiDocumentGetComponent,
|
|
79
|
-
...components_1.OpenApiDocumentCreateOrReplaceComponent,
|
|
80
|
-
...components_1.OpenApiDocumentCreateComponent,
|
|
81
|
-
...components_1.OpenApiDocumentValidateComponent,
|
|
82
|
-
},
|
|
83
|
-
security: {
|
|
84
|
-
...components_1.OpenApiSecurityUpsertUserComponent,
|
|
85
|
-
...components_1.OpenApiDocumentmCreateOrReplaceComponent,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
56
|
};
|
|
89
57
|
this.applicationDefinition = applicationDefinition;
|
|
90
58
|
(0, openApiGenerator_1.generateOpenApi)(kuzzleRoutes, this.kuzzleDefinition);
|
|
@@ -416,6 +416,19 @@ const defaultConfig = {
|
|
|
416
416
|
},
|
|
417
417
|
},
|
|
418
418
|
},
|
|
419
|
+
imports: {
|
|
420
|
+
settings: {
|
|
421
|
+
// @deprecated : replace undefined by 1
|
|
422
|
+
number_of_shards: 1,
|
|
423
|
+
number_of_replicas: 1,
|
|
424
|
+
},
|
|
425
|
+
mappings: {
|
|
426
|
+
dynamic: "strict",
|
|
427
|
+
properties: {
|
|
428
|
+
hash: { type: "keyword" },
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
},
|
|
419
432
|
},
|
|
420
433
|
},
|
|
421
434
|
maxScrollDuration: "1m",
|
|
@@ -27,7 +27,7 @@ class BackendOpenApi extends index_1.ApplicationManager {
|
|
|
27
27
|
super(application);
|
|
28
28
|
/* eslint-disable sort-keys */
|
|
29
29
|
this.definition = {
|
|
30
|
-
openapi: "3.
|
|
30
|
+
openapi: "3.1.0",
|
|
31
31
|
info: {
|
|
32
32
|
title: `${application.name} API`,
|
|
33
33
|
description: `${application.name} HTTP API definition`,
|
|
@@ -35,7 +35,6 @@ class BackendOpenApi extends index_1.ApplicationManager {
|
|
|
35
35
|
name: "Kuzzle team",
|
|
36
36
|
url: "https://kuzzle.io",
|
|
37
37
|
email: "support@kuzzle.io",
|
|
38
|
-
discord: "http://join.discord.kuzzle.io",
|
|
39
38
|
},
|
|
40
39
|
license: {
|
|
41
40
|
name: "Apache 2",
|
|
@@ -47,20 +46,9 @@ class BackendOpenApi extends index_1.ApplicationManager {
|
|
|
47
46
|
description: "Kuzzle API Documentation",
|
|
48
47
|
url: "https://docs.kuzzle.io/core/2/api/",
|
|
49
48
|
},
|
|
50
|
-
servers: [
|
|
51
|
-
{
|
|
52
|
-
url: "https://{baseUrl}:{port}",
|
|
53
|
-
description: `${application.name} Base Url`,
|
|
54
|
-
variables: {
|
|
55
|
-
baseUrl: { default: "localhost" },
|
|
56
|
-
port: { default: 7512 },
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
49
|
tags: [],
|
|
61
50
|
schemes: ["https", "http"],
|
|
62
51
|
paths: {},
|
|
63
|
-
components: {},
|
|
64
52
|
};
|
|
65
53
|
/* eslint-enable sort-keys */
|
|
66
54
|
}
|
package/lib/kuzzle/kuzzle.d.ts
CHANGED
|
@@ -1 +1,134 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import KuzzleEventEmitter from "./event/kuzzleEventEmitter";
|
|
3
|
+
import { InstallationConfig, ImportConfig, SupportConfig, StartOptions } from "./../types/Kuzzle";
|
|
4
|
+
import { KuzzleConfiguration } from "../types/config/KuzzleConfiguration";
|
|
1
5
|
export declare const BACKEND_IMPORT_KEY = "backend:init:import";
|
|
6
|
+
declare class Kuzzle extends KuzzleEventEmitter {
|
|
7
|
+
private config;
|
|
8
|
+
private _state;
|
|
9
|
+
private log;
|
|
10
|
+
private rootPath;
|
|
11
|
+
/**
|
|
12
|
+
* Internal index bootstrapper and accessor
|
|
13
|
+
*/
|
|
14
|
+
private internalIndex;
|
|
15
|
+
private pluginsManager;
|
|
16
|
+
private tokenManager;
|
|
17
|
+
private passport;
|
|
18
|
+
/**
|
|
19
|
+
* The funnel dispatches messages to API controllers
|
|
20
|
+
*/
|
|
21
|
+
private funnel;
|
|
22
|
+
/**
|
|
23
|
+
* The router listens to client requests and pass them to the funnel
|
|
24
|
+
*/
|
|
25
|
+
private router;
|
|
26
|
+
/**
|
|
27
|
+
* Statistics core component
|
|
28
|
+
*/
|
|
29
|
+
private statistics;
|
|
30
|
+
/**
|
|
31
|
+
* Network entry point
|
|
32
|
+
*/
|
|
33
|
+
private entryPoint;
|
|
34
|
+
/**
|
|
35
|
+
* Validation core component
|
|
36
|
+
*/
|
|
37
|
+
private validation;
|
|
38
|
+
/**
|
|
39
|
+
* Dump generator
|
|
40
|
+
*/
|
|
41
|
+
private dumpGenerator;
|
|
42
|
+
/**
|
|
43
|
+
* Vault component (will be initialized after bootstrap)
|
|
44
|
+
*/
|
|
45
|
+
private vault;
|
|
46
|
+
/**
|
|
47
|
+
* AsyncLocalStorage wrapper
|
|
48
|
+
*/
|
|
49
|
+
private asyncStore;
|
|
50
|
+
/**
|
|
51
|
+
* Kuzzle internal debugger
|
|
52
|
+
*/
|
|
53
|
+
private debugger;
|
|
54
|
+
/**
|
|
55
|
+
* Kuzzle version
|
|
56
|
+
*/
|
|
57
|
+
private version;
|
|
58
|
+
private openApiManager;
|
|
59
|
+
/**
|
|
60
|
+
* List of differents imports types and their associated method
|
|
61
|
+
*/
|
|
62
|
+
private importTypes;
|
|
63
|
+
private koncorde;
|
|
64
|
+
private secret;
|
|
65
|
+
/**
|
|
66
|
+
* Node unique ID amongst other cluster nodes
|
|
67
|
+
*/
|
|
68
|
+
id: string;
|
|
69
|
+
constructor(config: KuzzleConfiguration);
|
|
70
|
+
/**
|
|
71
|
+
* Initializes all the needed components of Kuzzle.
|
|
72
|
+
*
|
|
73
|
+
* @param {Application} - Application Plugin instance
|
|
74
|
+
* @param {Object} - Additional options (import, installations, plugins, secretsFile, support, vaultKey)
|
|
75
|
+
*
|
|
76
|
+
* @this {Kuzzle}
|
|
77
|
+
*/
|
|
78
|
+
start(application: any, options?: StartOptions): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Generates the node ID.
|
|
81
|
+
*
|
|
82
|
+
* This will init the cluster if it's enabled.
|
|
83
|
+
*/
|
|
84
|
+
private initKuzzleNode;
|
|
85
|
+
/**
|
|
86
|
+
* Gracefully exits after processing remaining requests
|
|
87
|
+
*
|
|
88
|
+
* @returns {Promise}
|
|
89
|
+
*/
|
|
90
|
+
shutdown(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Execute multiple handlers only once on any given environment
|
|
93
|
+
*
|
|
94
|
+
* @param {Array<{ id: string, handler: () => void, description?: string }>} installations - Array of unique methods to execute
|
|
95
|
+
*
|
|
96
|
+
* @returns {Promise<void>}
|
|
97
|
+
*/
|
|
98
|
+
install(installations: InstallationConfig[]): Promise<void>;
|
|
99
|
+
ask(...args: any[]): Promise<any>;
|
|
100
|
+
emit(...args: any[]): Promise<any>;
|
|
101
|
+
pipe(...args: any[]): Promise<any>;
|
|
102
|
+
private importUserMappings;
|
|
103
|
+
private importMappings;
|
|
104
|
+
private importFixtures;
|
|
105
|
+
private importPermissions;
|
|
106
|
+
/**
|
|
107
|
+
* Check if every import has been done, if one of them is not finished yet, wait for it
|
|
108
|
+
*/
|
|
109
|
+
private _waitForImportToFinish;
|
|
110
|
+
private isConfigsEmpty;
|
|
111
|
+
private persistHashedImport;
|
|
112
|
+
/**
|
|
113
|
+
* Load into the app several imports
|
|
114
|
+
*
|
|
115
|
+
* @param {Object} toImport - Contains `mappings`, `onExistingUsers`, `profiles`, `roles`, `userMappings`, `users`
|
|
116
|
+
* @param {Object} toSupport - Contains `fixtures`, `mappings`, `securities` (`profiles`, `roles`, `users`)
|
|
117
|
+
*
|
|
118
|
+
* @returns {Promise<void>}
|
|
119
|
+
*/
|
|
120
|
+
loadInitialState(toImport?: ImportConfig, toSupport?: SupportConfig): Promise<void>;
|
|
121
|
+
dump(suffix: any): any;
|
|
122
|
+
hash(input: any): string | Buffer;
|
|
123
|
+
get state(): kuzzleStateEnum;
|
|
124
|
+
set state(value: kuzzleStateEnum);
|
|
125
|
+
/**
|
|
126
|
+
* Register handlers and do a kuzzle dump for:
|
|
127
|
+
* - system signals
|
|
128
|
+
* - unhandled-rejection
|
|
129
|
+
* - uncaught-exception
|
|
130
|
+
*/
|
|
131
|
+
registerSignalHandlers(): void;
|
|
132
|
+
dumpAndExit(suffix: any): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
export { Kuzzle };
|
package/lib/kuzzle/kuzzle.js
CHANGED
|
@@ -46,7 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
47
|
};
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
exports.BACKEND_IMPORT_KEY = void 0;
|
|
49
|
+
exports.Kuzzle = exports.BACKEND_IMPORT_KEY = void 0;
|
|
50
50
|
const path_1 = __importDefault(require("path"));
|
|
51
51
|
const murmurhash_native_1 = require("murmurhash-native");
|
|
52
52
|
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
@@ -382,6 +382,45 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
382
382
|
await bluebird_1.default.delay(1000);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
+
isConfigsEmpty(importConfig, supportConfig) {
|
|
386
|
+
if (lodash_1.default.isEmpty(importConfig.mappings) &&
|
|
387
|
+
lodash_1.default.isEmpty(importConfig.profiles) &&
|
|
388
|
+
lodash_1.default.isEmpty(importConfig.roles) &&
|
|
389
|
+
lodash_1.default.isEmpty(importConfig.userMappings) &&
|
|
390
|
+
lodash_1.default.isEmpty(importConfig.users) &&
|
|
391
|
+
lodash_1.default.isEmpty(supportConfig.fixtures) &&
|
|
392
|
+
lodash_1.default.isEmpty(supportConfig.mappings) &&
|
|
393
|
+
lodash_1.default.isEmpty(supportConfig.securities)) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
async persistHashedImport({ existingRedisHash, existingESHash, importPayloadHash, type, }) {
|
|
399
|
+
if (!existingRedisHash && !existingESHash) {
|
|
400
|
+
// If the import is not initialized in the redis cache and in the ES, we initialize it
|
|
401
|
+
this.log.info(`${type} import is not initialized, initializing...`);
|
|
402
|
+
await this.ask("core:storage:private:document:create", "kuzzle", "imports", {
|
|
403
|
+
hash: importPayloadHash,
|
|
404
|
+
}, { id: `${exports.BACKEND_IMPORT_KEY}:${type}` });
|
|
405
|
+
await this.ask("core:cache:internal:store", `${exports.BACKEND_IMPORT_KEY}:${type}`, importPayloadHash);
|
|
406
|
+
}
|
|
407
|
+
else if (existingRedisHash && !existingESHash) {
|
|
408
|
+
// If the import is initialized in the redis cache but not in the ES
|
|
409
|
+
// We initialize it in the ES
|
|
410
|
+
this.log.info(`${type} import is not initialized in %kuzzle.imports, initializing...`);
|
|
411
|
+
const redisCache = await this.ask("core:cache:internal:get", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
412
|
+
await this.ask("core:storage:private:document:create", "kuzzle", "imports", {
|
|
413
|
+
hash: redisCache,
|
|
414
|
+
}, { id: `${exports.BACKEND_IMPORT_KEY}:${type}` });
|
|
415
|
+
}
|
|
416
|
+
else if (!existingRedisHash && existingESHash) {
|
|
417
|
+
// If the import is initialized in the ES but not in the redis cache
|
|
418
|
+
// We initialize it in the redis cache
|
|
419
|
+
this.log.info(`${type} import is not initialized in the redis cache, initializing...`);
|
|
420
|
+
const esDocument = await this.ask("core:storage:private:document:get", "kuzzle", "imports", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
421
|
+
await this.ask("core:cache:internal:store", `${exports.BACKEND_IMPORT_KEY}:${type}`, esDocument._source.hash);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
385
424
|
/**
|
|
386
425
|
* Load into the app several imports
|
|
387
426
|
*
|
|
@@ -391,14 +430,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
391
430
|
* @returns {Promise<void>}
|
|
392
431
|
*/
|
|
393
432
|
async loadInitialState(toImport = {}, toSupport = {}) {
|
|
394
|
-
if (
|
|
395
|
-
lodash_1.default.isEmpty(toImport.profiles) &&
|
|
396
|
-
lodash_1.default.isEmpty(toImport.roles) &&
|
|
397
|
-
lodash_1.default.isEmpty(toImport.userMappings) &&
|
|
398
|
-
lodash_1.default.isEmpty(toImport.users) &&
|
|
399
|
-
lodash_1.default.isEmpty(toSupport.fixtures) &&
|
|
400
|
-
lodash_1.default.isEmpty(toSupport.mappings) &&
|
|
401
|
-
lodash_1.default.isEmpty(toSupport.securities)) {
|
|
433
|
+
if (this.isConfigsEmpty(toImport, toSupport)) {
|
|
402
434
|
return;
|
|
403
435
|
}
|
|
404
436
|
const lockedMutex = [];
|
|
@@ -422,17 +454,32 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
422
454
|
}
|
|
423
455
|
const importPayloadHash = (0, crypto_1.sha256)((0, json_stable_stringify_1.default)(importPayload));
|
|
424
456
|
const mutex = new mutex_1.Mutex(`backend:import:${type}`, { timeout: 0 });
|
|
425
|
-
const
|
|
426
|
-
const
|
|
457
|
+
const existingRedisHash = await this.ask("core:cache:internal:get", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
458
|
+
const existingESHash = await this.ask("core:storage:private:document:exist", "kuzzle", "imports", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
459
|
+
let initialized = false;
|
|
460
|
+
if (existingRedisHash) {
|
|
461
|
+
// Check if the import is already initialized inside the redis cache
|
|
462
|
+
initialized = existingRedisHash === importPayloadHash;
|
|
463
|
+
}
|
|
464
|
+
else if (existingESHash) {
|
|
465
|
+
// Check if the import is already initialized inside the ES
|
|
466
|
+
const esDocument = await this.ask("core:storage:private:document:get", "kuzzle", "imports", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
467
|
+
initialized = esDocument._source.hash === importPayloadHash;
|
|
468
|
+
}
|
|
427
469
|
const locked = await mutex.lock();
|
|
428
470
|
await importMethod({ toImport, toSupport }, {
|
|
429
471
|
firstCall: !initialized && locked,
|
|
430
|
-
initialized,
|
|
472
|
+
initialized: initialized,
|
|
431
473
|
locked,
|
|
432
474
|
});
|
|
433
|
-
if (
|
|
475
|
+
if (locked) {
|
|
434
476
|
lockedMutex.push(mutex);
|
|
435
|
-
await this.
|
|
477
|
+
await this.persistHashedImport({
|
|
478
|
+
existingESHash,
|
|
479
|
+
existingRedisHash,
|
|
480
|
+
importPayloadHash,
|
|
481
|
+
type,
|
|
482
|
+
});
|
|
436
483
|
}
|
|
437
484
|
}
|
|
438
485
|
await this._waitForImportToFinish();
|
|
@@ -536,5 +583,6 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
536
583
|
await this.shutdown();
|
|
537
584
|
}
|
|
538
585
|
}
|
|
586
|
+
exports.Kuzzle = Kuzzle;
|
|
539
587
|
module.exports = Kuzzle;
|
|
540
588
|
//# sourceMappingURL=kuzzle.js.map
|
package/lib/types/Global.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Backend } from "../core/backend";
|
|
2
|
+
import { Kuzzle } from "../kuzzle";
|
|
3
|
+
/**
|
|
4
|
+
* This file contains global type declarations for Kuzzle.
|
|
5
|
+
* We need to use `var` so Typescript extends the globalThis type.
|
|
6
|
+
* See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis
|
|
7
|
+
*/
|
|
2
8
|
declare global {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
app: Backend;
|
|
7
|
-
NODE_ENV: string;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
9
|
+
var app: Backend;
|
|
10
|
+
var kuzzle: Kuzzle;
|
|
11
|
+
var NODE_ENV: string;
|
|
10
12
|
}
|
|
11
13
|
export {};
|
package/lib/types/Global.js
CHANGED
|
@@ -9,7 +9,6 @@ export type OpenApiDefinition = {
|
|
|
9
9
|
name: string;
|
|
10
10
|
url: string;
|
|
11
11
|
email: string;
|
|
12
|
-
discord: string;
|
|
13
12
|
};
|
|
14
13
|
license: {
|
|
15
14
|
name: string;
|
|
@@ -21,23 +20,11 @@ export type OpenApiDefinition = {
|
|
|
21
20
|
description: string;
|
|
22
21
|
url: string;
|
|
23
22
|
};
|
|
24
|
-
servers: Array<{
|
|
25
|
-
url: string;
|
|
26
|
-
description: string;
|
|
27
|
-
variables: {
|
|
28
|
-
baseUrl: {
|
|
29
|
-
default: string;
|
|
30
|
-
};
|
|
31
|
-
port: {
|
|
32
|
-
default: number;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
}>;
|
|
36
23
|
tags: Array<{
|
|
37
24
|
description: string;
|
|
38
25
|
name: string;
|
|
39
26
|
}>;
|
|
40
27
|
schemes: string[];
|
|
41
28
|
paths: JSONObject;
|
|
42
|
-
components
|
|
29
|
+
components?: JSONObject;
|
|
43
30
|
};
|
|
@@ -316,6 +316,26 @@ export type StorageEngineElasticsearch = {
|
|
|
316
316
|
};
|
|
317
317
|
};
|
|
318
318
|
};
|
|
319
|
+
imports: {
|
|
320
|
+
settings: {
|
|
321
|
+
/**
|
|
322
|
+
* @default 1
|
|
323
|
+
*/
|
|
324
|
+
number_of_shards: number;
|
|
325
|
+
/**
|
|
326
|
+
* @default 1
|
|
327
|
+
*/
|
|
328
|
+
number_of_replicas: number;
|
|
329
|
+
};
|
|
330
|
+
mappings: {
|
|
331
|
+
dynamic: "strict";
|
|
332
|
+
properties: {
|
|
333
|
+
hash: {
|
|
334
|
+
type: "keyword";
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
};
|
|
319
339
|
};
|
|
320
340
|
};
|
|
321
341
|
maxScrollDuration: string;
|
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.29.
|
|
4
|
+
"version": "2.29.1-beta.2",
|
|
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": {
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
DocumentCount:
|
|
2
|
-
summary: "Counts documents in a collection."
|
|
3
|
-
tags:
|
|
4
|
-
- document
|
|
5
|
-
parameters:
|
|
6
|
-
- in: path
|
|
7
|
-
name: index
|
|
8
|
-
schema:
|
|
9
|
-
type: string
|
|
10
|
-
- in: path
|
|
11
|
-
name: collection
|
|
12
|
-
schema:
|
|
13
|
-
type: string
|
|
14
|
-
- in: body
|
|
15
|
-
name: "body"
|
|
16
|
-
description: "Counts documents in a collection."
|
|
17
|
-
required: true
|
|
18
|
-
schema:
|
|
19
|
-
$ref: "#/components/document/DocumentCountRequest"
|
|
20
|
-
responses:
|
|
21
|
-
200:
|
|
22
|
-
description: "Counts documents in a collection."
|
|
23
|
-
schema:
|
|
24
|
-
$ref: "#/components/document/DocumentCountResponse"
|
|
25
|
-
|
|
26
|
-
components:
|
|
27
|
-
schemas:
|
|
28
|
-
DocumentCountRequest:
|
|
29
|
-
allOf:
|
|
30
|
-
- type: "object"
|
|
31
|
-
properties:
|
|
32
|
-
query:
|
|
33
|
-
type: "object"
|
|
34
|
-
properties:
|
|
35
|
-
match_all:
|
|
36
|
-
type: "object"
|
|
37
|
-
|
|
38
|
-
DocumentCountResponse:
|
|
39
|
-
allOf:
|
|
40
|
-
- $ref: "#/components/ResponsePayload"
|
|
41
|
-
- type: "object"
|
|
42
|
-
properties:
|
|
43
|
-
result:
|
|
44
|
-
type: "object"
|
|
45
|
-
properties:
|
|
46
|
-
count:
|
|
47
|
-
type: "integer"
|