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
@@ -83,7 +83,7 @@ class ClientAdapter {
83
83
  ));
84
84
  }
85
85
 
86
- async createIndex (index, { indexCacheOnly=false, propagate=true } = {}) {
86
+ async createIndex (index, { indexCacheOnly = false, propagate = true } = {}) {
87
87
  if (this.cache.hasIndex(index)) {
88
88
  throw servicesError.get('index_already_exists', this.scope, index);
89
89
  }
@@ -106,7 +106,7 @@ class ClientAdapter {
106
106
  index,
107
107
  collection,
108
108
  opts,
109
- { indexCacheOnly=false, propagate=true } = {},
109
+ { indexCacheOnly = false, propagate = true } = {},
110
110
  ) {
111
111
 
112
112
  if (! indexCacheOnly) {
@@ -462,6 +462,21 @@ class ClientAdapter {
462
462
  return this.client.exists(index, collection, id);
463
463
  });
464
464
 
465
+ /**
466
+ * Check if a document multiple document Exists
467
+ *
468
+ * @param {string} index
469
+ * @param {string} collection
470
+ * @param {string} id -- document unique identifier
471
+ * @returns {Promise.<boolean>}
472
+ */
473
+ global.kuzzle.onAsk(
474
+ `core:storage:${this.scope}:document:mExists`,
475
+ (index, collection, ids) => {
476
+ this.cache.assertCollectionExists(index, collection);
477
+ return this.client.mExists(index, collection, ids);
478
+ });
479
+
465
480
  /**
466
481
  * Get a document using its unique id
467
482
  *
@@ -648,15 +663,35 @@ class ClientAdapter {
648
663
  *
649
664
  * @param {string} index
650
665
  * @param {string} collection
651
- * @param {Object} query -- search query, in ES format
666
+ * @param {Object} searchBody -- search query, in ES format
652
667
  * @param {Object} [opts] -- see Elasticsearch "search" options
653
668
  * @returns {Promise.<{ scrollId, hits, aggregations, total }>}
654
669
  */
655
670
  global.kuzzle.onAsk(
656
671
  `core:storage:${this.scope}:document:search`,
657
- (index, collection, query, opts) => {
672
+ (index, collection, searchBody, opts) => {
658
673
  this.cache.assertCollectionExists(index, collection);
659
- return this.client.search(index, collection, query, opts);
674
+ return this.client.search({ collection, index, searchBody }, opts);
675
+ });
676
+
677
+ /**
678
+ * Search for multiples documents
679
+ *
680
+ * @param {Object[]} targets
681
+ * @param {Object} searchBody -- search query, in ES format
682
+ * @param {Object} [opts] -- see Elasticsearch "search" options
683
+ * @returns {Promise.<{ scrollId, hits, aggregations, total }>}
684
+ */
685
+ global.kuzzle.onAsk(
686
+ `core:storage:${this.scope}:document:multiSearch`,
687
+ (targets, searchBody, opts) => {
688
+ for (const target of targets) {
689
+ for (const collection of target.collections) {
690
+ this.cache.assertCollectionExists(target.index, collection);
691
+ }
692
+ }
693
+
694
+ return this.client.search({ searchBody, targets }, opts);
660
695
  });
661
696
 
662
697
  /**
@@ -827,12 +862,12 @@ class ClientAdapter {
827
862
  * @returns {Promise}
828
863
  */
829
864
  async loadFixtures (fixtures = {}) {
830
- if (!isPlainObject(fixtures)) {
865
+ if (! isPlainObject(fixtures)) {
831
866
  throw kerror.get('api', 'assert', 'invalid_argument', fixtures, 'object');
832
867
  }
833
868
 
834
869
  for (const index of Object.keys(fixtures)) {
835
- if (!isPlainObject(fixtures[index])) {
870
+ if (! isPlainObject(fixtures[index])) {
836
871
  throw kerror.get('api', 'assert', 'invalid_argument', fixtures[index], 'object');
837
872
  }
838
873
 
@@ -870,7 +905,7 @@ class ClientAdapter {
870
905
  refresh: false,
871
906
  }
872
907
  ) {
873
- if (!isPlainObject(fixtures)) {
908
+ if (! isPlainObject(fixtures)) {
874
909
  throw kerror.get('api', 'assert', 'invalid_argument', fixtures, 'object');
875
910
  }
876
911
 
@@ -880,7 +915,7 @@ class ClientAdapter {
880
915
 
881
916
  try {
882
917
  for (const index of Object.keys(fixtures)) {
883
- if (!isPlainObject(fixtures[index])) {
918
+ if (! isPlainObject(fixtures[index])) {
884
919
  throw kerror.get('api', 'assert', 'invalid_argument', fixtures[index], 'object');
885
920
  }
886
921
 
@@ -908,7 +943,7 @@ class ClientAdapter {
908
943
  propagate: options.propagate,
909
944
  });
910
945
 
911
- if (options.refresh && !options.indexCacheOnly) {
946
+ if (options.refresh && ! options.indexCacheOnly) {
912
947
  await this.client.refreshCollection(index, collection);
913
948
  }
914
949
  }
@@ -19,13 +19,29 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
24
40
  };
25
41
  Object.defineProperty(exports, "__esModule", { value: true });
26
42
  exports.IndexCache = void 0;
27
- const kerror_1 = __importDefault(require("../../kerror"));
28
- const storageError = kerror_1.default.wrap('services', 'storage');
43
+ const kerror = __importStar(require("../../kerror"));
44
+ const storageError = kerror.wrap('services', 'storage');
29
45
  class IndexCache {
30
46
  constructor() {
31
47
  /**
@@ -33,7 +33,7 @@ class BaseType {
33
33
  * @param {string[]} errorMessages
34
34
  * @returns {boolean}
35
35
  */
36
- validate() {
36
+ validate () {
37
37
  return true;
38
38
  }
39
39
 
@@ -44,7 +44,7 @@ class BaseType {
44
44
  * @returns {TypeOptions}
45
45
  * @throws {KuzzleError}
46
46
  */
47
- validateFieldSpecification(opts) {
47
+ validateFieldSpecification (opts) {
48
48
  return opts;
49
49
  }
50
50
 
@@ -53,7 +53,7 @@ class BaseType {
53
53
  * @param {string[]} allowedProperties
54
54
  * @returns {boolean}
55
55
  */
56
- checkAllowedProperties(object, allowedProperties) {
56
+ checkAllowedProperties (object, allowedProperties) {
57
57
  if (typeof object !== 'object'
58
58
  || Array.isArray(object)
59
59
  || object === null
@@ -61,7 +61,7 @@ class BaseType {
61
61
  return false;
62
62
  }
63
63
 
64
- return !Object.keys(object).some(
64
+ return ! Object.keys(object).some(
65
65
  propertyName => allowedProperties.indexOf(propertyName) === -1);
66
66
  }
67
67
 
@@ -70,7 +70,7 @@ class BaseType {
70
70
  * @param {boolean} parentStrictness
71
71
  * @returns {boolean}
72
72
  */
73
- getStrictness(fieldSpec, parentStrictness) {
73
+ getStrictness (fieldSpec, parentStrictness) {
74
74
  return parentStrictness;
75
75
  }
76
76
  }
@@ -27,7 +27,7 @@ const BaseType = require('../baseType');
27
27
  * @class AnythingType
28
28
  */
29
29
  class AnythingType extends BaseType {
30
- constructor() {
30
+ constructor () {
31
31
  super();
32
32
  this.typeName = 'anything';
33
33
  this.allowChildren = false;
@@ -27,7 +27,7 @@ const BaseType = require('../baseType');
27
27
  * @class BooleanType
28
28
  */
29
29
  class BooleanType extends BaseType {
30
- constructor() {
30
+ constructor () {
31
31
  super();
32
32
  this.typeName = 'boolean';
33
33
  this.allowChildren = false;
@@ -39,7 +39,7 @@ class BooleanType extends BaseType {
39
39
  * @param {*} fieldValue
40
40
  * @param {string[]} errorMessages
41
41
  */
42
- validate(typeOptions, fieldValue, errorMessages) {
42
+ validate (typeOptions, fieldValue, errorMessages) {
43
43
  if (typeof fieldValue !== 'boolean') {
44
44
  errorMessages.push('The field must be of type boolean.');
45
45
  return false;
@@ -114,7 +114,7 @@ const
114
114
  * @class DateType
115
115
  */
116
116
  class DateType extends BaseType {
117
- constructor() {
117
+ constructor () {
118
118
  super();
119
119
  this.typeName = 'date';
120
120
  this.allowChildren = false;
@@ -127,7 +127,7 @@ class DateType extends BaseType {
127
127
  * @param {string[]} errorMessages
128
128
  * @returns {boolean}
129
129
  */
130
- validate(typeOptions, fieldValue, errorMessages) {
130
+ validate (typeOptions, fieldValue, errorMessages) {
131
131
  let momentDate = null;
132
132
 
133
133
  for (const formatOpt of typeOptions.formats) {
@@ -138,7 +138,7 @@ class DateType extends BaseType {
138
138
  }
139
139
  }
140
140
 
141
- if (momentDate === null || !momentDate.isValid()) {
141
+ if (momentDate === null || ! momentDate.isValid()) {
142
142
  errorMessages.push('The date format is invalid.');
143
143
  return false;
144
144
  }
@@ -175,15 +175,15 @@ class DateType extends BaseType {
175
175
  * @returns {TypeOptions}
176
176
  * @throws {PreconditionError}
177
177
  */
178
- validateFieldSpecification(typeOptions) {
178
+ validateFieldSpecification (typeOptions) {
179
179
  if (has(typeOptions, 'formats')) {
180
- if ( !Array.isArray(typeOptions.formats)
180
+ if ( ! Array.isArray(typeOptions.formats)
181
181
  || typeOptions.formats.length === 0
182
182
  ) {
183
183
  throw assertionError.get('invalid_type', 'formats', 'non-empty array');
184
184
  }
185
185
 
186
- const unrecognized = typeOptions.formats.filter(f => !formatMap[f]);
186
+ const unrecognized = typeOptions.formats.filter(f => ! formatMap[f]);
187
187
  if (unrecognized.length > 0) {
188
188
  throw typeError.get('invalid_date_format', unrecognized.join(', '));
189
189
  }
@@ -197,7 +197,7 @@ class DateType extends BaseType {
197
197
  min = null,
198
198
  max = null;
199
199
 
200
- if (!this.checkAllowedProperties(typeOptions.range, ['min', 'max'])) {
200
+ if (! this.checkAllowedProperties(typeOptions.range, ['min', 'max'])) {
201
201
  throw assertionError.get('unexpected_properties', 'range', 'min, max');
202
202
  }
203
203
 
@@ -228,7 +228,7 @@ class DateType extends BaseType {
228
228
  }
229
229
  }
230
230
 
231
- function convertRangeValue(name, value) {
231
+ function convertRangeValue (name, value) {
232
232
  let converted;
233
233
 
234
234
  if (typeof value === 'string') {
@@ -240,7 +240,7 @@ function convertRangeValue(name, value) {
240
240
  converted = moment.utc(value);
241
241
  }
242
242
 
243
- if (!converted || !converted.isValid()) {
243
+ if (! converted || ! converted.isValid()) {
244
244
  throw typeError.get('invalid_date', value);
245
245
  }
246
246
 
@@ -30,7 +30,7 @@ const
30
30
  * @class EmailType
31
31
  */
32
32
  class EmailType extends BaseType {
33
- constructor() {
33
+ constructor () {
34
34
  super();
35
35
  this.typeName = 'email';
36
36
  this.allowChildren = false;
@@ -43,7 +43,7 @@ class EmailType extends BaseType {
43
43
  * @param {string[]} errorMessages
44
44
  * @returns {boolean}
45
45
  */
46
- validate(typeOptions, fieldValue, errorMessages) {
46
+ validate (typeOptions, fieldValue, errorMessages) {
47
47
  if (fieldValue === undefined || fieldValue === null) {
48
48
  if (typeOptions.notEmpty) {
49
49
  errorMessages.push('Field cannot be undefined or null');
@@ -66,7 +66,7 @@ class EmailType extends BaseType {
66
66
  return true;
67
67
  }
68
68
 
69
- if (!validator.isEmail(fieldValue)) {
69
+ if (! validator.isEmail(fieldValue)) {
70
70
  errorMessages.push('The string must be a valid email address.');
71
71
  return false;
72
72
  }
@@ -79,8 +79,8 @@ class EmailType extends BaseType {
79
79
  * @returns {TypeOptions}
80
80
  * @throws {PreconditionError}
81
81
  */
82
- validateFieldSpecification(typeOptions) {
83
- if (!Object.prototype.hasOwnProperty.call(typeOptions, 'notEmpty')) {
82
+ validateFieldSpecification (typeOptions) {
83
+ if (! Object.prototype.hasOwnProperty.call(typeOptions, 'notEmpty')) {
84
84
  typeOptions.notEmpty = false;
85
85
  }
86
86
  else if (typeof typeOptions.notEmpty !== 'boolean') {
@@ -29,7 +29,7 @@ const
29
29
  * @class EnumType
30
30
  */
31
31
  class EnumType extends BaseType {
32
- constructor() {
32
+ constructor () {
33
33
  super();
34
34
  this.typeName = 'enum';
35
35
  this.allowChildren = false;
@@ -42,13 +42,13 @@ class EnumType extends BaseType {
42
42
  * @param {string[]} errorMessages
43
43
  * @returns {boolean}
44
44
  */
45
- validate(typeOptions, fieldValue, errorMessages) {
45
+ validate (typeOptions, fieldValue, errorMessages) {
46
46
  if (typeof fieldValue !== 'string') {
47
47
  errorMessages.push('The field must be a string.');
48
48
  return false;
49
49
  }
50
50
 
51
- if (!typeOptions.values.includes(fieldValue)) {
51
+ if (! typeOptions.values.includes(fieldValue)) {
52
52
  errorMessages.push(
53
53
  `The field only accepts following values: "${typeOptions.values.join(', ')}".`);
54
54
  return false;
@@ -62,12 +62,12 @@ class EnumType extends BaseType {
62
62
  * @returns {TypeOptions}
63
63
  * @throws {PreconditionError}
64
64
  */
65
- validateFieldSpecification(typeOptions) {
66
- if (!Object.prototype.hasOwnProperty.call(typeOptions, 'values')) {
65
+ validateFieldSpecification (typeOptions) {
66
+ if (! Object.prototype.hasOwnProperty.call(typeOptions, 'values')) {
67
67
  throw kerror.get('validation', 'types', 'missing_enum_values');
68
68
  }
69
69
 
70
- if (!Array.isArray(typeOptions.values)
70
+ if (! Array.isArray(typeOptions.values)
71
71
  || typeOptions.values.length === 0
72
72
  ) {
73
73
  throw kerror.get('validation', 'assert', 'invalid_type', 'values', 'string[]');
@@ -28,7 +28,7 @@ const { Koncorde } = require('../../shared/KoncordeWrapper');
28
28
  * @class GeoPointType
29
29
  */
30
30
  class GeoPointType extends BaseType {
31
- constructor() {
31
+ constructor () {
32
32
  super();
33
33
  this.typeName = 'geo_point';
34
34
  this.allowChildren = false;
@@ -41,7 +41,7 @@ class GeoPointType extends BaseType {
41
41
  * @param {string[]} errorMessages
42
42
  * @returns {boolean}
43
43
  */
44
- validate(typeOptions, fieldValue, errorMessages) {
44
+ validate (typeOptions, fieldValue, errorMessages) {
45
45
  if (Koncorde.convertGeopoint(fieldValue) === null) {
46
46
  errorMessages.push('Invalid GeoPoint format');
47
47
  return false;
@@ -63,7 +63,7 @@ const
63
63
  * @class GeoShapeType
64
64
  */
65
65
  class GeoShapeType extends BaseType {
66
- constructor() {
66
+ constructor () {
67
67
  super();
68
68
  this.typeName = 'geo_shape';
69
69
  this.allowChildren = false;
@@ -76,7 +76,7 @@ class GeoShapeType extends BaseType {
76
76
  * @param {string[]} errorMessages
77
77
  * @returns {boolean}
78
78
  */
79
- validate(typeOptions, fieldValue, errorMessages) {
79
+ validate (typeOptions, fieldValue, errorMessages) {
80
80
  return this.recursiveShapeValidation(
81
81
  typeOptions.shapeTypes,
82
82
  fieldValue,
@@ -90,8 +90,8 @@ class GeoShapeType extends BaseType {
90
90
  * @param {string[]} errorMessages
91
91
  * @returns {boolean}
92
92
  */
93
- recursiveShapeValidation(allowedShapes, shape, errorMessages) {
94
- if (!this.checkStructure(allowedShapes, shape, errorMessages)) {
93
+ recursiveShapeValidation (allowedShapes, shape, errorMessages) {
94
+ if (! this.checkStructure(allowedShapes, shape, errorMessages)) {
95
95
  return false;
96
96
  }
97
97
 
@@ -113,7 +113,7 @@ class GeoShapeType extends BaseType {
113
113
  case 'multipolygon':
114
114
  coordinateValidation = isPolygon;
115
115
  if (shape.orientation
116
- && !allowedOrientations.includes(shape.orientation)
116
+ && ! allowedOrientations.includes(shape.orientation)
117
117
  ) {
118
118
  errorMessages.push('The orientation property has not a valid value.');
119
119
  result = false;
@@ -123,7 +123,7 @@ class GeoShapeType extends BaseType {
123
123
  coordinateValidation = () => true;
124
124
 
125
125
  for (let i = 0; i < shape.geometries.length; i++) {
126
- if (!this.recursiveShapeValidation(
126
+ if (! this.recursiveShapeValidation(
127
127
  allowedShapes,
128
128
  shape.geometries[i],
129
129
  errorMessages)
@@ -143,11 +143,13 @@ class GeoShapeType extends BaseType {
143
143
  errorMessages.push('The radius property has not a valid format.');
144
144
  result = false;
145
145
  }
146
- } catch (error) {
146
+ }
147
+ catch (error) {
147
148
  errorMessages.push('The radius property has not a valid format.');
148
149
  result = false;
149
150
  }
150
- } else if (typeof shape.radius !== 'number') {
151
+ }
152
+ else if (typeof shape.radius !== 'number') {
151
153
  errorMessages.push('The radius property has not a valid format.');
152
154
  result = false;
153
155
  }
@@ -161,14 +163,15 @@ class GeoShapeType extends BaseType {
161
163
 
162
164
  if (isMulti) {
163
165
  if (shape.coordinates.some(
164
- coordinate => !coordinateValidation(coordinate)
166
+ coordinate => ! coordinateValidation(coordinate)
165
167
  )) {
166
168
  errorMessages.push(
167
169
  `One of the shapes in the shape type "${shape.type}" has bad coordinates.`
168
170
  );
169
171
  result = false;
170
172
  }
171
- } else if (!coordinateValidation(shape.coordinates)) {
173
+ }
174
+ else if (! coordinateValidation(shape.coordinates)) {
172
175
  errorMessages.push(`The shape type "${shape.type}" has bad coordinates.`);
173
176
  return false;
174
177
  }
@@ -182,15 +185,15 @@ class GeoShapeType extends BaseType {
182
185
  * @param {string[]} errorMessages
183
186
  * @returns {boolean}
184
187
  */
185
- checkStructure(allowedShapes, shape, errorMessages) {
188
+ checkStructure (allowedShapes, shape, errorMessages) {
186
189
  let result = true;
187
190
 
188
- if (!shape.type) {
191
+ if (! shape.type) {
189
192
  errorMessages.push('The shape object has no type defined.');
190
193
  return false;
191
194
  }
192
195
 
193
- if (!this.checkAllowedProperties(shape, allowedShapeProperties)) {
196
+ if (! this.checkAllowedProperties(shape, allowedShapeProperties)) {
194
197
  errorMessages.push('The shape object has a not allowed property.');
195
198
  result = false;
196
199
  }
@@ -206,13 +209,13 @@ class GeoShapeType extends BaseType {
206
209
  }
207
210
 
208
211
  if (shape.type !== 'geometrycollection'
209
- && (!shape.coordinates || !Array.isArray(shape.coordinates)
212
+ && (! shape.coordinates || ! Array.isArray(shape.coordinates)
210
213
  )) {
211
214
  errorMessages.push(`The coordinates property must be provided for the "${shape.type}" shape type.`);
212
215
  result = false;
213
216
  }
214
217
 
215
- if (shape.type === 'circle' && !shape.radius) {
218
+ if (shape.type === 'circle' && ! shape.radius) {
216
219
  errorMessages.push('The radius property is mandatory for the "circle" shape type.');
217
220
  result = false;
218
221
  }
@@ -236,7 +239,7 @@ class GeoShapeType extends BaseType {
236
239
  }
237
240
 
238
241
  if (shape.type === 'geometrycollection'
239
- && (!shape.geometries || !Array.isArray(shape.geometries)
242
+ && (! shape.geometries || ! Array.isArray(shape.geometries)
240
243
  )) {
241
244
  errorMessages.push('The geometries property must be provided for the "geometrycollection" shape type.');
242
245
  result = false;
@@ -250,16 +253,16 @@ class GeoShapeType extends BaseType {
250
253
  * @returns {TypeOptions}
251
254
  * @throws {PreconditionError}
252
255
  */
253
- validateFieldSpecification(typeOptions) {
256
+ validateFieldSpecification (typeOptions) {
254
257
  if (Object.prototype.hasOwnProperty.call(typeOptions, 'shapeTypes')) {
255
- if (!Array.isArray(typeOptions.shapeTypes)
258
+ if (! Array.isArray(typeOptions.shapeTypes)
256
259
  || typeOptions.shapeTypes.length === 0
257
260
  ) {
258
261
  throw kerror.get('validation', 'assert', 'invalid_type', 'shapeTypes', 'string[]');
259
262
  }
260
263
 
261
264
  const invalid = typeOptions.shapeTypes.filter(
262
- shape => !allowedShapeTypes.includes(shape));
265
+ shape => ! allowedShapeTypes.includes(shape));
263
266
 
264
267
  if (invalid.length > 0) {
265
268
  throw kerror.get('validation', 'types', 'invalid_geoshape', invalid);
@@ -278,11 +281,11 @@ class GeoShapeType extends BaseType {
278
281
  * @returns {boolean}
279
282
  */
280
283
  function isPoint (point) {
281
- if (!Array.isArray(point) || point.length !== 2) {
284
+ if (! Array.isArray(point) || point.length !== 2) {
282
285
  return false;
283
286
  }
284
287
 
285
- return !(
288
+ return ! (
286
289
  point[0] < -180
287
290
  || point[0] > 180
288
291
  || point[1] < -90
@@ -294,7 +297,7 @@ function isPoint (point) {
294
297
  * @param {GeoShapePointCoordinates} pointB
295
298
  * @returns {boolean}
296
299
  */
297
- function isPointEqual(pointA, pointB) {
300
+ function isPointEqual (pointA, pointB) {
298
301
  return pointA[0] === pointB[0] && pointA[1] === pointB[1];
299
302
  }
300
303
 
@@ -303,7 +306,7 @@ function isPointEqual(pointA, pointB) {
303
306
  * @returns {boolean}
304
307
  */
305
308
  function isLine (line) {
306
- if (!Array.isArray(line) || line.length < 2) {
309
+ if (! Array.isArray(line) || line.length < 2) {
307
310
  return false;
308
311
  }
309
312
 
@@ -326,7 +329,7 @@ function isPolygonPart (polygonPart) {
326
329
  * @returns {boolean}
327
330
  */
328
331
  function isPolygon (polygon) {
329
- if (!Array.isArray(polygon)) {
332
+ if (! Array.isArray(polygon)) {
330
333
  return false;
331
334
  }
332
335
 
@@ -334,7 +337,7 @@ function isPolygon (polygon) {
334
337
  }
335
338
 
336
339
  function isEnvelope (envelope) {
337
- if (!Array.isArray(envelope) || envelope.length !== 2) {
340
+ if (! Array.isArray(envelope) || envelope.length !== 2) {
338
341
  return false;
339
342
  }
340
343
 
@@ -27,7 +27,7 @@ const Numeric = require('./numeric');
27
27
  * @class IntegerType
28
28
  */
29
29
  class IntegerType extends Numeric {
30
- constructor() {
30
+ constructor () {
31
31
  super();
32
32
  this.typeName = 'integer';
33
33
  this.allowChildren = false;
@@ -40,12 +40,12 @@ class IntegerType extends Numeric {
40
40
  * @param {string[]} errorMessages
41
41
  * @returns {boolean}
42
42
  */
43
- validate(typeOptions, fieldValue, errorMessages) {
44
- if (!super.validate(typeOptions, fieldValue, errorMessages)) {
43
+ validate (typeOptions, fieldValue, errorMessages) {
44
+ if (! super.validate(typeOptions, fieldValue, errorMessages)) {
45
45
  return false;
46
46
  }
47
47
 
48
- if (!Number.isInteger(fieldValue)) {
48
+ if (! Number.isInteger(fieldValue)) {
49
49
  errorMessages.push('The field must be an integer.');
50
50
  return false;
51
51
  }
@@ -30,7 +30,7 @@ const
30
30
  * @class IpAddressType
31
31
  */
32
32
  class IpAddressType extends BaseType {
33
- constructor() {
33
+ constructor () {
34
34
  super();
35
35
  this.typeName = 'ip_address';
36
36
  this.allowChildren = false;
@@ -43,7 +43,7 @@ class IpAddressType extends BaseType {
43
43
  * @param {string[]} errorMessages
44
44
  * @returns {boolean}
45
45
  */
46
- validate(typeOptions, fieldValue, errorMessages) {
46
+ validate (typeOptions, fieldValue, errorMessages) {
47
47
  if (typeof fieldValue !== 'string') {
48
48
  errorMessages.push('The field must be a string.');
49
49
  return false;
@@ -57,7 +57,7 @@ class IpAddressType extends BaseType {
57
57
  return true;
58
58
  }
59
59
 
60
- if (!validator.isIP(fieldValue)) {
60
+ if (! validator.isIP(fieldValue)) {
61
61
  errorMessages.push('The string must be a valid IP address.');
62
62
  return false;
63
63
  }
@@ -70,10 +70,11 @@ class IpAddressType extends BaseType {
70
70
  * @returns {TypeOptions}
71
71
  * @throws {PreconditionError}
72
72
  */
73
- validateFieldSpecification(typeOptions) {
74
- if (!Object.prototype.hasOwnProperty.call(typeOptions, 'notEmpty')) {
73
+ validateFieldSpecification (typeOptions) {
74
+ if (! Object.prototype.hasOwnProperty.call(typeOptions, 'notEmpty')) {
75
75
  typeOptions.notEmpty = false;
76
- } else if (typeof typeOptions.notEmpty !== 'boolean') {
76
+ }
77
+ else if (typeof typeOptions.notEmpty !== 'boolean') {
77
78
  throw kerror.get('invalid_type', 'notEmpty', 'boolean');
78
79
  }
79
80
 
@@ -29,7 +29,7 @@ const
29
29
  * @class NumericType
30
30
  */
31
31
  class NumericType extends BaseType {
32
- constructor() {
32
+ constructor () {
33
33
  super();
34
34
  this.typeName = 'numeric';
35
35
  this.allowChildren = false;
@@ -42,7 +42,7 @@ class NumericType extends BaseType {
42
42
  * @param {string[]} errorMessages
43
43
  * @returns {boolean}
44
44
  */
45
- validate(typeOptions, fieldValue, errorMessages) {
45
+ validate (typeOptions, fieldValue, errorMessages) {
46
46
  if (typeof fieldValue !== 'number') {
47
47
  errorMessages.push('The field must be a number.');
48
48
  return false;
@@ -72,9 +72,9 @@ class NumericType extends BaseType {
72
72
  * @returns {TypeOptions}
73
73
  * @throws {PreconditionError}
74
74
  */
75
- validateFieldSpecification(typeOptions) {
75
+ validateFieldSpecification (typeOptions) {
76
76
  if (Object.prototype.hasOwnProperty.call(typeOptions, 'range')) {
77
- if (!this.checkAllowedProperties(typeOptions.range, ['min', 'max'])) {
77
+ if (! this.checkAllowedProperties(typeOptions.range, ['min', 'max'])) {
78
78
  throw kerror.get('unexpected_properties', 'range', 'min, max');
79
79
  }
80
80