rest-client-sdk 7.1.1 → 7.2.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.
package/dist/index.js CHANGED
@@ -2122,6 +2122,54 @@
2122
2122
  return JsSerializer;
2123
2123
  }(Serializer);
2124
2124
 
2125
+ function levenshteinDistance(a, b) {
2126
+ var matrix = []; // Increment along the first column of each row
2127
+
2128
+ for (var i = 0; i <= b.length; i += 1) {
2129
+ matrix[i] = [i];
2130
+ } // Increment each column in the first row
2131
+
2132
+
2133
+ for (var j = 0; j <= a.length; j += 1) {
2134
+ matrix[0][j] = j;
2135
+ } // Fill in the rest of the matrix
2136
+
2137
+
2138
+ for (var _i = 1; _i <= b.length; _i += 1) {
2139
+ for (var _j = 1; _j <= a.length; _j += 1) {
2140
+ if (b.charAt(_i - 1) === a.charAt(_j - 1)) {
2141
+ matrix[_i][_j] = matrix[_i - 1][_j - 1];
2142
+ } else {
2143
+ matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1, // substitution
2144
+ matrix[_i][_j - 1] + 1, // insertion
2145
+ matrix[_i - 1][_j] + 1 // deletion
2146
+ );
2147
+ }
2148
+ }
2149
+ }
2150
+
2151
+ return matrix[b.length][a.length];
2152
+ } // eslint-disable-next-line import/prefer-default-export
2153
+
2154
+
2155
+ function findClosestWord(word, list) {
2156
+ var maxDistance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
2157
+ var closestWord = null;
2158
+ var minDistance = Infinity; // eslint-disable-next-line no-plusplus
2159
+
2160
+ for (var i = 0; i < list.length; i += 1) {
2161
+ var candidate = list[i];
2162
+ var distance = levenshteinDistance(word, candidate);
2163
+
2164
+ if (distance < minDistance && distance <= maxDistance) {
2165
+ minDistance = distance;
2166
+ closestWord = candidate;
2167
+ }
2168
+ }
2169
+
2170
+ return closestWord;
2171
+ }
2172
+
2125
2173
  var generateId = function generateId() {
2126
2174
  return "rest-client-sdk|".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
2127
2175
  };
@@ -2271,7 +2319,9 @@
2271
2319
  var metadata = this.mapping.getClassMetadataByKey(key);
2272
2320
 
2273
2321
  if (!metadata) {
2274
- throw new Error("Unable to get metadata for repository ".concat(key));
2322
+ var closeKey = findClosestWord(key, this.mapping.getMappingKeys(), 5);
2323
+ var suggestions = closeKey ? " Did you mean \"".concat(closeKey, "\"?") : '';
2324
+ throw new Error("Unable to get metadata for repository \"".concat(key, "\".").concat(suggestions));
2275
2325
  } // eslint-disable-next-line new-cap
2276
2326
 
2277
2327