kuzzle 2.16.11 → 2.17.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.
Files changed (187) hide show
  1. package/lib/api/controllers/adminController.js +3 -3
  2. package/lib/api/controllers/authController.js +12 -12
  3. package/lib/api/controllers/baseController.js +60 -3
  4. package/lib/api/controllers/clusterController.js +1 -1
  5. package/lib/api/controllers/collectionController.js +7 -5
  6. package/lib/api/controllers/documentController.js +130 -17
  7. package/lib/api/controllers/indexController.js +1 -1
  8. package/lib/api/controllers/memoryStorageController.js +39 -38
  9. package/lib/api/controllers/realtimeController.js +1 -1
  10. package/lib/api/controllers/securityController.js +50 -50
  11. package/lib/api/controllers/serverController.js +73 -27
  12. package/lib/api/documentExtractor.js +3 -3
  13. package/lib/api/funnel.js +44 -21
  14. package/lib/api/httpRoutes.js +9 -4
  15. package/lib/api/openapi/OpenApiManager.d.ts +11 -0
  16. package/lib/api/openapi/OpenApiManager.js +96 -0
  17. package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
  18. package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
  19. package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
  20. package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
  21. package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
  22. package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
  23. package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
  24. package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
  25. package/lib/api/openapi/{document → components/document}/index.js +7 -2
  26. package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
  27. package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
  28. package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
  29. package/lib/api/openapi/components/document/validate.yaml +42 -0
  30. package/lib/api/openapi/components/index.d.ts +2 -0
  31. package/lib/api/openapi/components/index.js +18 -0
  32. package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
  33. package/lib/api/openapi/index.d.ts +1 -2
  34. package/lib/api/openapi/index.js +1 -5
  35. package/lib/api/openapi/openApiGenerator.d.ts +7 -0
  36. package/lib/api/openapi/openApiGenerator.js +133 -0
  37. package/lib/api/request/kuzzleRequest.js +8 -6
  38. package/lib/cluster/node.js +9 -9
  39. package/lib/cluster/publisher.js +1 -1
  40. package/lib/cluster/state.js +20 -4
  41. package/lib/cluster/subscriber.js +1 -1
  42. package/lib/cluster/workers/IDCardRenewer.js +2 -2
  43. package/lib/config/default.config.js +1 -0
  44. package/lib/config/index.js +6 -6
  45. package/lib/core/auth/passportResponse.js +6 -6
  46. package/lib/core/auth/passportWrapper.js +5 -5
  47. package/lib/core/backend/backend.d.ts +11 -3
  48. package/lib/core/backend/backend.js +22 -17
  49. package/lib/core/backend/backendConfig.d.ts +5 -1
  50. package/lib/core/backend/backendConfig.js +25 -2
  51. package/lib/core/backend/backendController.js +21 -5
  52. package/lib/core/backend/backendErrors.d.ts +58 -0
  53. package/lib/core/backend/backendErrors.js +121 -0
  54. package/lib/core/backend/backendHook.js +21 -5
  55. package/lib/core/backend/backendImport.js +21 -5
  56. package/lib/core/backend/backendOpenApi.d.ts +9 -0
  57. package/lib/core/backend/backendOpenApi.js +69 -0
  58. package/lib/core/backend/backendPipe.js +21 -5
  59. package/lib/core/backend/backendPlugin.js +22 -3
  60. package/lib/core/backend/backendVault.js +21 -2
  61. package/lib/core/backend/index.d.ts +2 -0
  62. package/lib/core/backend/index.js +2 -0
  63. package/lib/core/network/accessLogger.js +6 -6
  64. package/lib/core/network/clientConnection.js +1 -1
  65. package/lib/core/network/entryPoint.js +5 -5
  66. package/lib/core/network/httpRouter/index.js +5 -5
  67. package/lib/core/network/httpRouter/routeHandler.js +3 -3
  68. package/lib/core/network/httpRouter/routePart.js +5 -5
  69. package/lib/core/network/protocolManifest.js +1 -1
  70. package/lib/core/network/protocols/httpMessage.js +2 -2
  71. package/lib/core/network/protocols/httpwsProtocol.js +228 -50
  72. package/lib/core/network/protocols/mqttProtocol.js +3 -3
  73. package/lib/core/network/protocols/protocol.js +3 -3
  74. package/lib/core/network/router.js +7 -6
  75. package/lib/core/plugin/plugin.js +38 -64
  76. package/lib/core/plugin/pluginContext.js +22 -3
  77. package/lib/core/plugin/pluginManifest.js +3 -3
  78. package/lib/core/plugin/pluginRepository.js +5 -5
  79. package/lib/core/plugin/pluginsManager.js +29 -28
  80. package/lib/core/realtime/channel.js +20 -4
  81. package/lib/core/realtime/hotelClerk.js +24 -5
  82. package/lib/core/realtime/notification/server.js +1 -1
  83. package/lib/core/realtime/notification/user.js +1 -1
  84. package/lib/core/realtime/notifier.js +5 -5
  85. package/lib/core/security/index.js +1 -1
  86. package/lib/core/security/profileRepository.d.ts +176 -0
  87. package/lib/core/security/profileRepository.js +445 -443
  88. package/lib/core/security/roleRepository.js +16 -16
  89. package/lib/core/security/securityLoader.js +2 -2
  90. package/lib/core/security/tokenRepository.js +11 -11
  91. package/lib/core/security/userRepository.js +8 -8
  92. package/lib/core/shared/abstractManifest.js +4 -4
  93. package/lib/core/shared/repository.js +5 -5
  94. package/lib/core/shared/sdk/embeddedSdk.js +21 -2
  95. package/lib/core/shared/sdk/funnelProtocol.js +1 -1
  96. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  97. package/lib/core/shared/store.js +30 -23
  98. package/lib/core/statistics/statistics.js +17 -17
  99. package/lib/core/storage/clientAdapter.js +45 -10
  100. package/lib/core/storage/indexCache.js +20 -4
  101. package/lib/core/validation/baseType.js +5 -5
  102. package/lib/core/validation/types/anything.js +1 -1
  103. package/lib/core/validation/types/boolean.js +2 -2
  104. package/lib/core/validation/types/date.js +9 -9
  105. package/lib/core/validation/types/email.js +5 -5
  106. package/lib/core/validation/types/enum.js +6 -6
  107. package/lib/core/validation/types/geoPoint.js +2 -2
  108. package/lib/core/validation/types/geoShape.js +28 -25
  109. package/lib/core/validation/types/integer.js +4 -4
  110. package/lib/core/validation/types/ipAddress.js +7 -6
  111. package/lib/core/validation/types/numeric.js +4 -4
  112. package/lib/core/validation/types/object.js +5 -5
  113. package/lib/core/validation/types/string.js +5 -5
  114. package/lib/core/validation/types/url.js +7 -6
  115. package/lib/core/validation/validation.js +95 -84
  116. package/lib/kerror/codes/1-services.json +12 -0
  117. package/lib/kerror/codes/2-api.json +12 -0
  118. package/lib/kerror/codes/3-network.json +12 -0
  119. package/lib/kerror/codes/4-plugin.json +6 -0
  120. package/lib/kerror/codes/index.js +11 -11
  121. package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
  122. package/lib/kerror/errors/multipleErrorsError.js +3 -3
  123. package/lib/kerror/index.d.ts +82 -0
  124. package/lib/kerror/index.js +176 -143
  125. package/lib/kuzzle/dumpGenerator.js +3 -3
  126. package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
  127. package/lib/kuzzle/event/pipeRunner.js +1 -1
  128. package/lib/kuzzle/event/waterfall.js +6 -6
  129. package/lib/kuzzle/kuzzle.js +59 -9
  130. package/lib/kuzzle/log.js +3 -3
  131. package/lib/kuzzle/vault.js +3 -3
  132. package/lib/model/security/profile.d.ts +54 -0
  133. package/lib/model/security/profile.js +192 -232
  134. package/lib/model/security/rights.js +1 -1
  135. package/lib/model/security/role.d.ts +40 -0
  136. package/lib/model/security/role.js +174 -190
  137. package/lib/model/security/user.d.ts +29 -0
  138. package/lib/model/security/user.js +103 -52
  139. package/lib/model/storage/apiKey.js +2 -2
  140. package/lib/model/storage/baseModel.js +3 -3
  141. package/lib/service/cache/redis.js +7 -7
  142. package/lib/service/storage/elasticsearch.js +152 -90
  143. package/lib/service/storage/esWrapper.js +2 -3
  144. package/lib/types/ControllerDefinition.d.ts +3 -3
  145. package/lib/types/ControllerRights.d.ts +22 -0
  146. package/lib/types/ControllerRights.js +23 -0
  147. package/lib/types/HttpStream.d.ts +32 -0
  148. package/lib/types/HttpStream.js +70 -0
  149. package/lib/types/OpenApiDefinition.d.ts +43 -0
  150. package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
  151. package/lib/types/Plugin.js +20 -4
  152. package/lib/types/Policy.d.ts +25 -0
  153. package/lib/types/{InternalLogger.js → Policy.js} +2 -2
  154. package/lib/types/PolicyRestrictions.d.ts +21 -0
  155. package/lib/types/PolicyRestrictions.js +23 -0
  156. package/lib/types/Target.d.ts +15 -0
  157. package/lib/types/Target.js +23 -0
  158. package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
  159. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  160. package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
  161. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
  162. package/lib/types/errors/ErrorDefinition.d.ts +27 -0
  163. package/lib/types/errors/ErrorDefinition.js +3 -0
  164. package/lib/types/errors/ErrorDomains.d.ts +17 -0
  165. package/lib/types/errors/ErrorDomains.js +3 -0
  166. package/lib/types/index.d.ts +9 -1
  167. package/lib/types/index.js +9 -1
  168. package/lib/util/array.d.ts +11 -0
  169. package/lib/util/array.js +57 -0
  170. package/lib/util/assertType.js +6 -6
  171. package/lib/util/bufferedPassThrough.d.ts +76 -0
  172. package/lib/util/bufferedPassThrough.js +161 -0
  173. package/lib/util/deprecate.js +7 -5
  174. package/lib/util/didYouMean.js +1 -1
  175. package/lib/util/dump-collection.d.ts +3 -0
  176. package/lib/util/dump-collection.js +284 -0
  177. package/lib/util/extractFields.js +2 -2
  178. package/lib/util/inflector.d.ts +8 -0
  179. package/lib/util/inflector.js +16 -0
  180. package/lib/util/mutex.js +21 -2
  181. package/lib/util/requestAssertions.js +7 -7
  182. package/lib/util/wildcard.js +55 -0
  183. package/package-lock.json +535 -75
  184. package/package.json +5 -3
  185. package/lib/api/openApiGenerator.d.ts +0 -7
  186. package/lib/api/openApiGenerator.js +0 -197
  187. package/lib/types/InternalLogger.d.ts +0 -25
@@ -93,6 +93,12 @@
93
93
  "code": 15,
94
94
  "message": "Plugin \"%s\" not found.%s",
95
95
  "class": "NotFoundError"
96
+ },
97
+ "invalid_openapi_schema": {
98
+ "description": "OpenAPI specification is invalid",
99
+ "code": 16,
100
+ "message": "Invalid OpenAPI specification: \"%s\"",
101
+ "class": "PluginImplementationError"
96
102
  }
97
103
  }
98
104
  },
@@ -43,7 +43,7 @@ const domains = {
43
43
  * @param {object} - error config file domain
44
44
  */
45
45
 
46
- function checkErrors(subdomain, domain, options) {
46
+ function checkErrors (subdomain, domain, options) {
47
47
  const codes = new Set();
48
48
 
49
49
  for (const [name, error] of Object.entries(subdomain.errors)) {
@@ -57,7 +57,7 @@ function checkErrors(subdomain, domain, options) {
57
57
  error.code > 0x0000 && error.code <= 0xFFFF,
58
58
  `Error configuration file : Field 'code' must be between 1 and 65535 (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}).`);
59
59
  assert(
60
- !codes.has(error.code),
60
+ ! codes.has(error.code),
61
61
  `Error configuration file : code ${error.code} for error '${name}' is not unique (domain: ${domain.code}, subdomain: ${subdomain.code}).`);
62
62
 
63
63
  codes.add(error.code);
@@ -80,7 +80,7 @@ function checkErrors(subdomain, domain, options) {
80
80
  `Error configuration file : Field 'class' must target a known KuzzleError object (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}), '${name.class}' does not exist.`);
81
81
 
82
82
  // plugin errors aren't required to have descriptions
83
- if (!options.plugin) {
83
+ if (! options.plugin) {
84
84
  assert(
85
85
  typeof error.description === 'string' && error.description.length > 0,
86
86
  `Error configuration file : Field 'description' must be a non-empty string (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}).`);
@@ -94,19 +94,19 @@ function checkErrors(subdomain, domain, options) {
94
94
  }
95
95
  }
96
96
 
97
- function checkSubdomains(domain, options) {
97
+ function checkSubdomains (domain, options) {
98
98
  const subdomainCodes = new Set();
99
99
 
100
100
  for (const subdomainName of Object.keys(domain.subdomains)) {
101
101
  const subdomain = domain.subdomains[subdomainName];
102
102
 
103
103
  // Subdomain code for plugins is not required and is automatically set to 0
104
- if (!options.plugin) {
104
+ if (! options.plugin) {
105
105
  assert(
106
106
  has(subdomain, 'code'),
107
107
  `Error configuration file : Missing required 'code' field (domain: ${domain.code}, subdomain: ${subdomainName}).`);
108
108
  }
109
- else if (!has(subdomain, 'code')) {
109
+ else if (! has(subdomain, 'code')) {
110
110
  subdomain.code = 0;
111
111
  }
112
112
 
@@ -117,11 +117,11 @@ function checkSubdomains(domain, options) {
117
117
  subdomain.code >= 0x00 && subdomain.code <= 0xFF,
118
118
  `Error configuration file : Field 'code' must be between 0 and 255 (domain: ${domain.code}, subdomain: ${subdomainName}).`);
119
119
  assert(
120
- !subdomainCodes.has(subdomain.code),
120
+ ! subdomainCodes.has(subdomain.code),
121
121
  `Error configuration file : code ${subdomain.code} for subdomain '${subdomainName}' is not unique (domain: ${domain.code}).`);
122
122
 
123
123
  // We don't allow duplicates, except for defaulted plugin subdomain codes
124
- if (!options.plugin || subdomain.code > 0) {
124
+ if (! options.plugin || subdomain.code > 0) {
125
125
  subdomainCodes.add(subdomain.code);
126
126
  }
127
127
 
@@ -136,7 +136,7 @@ function checkSubdomains(domain, options) {
136
136
  }
137
137
  }
138
138
 
139
- function checkDomains(errorCodesFiles, options = {plugin: false}) {
139
+ function checkDomains (errorCodesFiles, options = { plugin: false }) {
140
140
  const domainCodes = new Set();
141
141
 
142
142
  for (const domainName of Object.keys(errorCodesFiles)) {
@@ -152,7 +152,7 @@ function checkDomains(errorCodesFiles, options = {plugin: false}) {
152
152
  domain.code >= 0x00 && domain.code <= 0xFF,
153
153
  `Error configuration file : Field 'code' must be between 0 and 255. (domain: '${domainName}').`);
154
154
  assert(
155
- !domainCodes.has(domain.code),
155
+ ! domainCodes.has(domain.code),
156
156
  `Error configuration file : code ${domain.code} for domain ${domainName} is not unique.`);
157
157
 
158
158
  domainCodes.add(domain.code);
@@ -168,7 +168,7 @@ function checkDomains(errorCodesFiles, options = {plugin: false}) {
168
168
  }
169
169
  }
170
170
 
171
- function loadPluginsErrors(pluginManifest, pluginCode) {
171
+ function loadPluginsErrors (pluginManifest, pluginCode) {
172
172
  // @todo this should be in its own, independant domain
173
173
  domains.plugin.subdomains[pluginManifest.name] = {
174
174
  code: pluginCode,
@@ -2,6 +2,6 @@ import { KuzzleError } from './kuzzleError';
2
2
  export declare class MultipleErrorsError extends KuzzleError {
3
3
  errors: Array<KuzzleError>;
4
4
  count: number;
5
- constructor(message: string, body?: Array<KuzzleError>, id?: string, code?: number);
5
+ constructor(message: string, errors?: KuzzleError[], id?: string, code?: number);
6
6
  toJSON(): import("kuzzle-sdk").JSONObject;
7
7
  }
@@ -23,10 +23,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MultipleErrorsError = void 0;
24
24
  const kuzzleError_1 = require("./kuzzleError");
25
25
  class MultipleErrorsError extends kuzzleError_1.KuzzleError {
26
- constructor(message, body = [], id, code) {
26
+ constructor(message, errors = [], id, code) {
27
27
  super(message, 400, id, code);
28
- this.errors = body;
29
- this.count = body.length;
28
+ this.errors = errors;
29
+ this.count = errors.length;
30
30
  }
31
31
  toJSON() {
32
32
  const serialized = super.toJSON();
@@ -0,0 +1,82 @@
1
+ import * as errors from './errors';
2
+ import { KuzzleError } from './errors';
3
+ import { ErrorDomains } from '../types';
4
+ /**
5
+ * Construct and return the corresponding error
6
+ *
7
+ * @param domains - Domains object with subdomains and error names
8
+ * @param domain - Domain (eg: 'external')
9
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
10
+ * @param error - Error name: (eg: 'index_not_found')
11
+ * @param placeholders - Placeholders value to inject in error message
12
+ * @param options - Last param can be additional options { message }
13
+ */
14
+ export declare function rawGet(domains: ErrorDomains, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
15
+ /**
16
+ * Returns a promise rejected with the corresponding error
17
+ *
18
+ * @param domains - Domains object with subdomains and error names
19
+ * @param domain - Domain (eg: 'external')
20
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
21
+ * @param error - Error name: (eg: 'index_not_found')
22
+ * @param placeholders - Placeholders value to inject in error message
23
+ */
24
+ export declare function rawReject(domains: ErrorDomains, domain: string, subdomain: string, error: string, ...placeholders: any[]): Promise<any>;
25
+ /**
26
+ * Construct and return the corresponding error, with its stack
27
+ * trace derivated from a provided source error
28
+ *
29
+ * @param domains - Domains object with subdomains and error names
30
+ * @param source - Original error
31
+ * @param domain - Domain (eg: 'external')
32
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
33
+ * @param error - Error name: (eg: 'index_not_found')
34
+ * @param placeholders - Placeholders value to inject in error message
35
+ */
36
+ export declare function rawGetFrom(domains: ErrorDomains, source: Error, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
37
+ /**
38
+ * Wrap error functions with the provided domain and subdomain.
39
+ */
40
+ export declare function rawWrap(domains: ErrorDomains, domain: string, subdomain: string): {
41
+ get: (error: any, ...placeholders: any[]) => errors.KuzzleError;
42
+ getFrom: (source: any, error: any, ...placeholders: any[]) => errors.KuzzleError;
43
+ reject: (error: any, ...placeholders: any[]) => Promise<any>;
44
+ };
45
+ /**
46
+ * Construct and return the corresponding error
47
+ *
48
+ * @param domain - Domain (eg: 'external')
49
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
50
+ * @param error - Error name: (eg: 'index_not_found')
51
+ * @param placeholders - Placeholders value to inject in error message
52
+ * @param options - Last param can be additional options { message }
53
+ */
54
+ export declare function get(domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
55
+ /**
56
+ * Returns a promise rejected with the corresponding error
57
+ *
58
+ * @param domain - Domain (eg: 'external')
59
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
60
+ * @param error - Error name: (eg: 'index_not_found')
61
+ * @param placeholders - Placeholders value to inject in error message
62
+ */
63
+ export declare function reject(domain: string, subdomain: string, error: string, ...placeholders: any[]): Promise<any>;
64
+ /**
65
+ * Construct and return the corresponding error, with its stack
66
+ * trace derivated from a provided source error
67
+ *
68
+ * @param source - Original error
69
+ * @param domain - Domain (eg: 'external')
70
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
71
+ * @param error - Error name: (eg: 'index_not_found')
72
+ * @param placeholders - Placeholders value to inject in error message
73
+ */
74
+ export declare function getFrom(source: Error, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
75
+ /**
76
+ * Wrap error functions with the provided domain and subdomain.
77
+ */
78
+ export declare function wrap(domain: string, subdomain: string): {
79
+ get: (error: any, ...placeholders: any[]) => errors.KuzzleError;
80
+ getFrom: (source: any, error: any, ...placeholders: any[]) => errors.KuzzleError;
81
+ reject: (error: any, ...placeholders: any[]) => Promise<any>;
82
+ };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /*
2
3
  * Kuzzle, a backend software, self-hostable and ready to use
3
4
  * to power modern apps
@@ -18,83 +19,89 @@
18
19
  * See the License for the specific language governing permissions and
19
20
  * limitations under the License.
20
21
  */
21
-
22
- 'use strict';
23
-
24
- const { format } = require('util');
25
-
26
- const Bluebird = require('bluebird');
27
- const _ = require('lodash');
28
-
29
- const { domains } = require('./codes');
30
- const errors = require('./errors');
31
- const { hilightUserCode } = require('../util/stackTrace');
32
-
22
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
31
+ }) : function(o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar = (this && this.__importStar) || function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.wrap = exports.getFrom = exports.reject = exports.get = exports.rawWrap = exports.rawGetFrom = exports.rawReject = exports.rawGet = void 0;
46
+ const util_1 = require("util");
47
+ const lodash_1 = __importDefault(require("lodash"));
48
+ const codes_1 = require("./codes");
49
+ const errors = __importStar(require("./errors"));
50
+ const stackTrace_1 = require("../util/stackTrace");
33
51
  /**
34
52
  * Gets this file name in the exact same format than the one printed in the
35
53
  * stacktraces (used to clean kerror lines from stacktraces)
36
54
  */
37
55
  let _currentFileName = null;
38
- function _getCurrentFileName () {
39
- if (_currentFileName !== null) {
56
+ function _getCurrentFileName() {
57
+ if (_currentFileName !== null) {
58
+ return _currentFileName;
59
+ }
60
+ _currentFileName = module.filename.substr(process.cwd().length + 1);
40
61
  return _currentFileName;
41
- }
42
-
43
- _currentFileName = module.filename.substr(process.cwd().length + 1);
44
-
45
- return _currentFileName;
46
62
  }
47
-
48
63
  /**
49
64
  * Construct and return the corresponding error
50
65
  *
51
- * @param {string} domain - Domain (eg: 'external')
52
- * @param {string} subdomain - Subdomain (eg: 'elasticsearch')
53
- * @param {string} error - Error name: (eg: 'index_not_found')
54
- * @param {...any} placeholders - Placeholders value to inject in error message
55
- * @param {object} options - Last param can be additional options { message }
66
+ * @param domains - Domains object with subdomains and error names
67
+ * @param domain - Domain (eg: 'external')
68
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
69
+ * @param error - Error name: (eg: 'index_not_found')
70
+ * @param placeholders - Placeholders value to inject in error message
71
+ * @param options - Last param can be additional options { message }
56
72
  */
57
- function get (domain, subdomain, error, ...placeholders) {
58
- let options = {};
59
-
60
- // extract options object from the placeholders
61
- if (_.isPlainObject(placeholders[placeholders.length - 1])) {
62
- options = placeholders.pop();
63
- }
64
-
65
- const kuzzleError = _.get(domains, `${domain}.subdomains.${subdomain}.errors.${error}`);
66
-
67
- if (! kuzzleError) {
68
- return get('core', 'fatal', 'unexpected_error', `${domain}.${subdomain}.${error}`);
69
- }
70
-
71
- let body = null;
72
-
73
- if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
74
- body = placeholders.splice(-1)[0];
75
- }
76
-
77
- const message = options.message || format(kuzzleError.message, ...placeholders);
78
- const id = `${domain}.${subdomain}.${error}`;
79
- const code = domains[domain].code << 24
80
- | domains[domain].subdomains[subdomain].code << 16
81
- | domains[domain].subdomains[subdomain].errors[error].code;
82
-
83
- let kerror;
84
- if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
85
- kerror = new errors[kuzzleError.class](message, body, id, code);
86
- }
87
- else {
88
- kerror = new errors[kuzzleError.class](message, id, code);
89
- }
90
-
91
- if (error.name !== 'InternalError') {
92
- cleanStackTrace(kerror);
93
- }
94
-
95
- return kerror;
73
+ function rawGet(domains, domain, subdomain, error, ...placeholders) {
74
+ let options = {};
75
+ // extract options object from the placeholders
76
+ if (lodash_1.default.isPlainObject(placeholders[placeholders.length - 1])) {
77
+ options = placeholders.pop();
78
+ }
79
+ const kuzzleError = lodash_1.default.get(domains, `${domain}.subdomains.${subdomain}.errors.${error}`);
80
+ if (!kuzzleError) {
81
+ return get('core', 'fatal', 'unexpected_error', `${domain}.${subdomain}.${error}`);
82
+ }
83
+ let body = null;
84
+ if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
85
+ body = placeholders.splice(-1)[0];
86
+ }
87
+ const message = options.message || (0, util_1.format)(kuzzleError.message, ...placeholders);
88
+ const id = `${domain}.${subdomain}.${error}`;
89
+ const code = domains[domain].code << 24
90
+ | domains[domain].subdomains[subdomain].code << 16
91
+ | domains[domain].subdomains[subdomain].errors[error].code;
92
+ let kerror;
93
+ if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
94
+ kerror = new errors[kuzzleError.class](message, body, id, code);
95
+ }
96
+ else {
97
+ kerror = new errors[kuzzleError.class](message, id, code);
98
+ }
99
+ if (kuzzleError.class !== 'InternalError') {
100
+ cleanStackTrace(kerror);
101
+ }
102
+ return kerror;
96
103
  }
97
-
104
+ exports.rawGet = rawGet;
98
105
  /**
99
106
  * Removes the first lines of the stacktrace because they are related
100
107
  * to internal mechanisms.
@@ -106,98 +113,124 @@ function get (domain, subdomain, error, ...placeholders) {
106
113
  * // Line that triggered the error =>
107
114
  * at ControllerManager.add (kuzzle/lib/core/backend/backend.ts:226:34)
108
115
  */
109
-
110
- function cleanStackTrace (error) {
111
- // Keep the original error message
112
- const messageLength = error.message.split('\n').length;
113
- const currentFileName = _getCurrentFileName();
114
-
115
- // we keep the new error instantiation line ("new ...Error (") on purpose:
116
- // this will allow us to replace it without inserting a new line in the array,
117
- // saving us from building a new array
118
- const newStack = error.stack.split('\n')
119
- .filter((line, index) => {
120
- if (index < messageLength) {
121
- return true;
122
- }
123
-
124
- // filter all lines related to the kerror object
125
- return !line.includes(currentFileName);
116
+ function cleanStackTrace(error) {
117
+ // Keep the original error message
118
+ const messageLength = error.message.split('\n').length;
119
+ const currentFileName = _getCurrentFileName();
120
+ // we keep the new error instantiation line ("new ...Error (") on purpose:
121
+ // this will allow us to replace it without inserting a new line in the array,
122
+ // saving us from building a new array
123
+ const newStack = error.stack.split('\n')
124
+ .filter((line, index) => {
125
+ if (index < messageLength) {
126
+ return true;
127
+ }
128
+ // filter all lines related to the kerror object
129
+ return !line.includes(currentFileName);
126
130
  })
127
- .map(hilightUserCode);
128
-
129
- // insert a deletion message in place of the new error instantiation line
130
- newStack[messageLength] = ' [...Kuzzle internal calls deleted...]';
131
-
132
- error.stack = newStack.join('\n');
131
+ .map(stackTrace_1.hilightUserCode);
132
+ // insert a deletion message in place of the new error instantiation line
133
+ newStack[messageLength] = ' [...Kuzzle internal calls deleted...]';
134
+ error.stack = newStack.join('\n');
133
135
  }
134
-
135
136
  /**
136
137
  * Returns a promise rejected with the corresponding error
137
138
  *
138
- * @param {string} domain - Domain (eg: 'external')
139
- * @param {string} subdomain - Subdomain (eg: 'elasticsearch')
140
- * @param {string} error - Error name: (eg: 'index_not_found')
141
- * @param {...any} placeholders - Placeholders value to inject in error message
139
+ * @param domains - Domains object with subdomains and error names
140
+ * @param domain - Domain (eg: 'external')
141
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
142
+ * @param error - Error name: (eg: 'index_not_found')
143
+ * @param placeholders - Placeholders value to inject in error message
142
144
  */
143
- function reject (domain, subdomain, error, ...placeholders) {
144
- return Bluebird.reject(get(domain, subdomain, error, ...placeholders));
145
+ function rawReject(domains, domain, subdomain, error, ...placeholders) {
146
+ return Promise.reject(rawGet(domains, domain, subdomain, error, ...placeholders));
145
147
  }
146
-
148
+ exports.rawReject = rawReject;
147
149
  /**
148
150
  * Construct and return the corresponding error, with its stack
149
151
  * trace derivated from a provided source error
150
152
  *
151
- * @param {Error} source
152
- * @param {string} domain - Domain (eg: 'external')
153
- * @param {string} subdomain - Subdomain (eg: 'elasticsearch')
154
- * @param {string} error - Error name: (eg: 'index_not_found')
155
- * @param {...any} placeholders - Placeholders value to inject in error message
153
+ * @param domains - Domains object with subdomains and error names
154
+ * @param source - Original error
155
+ * @param domain - Domain (eg: 'external')
156
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
157
+ * @param error - Error name: (eg: 'index_not_found')
158
+ * @param placeholders - Placeholders value to inject in error message
156
159
  */
157
- function getFrom (source, domain, subdomain, error, ...placeholders) {
158
- const derivedError = get(domain, subdomain, error, ...placeholders);
159
-
160
- // If a stacktrace is present, we need to modify the first line because it
161
- // still contains the original error message
162
- if (derivedError.stack && derivedError.stack.length) {
163
- const stackArray = source.stack.split('\n');
164
- stackArray.shift();
165
- derivedError.stack = [
166
- `${derivedError.constructor.name}: ${derivedError.message}`,
167
- ...stackArray
168
- ].join('\n');
169
- }
170
-
171
- return derivedError;
160
+ function rawGetFrom(domains, source, domain, subdomain, error, ...placeholders) {
161
+ const derivedError = rawGet(domains, domain, subdomain, error, ...placeholders);
162
+ // If a stacktrace is present, we need to modify the first line because it
163
+ // still contains the original error message
164
+ if (derivedError.stack && derivedError.stack.length) {
165
+ const stackArray = source.stack.split('\n');
166
+ stackArray.shift();
167
+ derivedError.stack = [
168
+ `${derivedError.constructor.name}: ${derivedError.message}`,
169
+ ...stackArray
170
+ ].join('\n');
171
+ }
172
+ return derivedError;
172
173
  }
173
-
174
+ exports.rawGetFrom = rawGetFrom;
174
175
  /**
175
176
  * Wrap error functions with the provided domain and subdomain.
176
177
  */
177
- function wrap (domain, subdomain) {
178
- return {
179
- get: (error, ...placeholders) => get(
180
- domain,
181
- subdomain,
182
- error,
183
- ...placeholders),
184
- getFrom: (source, error, ...placeholders) => getFrom(
185
- source,
186
- domain,
187
- subdomain,
188
- error,
189
- ...placeholders),
190
- reject: (error, ...placeholders) => reject(
191
- domain,
192
- subdomain,
193
- error,
194
- ...placeholders),
195
- };
178
+ function rawWrap(domains, domain, subdomain) {
179
+ return {
180
+ get: (error, ...placeholders) => rawGet(domains, domain, subdomain, error, ...placeholders),
181
+ getFrom: (source, error, ...placeholders) => rawGetFrom(domains, source, domain, subdomain, error, ...placeholders),
182
+ reject: (error, ...placeholders) => rawReject(domains, domain, subdomain, error, ...placeholders),
183
+ };
196
184
  }
197
-
198
- module.exports = {
199
- get,
200
- getFrom,
201
- reject,
202
- wrap,
203
- };
185
+ exports.rawWrap = rawWrap;
186
+ /**
187
+ * Construct and return the corresponding error
188
+ *
189
+ * @param domain - Domain (eg: 'external')
190
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
191
+ * @param error - Error name: (eg: 'index_not_found')
192
+ * @param placeholders - Placeholders value to inject in error message
193
+ * @param options - Last param can be additional options { message }
194
+ */
195
+ function get(domain, subdomain, error, ...placeholders) {
196
+ return rawGet(codes_1.domains, domain, subdomain, error, ...placeholders);
197
+ }
198
+ exports.get = get;
199
+ /**
200
+ * Returns a promise rejected with the corresponding error
201
+ *
202
+ * @param domain - Domain (eg: 'external')
203
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
204
+ * @param error - Error name: (eg: 'index_not_found')
205
+ * @param placeholders - Placeholders value to inject in error message
206
+ */
207
+ function reject(domain, subdomain, error, ...placeholders) {
208
+ return rawReject(codes_1.domains, domain, subdomain, error, ...placeholders);
209
+ }
210
+ exports.reject = reject;
211
+ /**
212
+ * Construct and return the corresponding error, with its stack
213
+ * trace derivated from a provided source error
214
+ *
215
+ * @param source - Original error
216
+ * @param domain - Domain (eg: 'external')
217
+ * @param subdomain - Subdomain (eg: 'elasticsearch')
218
+ * @param error - Error name: (eg: 'index_not_found')
219
+ * @param placeholders - Placeholders value to inject in error message
220
+ */
221
+ function getFrom(source, domain, subdomain, error, ...placeholders) {
222
+ return rawGetFrom(codes_1.domains, source, domain, subdomain, error, ...placeholders);
223
+ }
224
+ exports.getFrom = getFrom;
225
+ /**
226
+ * Wrap error functions with the provided domain and subdomain.
227
+ */
228
+ function wrap(domain, subdomain) {
229
+ return {
230
+ get: (error, ...placeholders) => get(domain, subdomain, error, ...placeholders),
231
+ getFrom: (source, error, ...placeholders) => getFrom(source, domain, subdomain, error, ...placeholders),
232
+ reject: (error, ...placeholders) => reject(domain, subdomain, error, ...placeholders),
233
+ };
234
+ }
235
+ exports.wrap = wrap;
236
+ //# sourceMappingURL=index.js.map
@@ -175,7 +175,7 @@ class DumpGenerator {
175
175
  // dumping Kuzzle's stats
176
176
  global.kuzzle.log.info('> dumping kuzzle\'s stats');
177
177
  const statistics = await global.kuzzle.statistics.getAllStats(
178
- new Request({action: 'getAllStats', controller: 'statistics'}));
178
+ new Request({ action: 'getAllStats', controller: 'statistics' }));
179
179
 
180
180
  fs.writeFileSync(
181
181
  path.join(dumpPath, 'statistics.json'),
@@ -197,14 +197,14 @@ class DumpGenerator {
197
197
  try {
198
198
  fs.accessSync(dumpPath, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK);
199
199
  }
200
- catch(e) {
200
+ catch (e) {
201
201
  return;
202
202
  }
203
203
 
204
204
  const dumps = fs.readdirSync(dumpPath)
205
205
  .map(file => {
206
206
  const filepath = `${dumpPath}/${file}`;
207
- return {path: filepath, stat: fs.statSync(filepath)};
207
+ return { path: filepath, stat: fs.statSync(filepath) };
208
208
  })
209
209
  .filter(prop => prop.stat.isDirectory())
210
210
  .sort((a, b) => {
@@ -80,7 +80,7 @@ class KuzzleEventEmitter extends EventEmitter {
80
80
  onPipe (event, fn) {
81
81
  assert(typeof fn === 'function', `Cannot listen to pipe event ${event}: "${fn}" is not a function`);
82
82
 
83
- if (!this.corePipes.has(event)) {
83
+ if (! this.corePipes.has(event)) {
84
84
  this.corePipes.set(event, []);
85
85
  }
86
86
 
@@ -96,7 +96,7 @@ class KuzzleEventEmitter extends EventEmitter {
96
96
  */
97
97
  onAsk (event, fn) {
98
98
  assert(typeof fn === 'function', `Cannot listen to ask event "${event}": "${fn}" is not a function`);
99
- assert(!this.coreAnswerers.has(event), `Cannot add a listener to the ask event "${event}": event has already an answerer`);
99
+ assert(! this.coreAnswerers.has(event), `Cannot add a listener to the ask event "${event}": event has already an answerer`);
100
100
 
101
101
  this.coreAnswerers.set(event, fn);
102
102
  }
@@ -143,7 +143,7 @@ class KuzzleEventEmitter extends EventEmitter {
143
143
  let callback = null;
144
144
 
145
145
  // safe: a pipe's payload can never contain functions
146
- if (payload.length > 0 && typeof payload[payload.length-1] === 'function') {
146
+ if (payload.length > 0 && typeof payload[payload.length - 1] === 'function') {
147
147
  callback = payload.pop();
148
148
  }
149
149
 
@@ -185,7 +185,7 @@ class KuzzleEventEmitter extends EventEmitter {
185
185
 
186
186
  const fn = this.coreAnswerers.get(event);
187
187
 
188
- if (!fn) {
188
+ if (! fn) {
189
189
  throw kerror.get('core', 'fatal', 'assertion_failed', `the requested ask event '${event}' doesn't have an answerer`);
190
190
  }
191
191
 
@@ -40,7 +40,7 @@ const kerror = require('../../kerror').wrap('plugin', 'runtime');
40
40
  function waterfallCallback (error, result) {
41
41
  this.instance.running--;
42
42
 
43
- if (!this.instance.buffer.isEmpty()) {
43
+ if (! this.instance.buffer.isEmpty()) {
44
44
  setImmediate(this.instance._boundRunNext);
45
45
  }
46
46