@azure/core-client 1.6.1-alpha.20220518.2 → 1.6.1-alpha.20220725.3

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/dist/index.js CHANGED
@@ -166,6 +166,9 @@ class SerializerImpl {
166
166
  this.modelMappers = modelMappers;
167
167
  this.isXML = isXML;
168
168
  }
169
+ /**
170
+ * @deprecated Removing the constraints validation on client side.
171
+ */
169
172
  validateConstraints(mapper, value, objectName) {
170
173
  const failValidation = (constraintName, constraintValue) => {
171
174
  throw new Error(`"${objectName}" with value "${value}" should satisfy the constraint "${constraintName}": ${constraintValue}.`);
@@ -267,8 +270,6 @@ class SerializerImpl {
267
270
  payload = object;
268
271
  }
269
272
  else {
270
- // Validate Constraints if any
271
- this.validateConstraints(mapper, object, objectName);
272
273
  if (mapperType.match(/^any$/i) !== null) {
273
274
  payload = object;
274
275
  }
@@ -979,7 +980,30 @@ function deserializeSequenceType(serializer, mapper, responseBody, objectName, o
979
980
  }
980
981
  return responseBody;
981
982
  }
983
+ function getIndexDiscriminator(discriminators, discriminatorValue, typeName) {
984
+ const typeNamesToCheck = [typeName];
985
+ while (typeNamesToCheck.length) {
986
+ const currentName = typeNamesToCheck.shift();
987
+ const indexDiscriminator = discriminatorValue === currentName
988
+ ? discriminatorValue
989
+ : currentName + "." + discriminatorValue;
990
+ if (Object.prototype.hasOwnProperty.call(discriminators, indexDiscriminator)) {
991
+ return discriminators[indexDiscriminator];
992
+ }
993
+ else {
994
+ for (const [name, mapper] of Object.entries(discriminators)) {
995
+ if (name.startsWith(currentName + ".") &&
996
+ mapper.type.uberParent === currentName &&
997
+ mapper.type.className) {
998
+ typeNamesToCheck.push(mapper.type.className);
999
+ }
1000
+ }
1001
+ }
1002
+ }
1003
+ return undefined;
1004
+ }
982
1005
  function getPolymorphicMapper(serializer, mapper, object, polymorphicPropertyName) {
1006
+ var _a;
983
1007
  const polymorphicDiscriminator = getPolymorphicDiscriminatorRecursively(serializer, mapper);
984
1008
  if (polymorphicDiscriminator) {
985
1009
  let discriminatorName = polymorphicDiscriminator[polymorphicPropertyName];
@@ -989,12 +1013,9 @@ function getPolymorphicMapper(serializer, mapper, object, polymorphicPropertyNam
989
1013
  discriminatorName = discriminatorName.replace(/\\/gi, "");
990
1014
  }
991
1015
  const discriminatorValue = object[discriminatorName];
992
- if (discriminatorValue !== undefined && discriminatorValue !== null) {
993
- const typeName = mapper.type.uberParent || mapper.type.className;
994
- const indexDiscriminator = discriminatorValue === typeName
995
- ? discriminatorValue
996
- : typeName + "." + discriminatorValue;
997
- const polymorphicMapper = serializer.modelMappers.discriminators[indexDiscriminator];
1016
+ const typeName = (_a = mapper.type.uberParent) !== null && _a !== void 0 ? _a : mapper.type.className;
1017
+ if (typeof discriminatorValue === "string" && typeName) {
1018
+ const polymorphicMapper = getIndexDiscriminator(serializer.modelMappers.discriminators, discriminatorValue, typeName);
998
1019
  if (polymorphicMapper) {
999
1020
  mapper = polymorphicMapper;
1000
1021
  }