@kubb/plugin-ts 5.0.5 → 5.0.7

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.d.ts CHANGED
@@ -298,7 +298,6 @@ type EnumOptions$1 = {
298
298
  * site (`'inlineLiteral'`).
299
299
  *
300
300
  * @default 'asConst'
301
- * @note In Kubb v5, 'inlineLiteral' becomes the default.
302
301
  */
303
302
  type?: 'literal' | 'inlineLiteral';
304
303
  /**
@@ -512,7 +511,7 @@ export declare const pluginTsName = "plugin-ts";
512
511
  * })
513
512
  * ```
514
513
  */
515
- export declare const pluginTs: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginTs>;
514
+ export declare const pluginTs: import("kubb/kit").PluginFactory<PluginTs>;
516
515
  //#endregion
517
516
  //#region src/printers/functionParams.d.ts
518
517
  /**
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { n as __name, t as __exportAll } from "./rolldown-runtime-CthDji9g.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { parserTs } from "@kubb/parser-ts";
4
4
  import { File, jsxRenderer } from "kubb/jsx";
5
- import { Resolver, ast, createResolver, defineGenerator, definePlugin, isStringType, syncSchemaRef } from "kubb/kit";
5
+ import { Resolver, addGenerator, assertPluginOption, ast, createResolver, defineGenerator, definePlugin, isStringType, setMacros, setResolver, syncSchemaRef } from "kubb/kit";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
7
7
  //#region ../../internals/utils/src/casing.ts
8
8
  /**
@@ -1317,7 +1317,7 @@ function buildPropertyJSDocComments(schema, optional) {
1317
1317
  !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
1318
1318
  !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
1319
1319
  meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
1320
- meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
1320
+ meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : formatExample(meta.default)}` : null,
1321
1321
  ...exampleValues.map((example) => `@example ${formatExample(example)}`)
1322
1322
  ].filter(Boolean);
1323
1323
  const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
@@ -1831,6 +1831,9 @@ const typeGenerator = defineGenerator({
1831
1831
  }
1832
1832
  });
1833
1833
  //#endregion
1834
+ //#region package.json
1835
+ var version = "5.0.7";
1836
+ //#endregion
1834
1837
  //#region src/resolvers/resolverTs.ts
1835
1838
  /**
1836
1839
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
@@ -1875,6 +1878,53 @@ const resolverTs = createResolver({
1875
1878
  * cross-plugin dependency references.
1876
1879
  */
1877
1880
  const pluginTsName = "plugin-ts";
1881
+ const allowedEnumTypes = [
1882
+ "asConst",
1883
+ "enum",
1884
+ "constEnum",
1885
+ "literal",
1886
+ "inlineLiteral"
1887
+ ];
1888
+ const allowedSyntaxTypes = ["type", "interface"];
1889
+ const allowedArrayTypes = ["array", "generic"];
1890
+ const allowedOptionalTypes = [
1891
+ "questionToken",
1892
+ "undefined",
1893
+ "questionTokenAndUndefined"
1894
+ ];
1895
+ /**
1896
+ * Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
1897
+ */
1898
+ function assertEnumLikeOptions({ prefix, options }) {
1899
+ const checks = [
1900
+ {
1901
+ option: "enum.type",
1902
+ value: options.enum?.type,
1903
+ allowed: allowedEnumTypes
1904
+ },
1905
+ {
1906
+ option: "syntaxType",
1907
+ value: options.syntaxType,
1908
+ allowed: allowedSyntaxTypes
1909
+ },
1910
+ {
1911
+ option: "arrayType",
1912
+ value: options.arrayType,
1913
+ allowed: allowedArrayTypes
1914
+ },
1915
+ {
1916
+ option: "optionalType",
1917
+ value: options.optionalType,
1918
+ allowed: allowedOptionalTypes
1919
+ }
1920
+ ];
1921
+ for (const { option, value, allowed } of checks) if (value !== void 0) assertPluginOption({
1922
+ plugin: pluginTsName,
1923
+ option: `${prefix}${option}`,
1924
+ value,
1925
+ allowed
1926
+ });
1927
+ }
1878
1928
  /**
1879
1929
  * Generates TypeScript `type` aliases and `interface` declarations from an
1880
1930
  * OpenAPI spec. The foundation that every other Kubb plugin builds on:
@@ -1899,39 +1949,52 @@ const pluginTsName = "plugin-ts";
1899
1949
  * })
1900
1950
  * ```
1901
1951
  */
1902
- const pluginTs = definePlugin((options) => {
1903
- const { output = {
1904
- path: "types",
1905
- barrel: { type: "named" }
1906
- }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
1907
- const groupConfig = createGroupConfig(group);
1908
- const resolvedEnum = {
1909
- type: enumOptions.type ?? "asConst",
1910
- constCasing: enumOptions.constCasing ?? "camelCase",
1911
- typeSuffix: enumOptions.typeSuffix ?? "Key",
1912
- keyCasing: enumOptions.keyCasing ?? "none"
1913
- };
1914
- return {
1952
+ const pluginTs = definePlugin({
1953
+ meta: {
1915
1954
  name: pluginTsName,
1916
- options,
1917
- hooks: { "kubb:plugin:setup"(ctx) {
1918
- ctx.setOptions({
1919
- output,
1920
- exclude,
1921
- include,
1922
- override,
1923
- optionalType,
1924
- group: groupConfig,
1925
- arrayType,
1955
+ version,
1956
+ compatibility: { kubb: ">=5.8.0" }
1957
+ },
1958
+ setup(options) {
1959
+ const { output = {
1960
+ path: "types",
1961
+ barrel: { type: "named" }
1962
+ }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
1963
+ const resolvedEnum = {
1964
+ type: enumOptions.type ?? "asConst",
1965
+ constCasing: enumOptions.constCasing ?? "camelCase",
1966
+ typeSuffix: enumOptions.typeSuffix ?? "Key",
1967
+ keyCasing: enumOptions.keyCasing ?? "none"
1968
+ };
1969
+ assertEnumLikeOptions({
1970
+ prefix: "",
1971
+ options: {
1926
1972
  enum: resolvedEnum,
1927
1973
  syntaxType,
1928
- printer
1929
- });
1930
- ctx.setResolver(userResolver ? Resolver.merge(resolverTs, userResolver) : resolverTs);
1931
- if (userMacros?.length) ctx.setMacros(userMacros);
1932
- ctx.addGenerator(typeGenerator);
1933
- } }
1934
- };
1974
+ arrayType,
1975
+ optionalType
1976
+ }
1977
+ });
1978
+ for (const [index, entry] of override.entries()) assertEnumLikeOptions({
1979
+ prefix: `override[${index}].options.`,
1980
+ options: entry.options
1981
+ });
1982
+ setResolver(userResolver ? Resolver.merge(resolverTs, userResolver) : resolverTs);
1983
+ if (userMacros?.length) setMacros(userMacros);
1984
+ addGenerator(typeGenerator);
1985
+ return {
1986
+ output,
1987
+ exclude,
1988
+ include,
1989
+ override,
1990
+ optionalType,
1991
+ group: createGroupConfig(group),
1992
+ arrayType,
1993
+ enum: resolvedEnum,
1994
+ syntaxType,
1995
+ printer
1996
+ };
1997
+ }
1935
1998
  });
1936
1999
  //#endregion
1937
2000
  //#region src/printers/functionParams.ts