@kubb/plugin-ts 5.4.0-canary.20261029T124214 → 5.4.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 +123 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +47 -11
- package/dist/index.js.map +1 -1
- package/docs/guides/customization.md +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +10 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
-
import { KubbReactNode } from "kubb/jsx";
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
+
import { KubbReactNode } from "@kubb/renderer-jsx";
|
|
3
3
|
/**
|
|
4
4
|
* A TS-ESTree node, the AST shape `yuku-codegen` prints. Nodes built here carry no source positions.
|
|
5
5
|
*/
|
|
@@ -489,7 +489,7 @@ export declare function Type({ name, node, printer, enum: enumOptions, resolver,
|
|
|
489
489
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
490
490
|
* TypeScript output is produced.
|
|
491
491
|
*/
|
|
492
|
-
export declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
492
|
+
export declare const typeGenerator: import("@kubb/kit").Generator<PluginTs, unknown>;
|
|
493
493
|
/**
|
|
494
494
|
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
495
495
|
* cross-plugin dependency references.
|
|
@@ -519,7 +519,7 @@ export declare const pluginTsName = "plugin-ts";
|
|
|
519
519
|
* })
|
|
520
520
|
* ```
|
|
521
521
|
*/
|
|
522
|
-
export declare const pluginTs: import("kubb/kit").PluginFactory<PluginTs>;
|
|
522
|
+
export declare const pluginTs: import("@kubb/kit").PluginFactory<PluginTs>;
|
|
523
523
|
/**
|
|
524
524
|
* A type expression used as a function parameter type annotation.
|
|
525
525
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
-
import { KubbReactNode } from "kubb/jsx";
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
+
import { KubbReactNode } from "@kubb/renderer-jsx";
|
|
3
3
|
/**
|
|
4
4
|
* A TS-ESTree node, the AST shape `yuku-codegen` prints. Nodes built here carry no source positions.
|
|
5
5
|
*/
|
|
@@ -489,7 +489,7 @@ export declare function Type({ name, node, printer, enum: enumOptions, resolver,
|
|
|
489
489
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
490
490
|
* TypeScript output is produced.
|
|
491
491
|
*/
|
|
492
|
-
export declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
492
|
+
export declare const typeGenerator: import("@kubb/kit").Generator<PluginTs, unknown>;
|
|
493
493
|
/**
|
|
494
494
|
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
495
495
|
* cross-plugin dependency references.
|
|
@@ -519,7 +519,7 @@ export declare const pluginTsName = "plugin-ts";
|
|
|
519
519
|
* })
|
|
520
520
|
* ```
|
|
521
521
|
*/
|
|
522
|
-
export declare const pluginTs: import("kubb/kit").PluginFactory<PluginTs>;
|
|
522
|
+
export declare const pluginTs: import("@kubb/kit").PluginFactory<PluginTs>;
|
|
523
523
|
/**
|
|
524
524
|
* A type expression used as a function parameter type annotation.
|
|
525
525
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { Diagnostics, Resolver, addGenerator, ast, camelCase, createResolver, defineExtension, defineGenerator, isStringType, pascalCase, setMacros, setResolver, syncSchemaRef } from "@kubb/kit";
|
|
3
|
+
import { File, jsxRenderer } from "@kubb/renderer-jsx";
|
|
3
4
|
import { generate } from "yuku-codegen";
|
|
4
|
-
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
5
|
-
import { parserTs } from "@kubb/parser-ts";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
6
6
|
// \0rolldown/runtime.js
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", {
|
|
@@ -879,6 +879,22 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
879
879
|
}
|
|
880
880
|
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
881
881
|
/**
|
|
882
|
+
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
883
|
+
* per property, typed and serialized like any other.
|
|
884
|
+
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
885
|
+
*/
|
|
886
|
+
function spreadQuerystring(param) {
|
|
887
|
+
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
888
|
+
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
889
|
+
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
890
|
+
return schema.properties.map((property) => ast.factory.createParameter({
|
|
891
|
+
name: property.name,
|
|
892
|
+
in: "query",
|
|
893
|
+
schema: property.schema,
|
|
894
|
+
required: param.required && property.required
|
|
895
|
+
}));
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
882
898
|
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
883
899
|
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
884
900
|
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
@@ -887,17 +903,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
887
903
|
function getOperationParameters(node) {
|
|
888
904
|
const cached = operationParameterGroupsByNode.get(node);
|
|
889
905
|
if (cached) return cached;
|
|
890
|
-
const
|
|
906
|
+
const dedupe = (params) => {
|
|
891
907
|
const seen = /* @__PURE__ */ new Set();
|
|
892
|
-
return
|
|
893
|
-
if (
|
|
908
|
+
return params.filter((param) => {
|
|
909
|
+
if (seen.has(param.name)) return false;
|
|
894
910
|
seen.add(param.name);
|
|
895
911
|
return true;
|
|
896
912
|
});
|
|
897
913
|
};
|
|
914
|
+
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
898
915
|
const groups = {
|
|
899
916
|
path: group("path"),
|
|
900
|
-
query: group("query"),
|
|
917
|
+
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
901
918
|
header: group("header"),
|
|
902
919
|
cookie: group("cookie")
|
|
903
920
|
};
|
|
@@ -1351,6 +1368,25 @@ function buildResponseUnion(node, { resolver }) {
|
|
|
1351
1368
|
}
|
|
1352
1369
|
// src/printers/printerTs.ts
|
|
1353
1370
|
const { isNonNullable } = factory_exports;
|
|
1371
|
+
const requireModule = createRequire(import.meta.url);
|
|
1372
|
+
/**
|
|
1373
|
+
* Loads `@kubb/parser-ts` on first use. It is an optional peer dependency: only a deprecated `printer.nodes`
|
|
1374
|
+
* handler that returns a TypeScript compiler node needs it. Loads synchronously because node handlers are synchronous.
|
|
1375
|
+
*/
|
|
1376
|
+
function loadParserTs(load = () => requireModule("@kubb/parser-ts")) {
|
|
1377
|
+
try {
|
|
1378
|
+
return load();
|
|
1379
|
+
} catch (error) {
|
|
1380
|
+
if (error.code !== "MODULE_NOT_FOUND" || !error.message.split("\n")[0].includes("@kubb/parser-ts")) throw error;
|
|
1381
|
+
throw new Diagnostics.Error({
|
|
1382
|
+
code: Diagnostics.code.missingDependency,
|
|
1383
|
+
severity: "error",
|
|
1384
|
+
message: "Missing dependency: @kubb/parser-ts. A `printer.nodes` handler returned a TypeScript compiler node, and printing it needs @kubb/parser-ts.",
|
|
1385
|
+
help: "Run `npm i -D @kubb/parser-ts` in the project, or return a string from the handler.",
|
|
1386
|
+
plugin: "plugin-ts"
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1354
1390
|
/**
|
|
1355
1391
|
* Adapts user overrides, which work in strings, to the node-based printer: `this.transform` hands them printed
|
|
1356
1392
|
* strings and their result is wrapped back into a node. A deprecated compiler node prints through `@kubb/parser-ts`.
|
|
@@ -1366,7 +1402,7 @@ function toNodeHandlers(nodes) {
|
|
|
1366
1402
|
transform
|
|
1367
1403
|
}, node);
|
|
1368
1404
|
if (result === null || result === void 0) return result;
|
|
1369
|
-
return createRaw(typeof result === "string" ? result : parserTs().print(result).trimEnd());
|
|
1405
|
+
return createRaw(typeof result === "string" ? result : loadParserTs().parserTs().print(result).trimEnd());
|
|
1370
1406
|
}]));
|
|
1371
1407
|
}
|
|
1372
1408
|
/**
|
|
@@ -1883,11 +1919,11 @@ const typeGenerator = defineGenerator({
|
|
|
1883
1919
|
});
|
|
1884
1920
|
// kubb-extension.json
|
|
1885
1921
|
var compatibility = {
|
|
1886
|
-
"kubb": ">=5.
|
|
1922
|
+
"kubb": ">=5.16.0",
|
|
1887
1923
|
"node": ">=22.22"
|
|
1888
1924
|
};
|
|
1889
1925
|
// package.json
|
|
1890
|
-
var version = "5.4.
|
|
1926
|
+
var version = "5.4.1";
|
|
1891
1927
|
// src/resolvers/resolverTs.ts
|
|
1892
1928
|
/**
|
|
1893
1929
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|