@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.cjs CHANGED
@@ -110,12 +110,18 @@ function getPrimarySuccessContentType(node) {
110
110
  return contentTypes[0].split(";")[0].trim().toLowerCase();
111
111
  }
112
112
  /**
113
- * Whether an operation streams its primary success response as Server-Sent Events
114
- * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
115
- * one-shot `RequestResult`.
113
+ * The `text/event-stream` content of the primary success response, when it is the only content type. A response that also
114
+ * declares another type stays a normal call with its query hooks.
115
+ */
116
+ function getEventStreamContent(node) {
117
+ return getPrimarySuccessContentType(node) === "text/event-stream" ? getPrimarySuccessResponse(node)?.content?.[0] : void 0;
118
+ }
119
+ /**
120
+ * Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client
121
+ * generator uses this to return a typed event stream instead of a one-shot `RequestResult`.
116
122
  */
117
123
  function isEventStream(node) {
118
- return getPrimarySuccessContentType(node) === "text/event-stream";
124
+ return getEventStreamContent(node) !== void 0;
119
125
  }
120
126
  const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
121
127
  function buildRequestConfigType(node) {
@@ -183,6 +189,22 @@ function buildOperationComments(node, options = {}) {
183
189
  }
184
190
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
185
191
  /**
192
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
193
+ * per property, typed and serialized like any other.
194
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
195
+ */
196
+ function spreadQuerystring(param) {
197
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
198
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
199
+ if (schema?.type !== "object" || !formEncoded) return [param];
200
+ return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
201
+ name: property.name,
202
+ in: "query",
203
+ schema: property.schema,
204
+ required: param.required && property.required
205
+ }));
206
+ }
207
+ /**
186
208
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
187
209
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
188
210
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -191,17 +213,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
191
213
  function getOperationParameters(node) {
192
214
  const cached = operationParameterGroupsByNode.get(node);
193
215
  if (cached) return cached;
194
- const group = (location) => {
216
+ const dedupe = (params) => {
195
217
  const seen = /* @__PURE__ */ new Set();
196
- return node.parameters.filter((param) => {
197
- if (param.in !== location || seen.has(param.name)) return false;
218
+ return params.filter((param) => {
219
+ if (seen.has(param.name)) return false;
198
220
  seen.add(param.name);
199
221
  return true;
200
222
  });
201
223
  };
224
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
202
225
  const groups = {
203
226
  path: group("path"),
204
- query: group("query"),
227
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
205
228
  header: group("header"),
206
229
  cookie: group("cookie")
207
230
  };
@@ -488,11 +511,11 @@ function createGroupConfig(group) {
488
511
  }
489
512
  // kubb-extension.json
490
513
  var compatibility = {
491
- "kubb": ">=5.14.6",
514
+ "kubb": ">=5.16.0",
492
515
  "node": ">=22.22"
493
516
  };
494
517
  // package.json
495
- var version = "5.8.0";
518
+ var version = "5.8.1";
496
519
  // ../../internals/client/src/resolveOperationTypes.ts
497
520
  /**
498
521
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`