@hyper-fetch/core 7.2.6 → 7.4.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/README.md CHANGED
@@ -13,9 +13,6 @@
13
13
  <a href="https://www.npmjs.com/package/@hyper-fetch/core">
14
14
  <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/core.svg?logo=npm&color=e76f51" />
15
15
  </a>
16
- <a href="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage">
17
- <img src="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage" />
18
- </a>
19
16
  <a href="https://github.com/BetterTyped/hyper-fetch">
20
17
  <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
21
18
  </a>
@@ -3589,18 +3589,32 @@ function createClient(options) {
3589
3589
  }
3590
3590
 
3591
3591
  // src/sdk/sdk.ts
3592
- var createRecursiveProxy = (client, path) => {
3592
+ var getMethod = (key, options) => {
3593
+ const { methodTransform = (method) => method.toUpperCase() } = options != null ? options : {};
3594
+ return methodTransform(key);
3595
+ };
3596
+ var createRecursiveProxy = (client, path, options) => {
3593
3597
  return new Proxy(() => {
3594
3598
  }, {
3595
3599
  get: (_target, key) => {
3596
3600
  if (typeof key === "symbol" || key === "inspect") {
3597
3601
  return void 0;
3598
3602
  }
3603
+ let isMethod = false;
3604
+ let methodName = key;
3605
+ let pathSegment = key;
3606
+ if (key.startsWith("$")) {
3607
+ isMethod = true;
3608
+ methodName = key.slice(1);
3609
+ pathSegment = `:${key.slice(1)}`;
3610
+ } else if (options == null ? void 0 : options.camelCaseToKebabCase) {
3611
+ pathSegment = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
3612
+ }
3599
3613
  const endpoint = `/${path.join("/")}`;
3600
- const method = key.toUpperCase();
3614
+ const method = getMethod(isMethod ? methodName : key, options);
3601
3615
  const request = client.createRequest()({ endpoint, method });
3602
- const newPath = [...path, key.startsWith("$") ? `:${key.slice(1)}` : key];
3603
- const deeperProxy = createRecursiveProxy(client, newPath);
3616
+ const newPath = [...path, pathSegment];
3617
+ const deeperProxy = createRecursiveProxy(client, newPath, options);
3604
3618
  return new Proxy(request, {
3605
3619
  get: (reqTarget, reqKey) => {
3606
3620
  if (reqKey in reqTarget) {
@@ -3612,8 +3626,15 @@ var createRecursiveProxy = (client, path) => {
3612
3626
  }
3613
3627
  });
3614
3628
  };
3615
- var createSdk = (client) => {
3616
- return createRecursiveProxy(client, []);
3629
+ var createSdk = (client, options) => {
3630
+ const _a = options != null ? options : {}, {
3631
+ camelCaseToKebabCase = true,
3632
+ methodTransform = (method) => method.toUpperCase()
3633
+ } = _a, rest = __objRest(_a, [
3634
+ "camelCaseToKebabCase",
3635
+ "methodTransform"
3636
+ ]);
3637
+ return createRecursiveProxy(client, [], __spreadValues({ camelCaseToKebabCase, methodTransform }, rest));
3617
3638
  };
3618
3639
  export {
3619
3640
  AbortError,