@kubb/plugin-swr 5.8.0 → 5.8.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.
package/dist/index.js CHANGED
@@ -84,12 +84,18 @@ function getPrimarySuccessContentType(node) {
84
84
  return contentTypes[0].split(";")[0].trim().toLowerCase();
85
85
  }
86
86
  /**
87
- * Whether an operation streams its primary success response as Server-Sent Events
88
- * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
89
- * one-shot `RequestResult`.
87
+ * The `text/event-stream` content of the primary success response, when it is the only content type. A response that also
88
+ * declares another type stays a normal call with its query hooks.
89
+ */
90
+ function getEventStreamContent(node) {
91
+ return getPrimarySuccessContentType(node) === "text/event-stream" ? getPrimarySuccessResponse(node)?.content?.[0] : void 0;
92
+ }
93
+ /**
94
+ * Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client
95
+ * generator uses this to return a typed event stream instead of a one-shot `RequestResult`.
90
96
  */
91
97
  function isEventStream(node) {
92
- return getPrimarySuccessContentType(node) === "text/event-stream";
98
+ return getEventStreamContent(node) !== void 0;
93
99
  }
94
100
  const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
95
101
  function buildRequestConfigType(node) {
@@ -157,6 +163,22 @@ function buildOperationComments(node, options = {}) {
157
163
  }
158
164
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
159
165
  /**
166
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
167
+ * per property, typed and serialized like any other.
168
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
169
+ */
170
+ function spreadQuerystring(param) {
171
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
172
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
173
+ if (schema?.type !== "object" || !formEncoded) return [param];
174
+ return schema.properties.map((property) => ast.factory.createParameter({
175
+ name: property.name,
176
+ in: "query",
177
+ schema: property.schema,
178
+ required: param.required && property.required
179
+ }));
180
+ }
181
+ /**
160
182
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
161
183
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
162
184
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -165,17 +187,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
165
187
  function getOperationParameters(node) {
166
188
  const cached = operationParameterGroupsByNode.get(node);
167
189
  if (cached) return cached;
168
- const group = (location) => {
190
+ const dedupe = (params) => {
169
191
  const seen = /* @__PURE__ */ new Set();
170
- return node.parameters.filter((param) => {
171
- if (param.in !== location || seen.has(param.name)) return false;
192
+ return params.filter((param) => {
193
+ if (seen.has(param.name)) return false;
172
194
  seen.add(param.name);
173
195
  return true;
174
196
  });
175
197
  };
198
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
176
199
  const groups = {
177
200
  path: group("path"),
178
- query: group("query"),
201
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
179
202
  header: group("header"),
180
203
  cookie: group("cookie")
181
204
  };
@@ -462,11 +485,11 @@ function createGroupConfig(group) {
462
485
  }
463
486
  // kubb-extension.json
464
487
  var compatibility = {
465
- "kubb": ">=5.14.6",
488
+ "kubb": ">=5.16.0",
466
489
  "node": ">=22.22"
467
490
  };
468
491
  // package.json
469
- var version = "5.8.0";
492
+ var version = "5.8.1";
470
493
  // ../../internals/client/src/resolveOperationTypes.ts
471
494
  /**
472
495
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`