mock-config-server 3.6.0 → 3.6.1

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.
@@ -34,7 +34,31 @@ const calculateRouteConfigWeight = (restRouteConfig)=>{
34
34
  return routeConfigWeight;
35
35
  };
36
36
  const prepareRestRequestConfigs = (requestConfigs)=>{
37
- requestConfigs.forEach((requestConfig)=>{
37
+ const sortedByPathRequestConfigs = requestConfigs.sort(({ path: firstPath }, { path: secondPath })=>{
38
+ // ✅ important:
39
+ // do not compare RegExp paths and non-parameterized paths
40
+ if (firstPath instanceof RegExp || secondPath instanceof RegExp) return 0;
41
+ if (!firstPath.includes('/:') && !secondPath.includes('/:')) return 0;
42
+ const firstPathParts = firstPath.split('/');
43
+ const secondPathParts = secondPath.split('/');
44
+ const minimalPathPartsLength = Math.min(firstPathParts.length, secondPathParts.length);
45
+ // ✅ important:
46
+ // need to find the leftmost parameter/non-parameter pair and give priority to non-parameter one
47
+ for(let i = 0; i < minimalPathPartsLength; i += 1){
48
+ const firstPathPart = firstPathParts[i];
49
+ const secondPathPart = secondPathParts[i];
50
+ const isFirstPathPartParameter = firstPathPart.startsWith(':');
51
+ const isSecondPathPartParameter = secondPathPart.startsWith(':');
52
+ if (!isFirstPathPartParameter && !isSecondPathPartParameter) {
53
+ if (firstPathPart === secondPathPart) continue;
54
+ return 0;
55
+ }
56
+ if (isFirstPathPartParameter && isSecondPathPartParameter) continue;
57
+ return +isFirstPathPartParameter - +isSecondPathPartParameter;
58
+ }
59
+ return 0;
60
+ });
61
+ sortedByPathRequestConfigs.forEach((requestConfig)=>{
38
62
  requestConfig.routes.sort((first, second)=>// ✅ important:
39
63
  // Lift more specific configs for correct working of routes
40
64
  calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mock-config-server",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",