@sebspark/openapi-client 1.2.0 → 1.3.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
@@ -39,6 +39,45 @@ module.exports = __toCommonJS(src_exports);
39
39
  var import_openapi_core = require("@sebspark/openapi-core");
40
40
  var import_retry = require("@sebspark/retry");
41
41
  var import_axios = __toESM(require("axios"));
42
+
43
+ // src/paramsSerializer.ts
44
+ var paramsSerializer = (format) => (
45
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
46
+ (params) => {
47
+ if (!params) {
48
+ return "";
49
+ }
50
+ return Object.entries(params).filter(([, value]) => value !== void 0).flatMap(([key, value]) => {
51
+ if (Array.isArray(value)) {
52
+ if (format === "comma") {
53
+ return `${encodeURIComponent(key)}=${value.map((v) => encodeURIComponent(v)).join(",")}`;
54
+ }
55
+ return value.map((arrayValue, ix) => {
56
+ switch (format) {
57
+ case "indices": {
58
+ return `${encodeURIComponent(key)}[${ix}]=${encodeURIComponent(
59
+ arrayValue
60
+ )}`;
61
+ }
62
+ case "repeat": {
63
+ return `${encodeURIComponent(key)}=${encodeURIComponent(
64
+ arrayValue
65
+ )}`;
66
+ }
67
+ default: {
68
+ return `${encodeURIComponent(key)}[]=${encodeURIComponent(
69
+ arrayValue
70
+ )}`;
71
+ }
72
+ }
73
+ });
74
+ }
75
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
76
+ }).join("&");
77
+ }
78
+ );
79
+
80
+ // src/client.ts
42
81
  var TypedClient = (baseURL, globalOptions) => {
43
82
  const client = {
44
83
  get: (url, args, opts) => callServer(mergeArgs(baseURL, url, "get", args, opts, globalOptions)),
@@ -51,6 +90,7 @@ var TypedClient = (baseURL, globalOptions) => {
51
90
  };
52
91
  var callServer = async (args) => {
53
92
  try {
93
+ const serializer = paramsSerializer(args.arrayFormat);
54
94
  const { headers, data } = await (0, import_retry.retry)(
55
95
  () => import_axios.default.request({
56
96
  baseURL: args.baseUrl,
@@ -58,6 +98,7 @@ var callServer = async (args) => {
58
98
  method: args.method,
59
99
  headers: args.headers,
60
100
  params: args.params,
101
+ paramsSerializer: serializer,
61
102
  data: args.body
62
103
  }),
63
104
  args.retry
package/dist/index.mjs CHANGED
@@ -4,6 +4,45 @@ import {
4
4
  } from "@sebspark/openapi-core";
5
5
  import { retry } from "@sebspark/retry";
6
6
  import axios from "axios";
7
+
8
+ // src/paramsSerializer.ts
9
+ var paramsSerializer = (format) => (
10
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
11
+ (params) => {
12
+ if (!params) {
13
+ return "";
14
+ }
15
+ return Object.entries(params).filter(([, value]) => value !== void 0).flatMap(([key, value]) => {
16
+ if (Array.isArray(value)) {
17
+ if (format === "comma") {
18
+ return `${encodeURIComponent(key)}=${value.map((v) => encodeURIComponent(v)).join(",")}`;
19
+ }
20
+ return value.map((arrayValue, ix) => {
21
+ switch (format) {
22
+ case "indices": {
23
+ return `${encodeURIComponent(key)}[${ix}]=${encodeURIComponent(
24
+ arrayValue
25
+ )}`;
26
+ }
27
+ case "repeat": {
28
+ return `${encodeURIComponent(key)}=${encodeURIComponent(
29
+ arrayValue
30
+ )}`;
31
+ }
32
+ default: {
33
+ return `${encodeURIComponent(key)}[]=${encodeURIComponent(
34
+ arrayValue
35
+ )}`;
36
+ }
37
+ }
38
+ });
39
+ }
40
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
41
+ }).join("&");
42
+ }
43
+ );
44
+
45
+ // src/client.ts
7
46
  var TypedClient = (baseURL, globalOptions) => {
8
47
  const client = {
9
48
  get: (url, args, opts) => callServer(mergeArgs(baseURL, url, "get", args, opts, globalOptions)),
@@ -16,6 +55,7 @@ var TypedClient = (baseURL, globalOptions) => {
16
55
  };
17
56
  var callServer = async (args) => {
18
57
  try {
58
+ const serializer = paramsSerializer(args.arrayFormat);
19
59
  const { headers, data } = await retry(
20
60
  () => axios.request({
21
61
  baseURL: args.baseUrl,
@@ -23,6 +63,7 @@ var callServer = async (args) => {
23
63
  method: args.method,
24
64
  headers: args.headers,
25
65
  params: args.params,
66
+ paramsSerializer: serializer,
26
67
  data: args.body
27
68
  }),
28
69
  args.retry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/openapi-client",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",