@creatio-devkit/common 0.821.0 → 0.822.0

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.
@@ -1027,18 +1027,19 @@ class InternalRequestHandlerRegistryType {
1027
1027
  */
1028
1028
  static addRequestHandler(handlerType, config) {
1029
1029
  const existingHandler = this._requestHandlersMap.get(handlerType);
1030
- if (!existingHandler || (existingHandler.instanceConfig?.lazy && !existingHandler.instanceType)) {
1031
- const mergedConfig = {
1032
- instanceType: config.instanceType,
1033
- instanceConfig: {
1034
- ...(existingHandler?.instanceConfig ?? {}),
1035
- ...config.instanceConfig,
1036
- },
1037
- };
1038
- this._requestHandlersMap.set(handlerType, mergedConfig);
1039
- for (const listener of this._addItemListeners) {
1040
- listener(handlerType, mergedConfig);
1041
- }
1030
+ if (existingHandler && (!existingHandler.instanceConfig?.lazy || existingHandler.instanceType)) {
1031
+ return;
1032
+ }
1033
+ const mergedConfig = {
1034
+ instanceType: config.instanceType,
1035
+ instanceConfig: {
1036
+ ...(existingHandler?.instanceConfig ?? {}),
1037
+ ...config.instanceConfig,
1038
+ },
1039
+ };
1040
+ this._requestHandlersMap.set(handlerType, mergedConfig);
1041
+ for (const listener of this._addItemListeners) {
1042
+ listener(handlerType, mergedConfig);
1042
1043
  }
1043
1044
  }
1044
1045
  /**
@@ -1046,11 +1047,12 @@ class InternalRequestHandlerRegistryType {
1046
1047
  */
1047
1048
  static removeRequestHandler(handlerType) {
1048
1049
  const config = this._requestHandlersMap.get(handlerType);
1049
- if (config) {
1050
- this._requestHandlersMap.delete(handlerType);
1051
- for (const listener of this._removeItemListeners) {
1052
- listener(handlerType, config);
1053
- }
1050
+ if (!config) {
1051
+ return;
1052
+ }
1053
+ this._requestHandlersMap.delete(handlerType);
1054
+ for (const listener of this._removeItemListeners) {
1055
+ listener(handlerType, config);
1054
1056
  }
1055
1057
  }
1056
1058
  static clear() {
@@ -1080,16 +1082,16 @@ class RequestHandlerRegistryService {
1080
1082
  /**
1081
1083
  * Register request handler class.
1082
1084
  * @param config Request handler registration config.
1083
- * @param type Request handler type.
1085
+ * @param typeRef Request handler type reference (constructor).
1084
1086
  */
1085
- static register(config, type) {
1087
+ static register(config, typeRef) {
1086
1088
  const requestType = config.requestType;
1087
1089
  const requestHandlerType = config.type;
1088
1090
  if (!requestType) {
1089
1091
  throw new Error(`Error when register ${requestHandlerType}. Request type not specified.`);
1090
1092
  }
1091
1093
  const requestHandlerMapValue = {
1092
- instanceType: type,
1094
+ instanceType: typeRef,
1093
1095
  instanceConfig: config,
1094
1096
  };
1095
1097
  RequestHandlerRegistryService._internalRegistry.addRequestHandler(requestHandlerType, requestHandlerMapValue);
@@ -1137,17 +1139,21 @@ class ConverterRegistry extends ɵBaseRegistry {
1137
1139
  static has(type) {
1138
1140
  return this.store.typeInfos.has(type);
1139
1141
  }
1142
+ static find(type) {
1143
+ return this.store.typeInfos.get(type);
1144
+ }
1140
1145
  static get(type) {
1141
- if (!this.store.typeInfos.has(type)) {
1146
+ const registryItem = this.find(type);
1147
+ if (!registryItem) {
1142
1148
  throw new Error(`'${type}' converter doesn't exist`);
1143
1149
  }
1144
- return this.store.typeInfos.get(type);
1150
+ return registryItem;
1145
1151
  }
1146
1152
  static register(item) {
1147
1153
  checkTypeNameFormat(item.type, 'ConverterTypeName');
1148
1154
  checkCrtTypeNamePascalCase(item.type);
1149
1155
  // TODO RND-21723
1150
- const existingItem = this.store.typeInfos.get(item.type);
1156
+ const existingItem = this.find(item.type);
1151
1157
  this.store.typeInfos.set(item.type, {
1152
1158
  ...(existingItem ?? {}),
1153
1159
  ...item,
@@ -1354,16 +1360,19 @@ const validatorRegistryKey = 'ValidatorRegistry';
1354
1360
  */
1355
1361
  class ValidatorRegistry extends ɵBaseRegistry {
1356
1362
  static { this.registryKey = validatorRegistryKey; }
1357
- static _has(configType, type) {
1358
- const config = ValidatorRegistry.items.get(configType);
1359
- if (config?.lazy && !config?.typeRef) {
1363
+ static _hasWithAnotherTypeRef(configType, typeRef) {
1364
+ const existingItem = ValidatorRegistry.items.get(configType);
1365
+ if (!existingItem) {
1366
+ return false;
1367
+ }
1368
+ if (existingItem.lazy && !existingItem.typeRef) {
1360
1369
  return false;
1361
1370
  }
1362
- return ValidatorRegistry.items.has(configType) && ValidatorRegistry.items.get(configType)?.typeRef !== type;
1371
+ return existingItem.typeRef !== typeRef;
1363
1372
  }
1364
1373
  static validate(config) {
1365
1374
  checkTypeNameFormat(config.type, 'ValidatorTypeName');
1366
- if (config.typeRef && ValidatorRegistry._has(config.type, config.typeRef)) {
1375
+ if (config.typeRef && ValidatorRegistry._hasWithAnotherTypeRef(config.type, config.typeRef)) {
1367
1376
  throw new Error(`Error when register ${config.type}. Element with this type has already exist`);
1368
1377
  }
1369
1378
  }
@@ -1456,16 +1465,16 @@ class LazyModuleRef {
1456
1465
  get typeRef() {
1457
1466
  return this._typeRef;
1458
1467
  }
1459
- constructor(_metadata, _bootstrapFn,
1468
+ constructor(_moduleDefinition, _bootstrapFn,
1460
1469
  /** Name of source build ('host' or remote name) */
1461
1470
  sourceName) {
1462
- this._metadata = _metadata;
1471
+ this._moduleDefinition = _moduleDefinition;
1463
1472
  this._bootstrapFn = _bootstrapFn;
1464
1473
  this.sourceName = sourceName;
1465
1474
  }
1466
1475
  loadAndBootstrap() {
1467
1476
  if (!this._modulePromise) {
1468
- this._modulePromise = this._metadata.load().then((type) => {
1477
+ this._modulePromise = this._moduleDefinition.load().then((type) => {
1469
1478
  this._typeRef = type;
1470
1479
  this._bootstrapFn(type);
1471
1480
  return type;
@@ -1932,18 +1941,18 @@ function bootstrapDefaultCrtModule(name, type, options, root) {
1932
1941
  if (moduleDefinition.converters) {
1933
1942
  registerConverters(moduleDefinition.converters, options);
1934
1943
  }
1935
- moduleDefinition.includes?.forEach((t) => {
1936
- if (typeof t === 'function') {
1937
- bootstrapDefaultCrtModule(name, t, options, false);
1938
- bootstrapPredefinedModules(name, t, options);
1944
+ moduleDefinition.includes?.forEach((includedModuleMetadata) => {
1945
+ if (typeof includedModuleMetadata === 'function') {
1946
+ bootstrapDefaultCrtModule(name, includedModuleMetadata, options, false);
1947
+ bootstrapPredefinedModules(name, includedModuleMetadata, options);
1939
1948
  }
1940
- else if (typeof t === 'object') {
1949
+ else if (typeof includedModuleMetadata === 'object') {
1941
1950
  if (options.moduleType === 'remote' && !name) {
1942
1951
  console.error("To use lazy loading, 'remoteName' parameter should be specified.");
1943
1952
  return;
1944
1953
  }
1945
- const ref = new LazyModuleRef(t, (x) => bootstrapDefaultCrtModule(name, x, options, false), source);
1946
- bootstrapLazyCrtModule(name, t, options, ref);
1954
+ const ref = new LazyModuleRef(includedModuleMetadata, (x) => bootstrapDefaultCrtModule(name, x, options, false), source);
1955
+ bootstrapLazyCrtModule(name, includedModuleMetadata, options, ref);
1947
1956
  LazyModulesManager.instance.add(ref);
1948
1957
  }
1949
1958
  });