api-def 0.12.0-alpha.49 → 0.12.0-alpha.50

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/cjs/ApiUtils.js CHANGED
@@ -58,15 +58,30 @@ exports.inferResponseType = inferResponseType;
58
58
  var resolvePathParams = function (path, params) {
59
59
  var computedPath = path.startsWith("/") ? path : "/".concat(path);
60
60
  if (params) {
61
- var keys = Object.keys(params);
62
- for (var i = 0; i < keys.length; i++) {
63
- var argName = keys[i];
64
- var argValue = params[argName];
65
- computedPath = computedPath.replace(":".concat(argName), argValue).replace("{".concat(argName, "}"), argValue);
61
+ var computedPathParts = computedPath.split("/");
62
+ var unusedKeys = new Set(Object.keys(params));
63
+ for (var i = 0; i < computedPathParts.length; i++) {
64
+ var part = computedPathParts[i];
65
+ var paramKey = void 0;
66
+ if (part.startsWith(":")) {
67
+ paramKey = part.substring(1);
68
+ }
69
+ else if (part.startsWith("{") && part.endsWith("}")) {
70
+ paramKey = part.substring(1, part.length - 1);
71
+ }
72
+ if (paramKey) {
73
+ var paramValue = params[paramKey];
74
+ if (!paramValue) {
75
+ throw new Error("[api-def] Missing param '".concat(paramKey, "'"));
76
+ }
77
+ computedPathParts[i] = paramValue;
78
+ unusedKeys.delete(paramKey);
79
+ }
66
80
  }
67
- }
68
- if (computedPath.includes(":") || computedPath.includes("{")) {
69
- throw new Error("[api-def] Not all path params have been resolved: '".concat(computedPath, "'"));
81
+ if (unusedKeys.size > 0) {
82
+ throw new Error("[api-def] Missing param '".concat(Array.from(unusedKeys)[0], "'"));
83
+ }
84
+ return computedPathParts.join("/");
70
85
  }
71
86
  return computedPath;
72
87
  };
package/esm/ApiUtils.js CHANGED
@@ -48,17 +48,32 @@ export const inferResponseType = (contentType) => {
48
48
  return "text";
49
49
  };
50
50
  export const resolvePathParams = (path, params) => {
51
- let computedPath = path.startsWith("/") ? path : `/${path}`;
51
+ const computedPath = path.startsWith("/") ? path : `/${path}`;
52
52
  if (params) {
53
- const keys = Object.keys(params);
54
- for (let i = 0; i < keys.length; i++) {
55
- const argName = keys[i];
56
- const argValue = params[argName];
57
- computedPath = computedPath.replace(`:${argName}`, argValue).replace(`{${argName}}`, argValue);
53
+ const computedPathParts = computedPath.split("/");
54
+ const unusedKeys = new Set(Object.keys(params));
55
+ for (let i = 0; i < computedPathParts.length; i++) {
56
+ const part = computedPathParts[i];
57
+ let paramKey;
58
+ if (part.startsWith(":")) {
59
+ paramKey = part.substring(1);
60
+ }
61
+ else if (part.startsWith("{") && part.endsWith("}")) {
62
+ paramKey = part.substring(1, part.length - 1);
63
+ }
64
+ if (paramKey) {
65
+ const paramValue = params[paramKey];
66
+ if (!paramValue) {
67
+ throw new Error(`[api-def] Missing param '${paramKey}'`);
68
+ }
69
+ computedPathParts[i] = paramValue;
70
+ unusedKeys.delete(paramKey);
71
+ }
58
72
  }
59
- }
60
- if (computedPath.includes(":") || computedPath.includes("{")) {
61
- throw new Error(`[api-def] Not all path params have been resolved: '${computedPath}'`);
73
+ if (unusedKeys.size > 0) {
74
+ throw new Error(`[api-def] Missing param '${Array.from(unusedKeys)[0]}'`);
75
+ }
76
+ return computedPathParts.join("/");
62
77
  }
63
78
  return computedPath;
64
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.12.0-alpha.49",
3
+ "version": "0.12.0-alpha.50",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",