@kubb/plugin-ts 5.0.0-beta.81 → 5.0.0-beta.84
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 +66 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +17 -18
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "kubb/kit";
|
|
3
|
+
import { KubbReactNode } from "kubb/jsx";
|
|
2
4
|
import ts from "typescript";
|
|
3
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
4
|
-
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
5
|
-
import { OperationNode } from "@kubb/ast";
|
|
6
5
|
|
|
7
6
|
//#region ../../internals/shared/src/operation.d.ts
|
|
8
7
|
/**
|
|
@@ -545,7 +544,7 @@ declare function Type({
|
|
|
545
544
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
546
545
|
* TypeScript output is produced.
|
|
547
546
|
*/
|
|
548
|
-
declare const typeGenerator: import("
|
|
547
|
+
declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
549
548
|
//#endregion
|
|
550
549
|
//#region src/plugin.d.ts
|
|
551
550
|
/**
|
|
@@ -561,7 +560,7 @@ declare const pluginTsName = "plugin-ts";
|
|
|
561
560
|
*
|
|
562
561
|
* @example
|
|
563
562
|
* ```ts
|
|
564
|
-
* import { defineConfig } from 'kubb'
|
|
563
|
+
* import { defineConfig } from 'kubb/config'
|
|
565
564
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
566
565
|
*
|
|
567
566
|
* export default defineConfig({
|
|
@@ -577,7 +576,7 @@ declare const pluginTsName = "plugin-ts";
|
|
|
577
576
|
* })
|
|
578
577
|
* ```
|
|
579
578
|
*/
|
|
580
|
-
declare const pluginTs: (options?: Options | undefined) => import("
|
|
579
|
+
declare const pluginTs: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginTs>;
|
|
581
580
|
//#endregion
|
|
582
581
|
//#region src/printers/functionParams.d.ts
|
|
583
582
|
/**
|
|
@@ -923,7 +922,7 @@ type CreateOperationParamsOptions = {
|
|
|
923
922
|
* `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
|
|
924
923
|
* name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
|
|
925
924
|
*/
|
|
926
|
-
declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
925
|
+
declare function createOperationParams(node: ast.OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
927
926
|
//#endregion
|
|
928
927
|
//#region src/resolvers/resolverTs.d.ts
|
|
929
928
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
|
|
3
3
|
import { parserTs } from "@kubb/parser-ts";
|
|
4
|
-
import { File, jsxRenderer } from "
|
|
4
|
+
import { File, jsxRenderer } from "kubb/jsx";
|
|
5
5
|
import ts from "typescript";
|
|
6
|
-
import { Fragment, jsx, jsxs } from "
|
|
7
|
-
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
8
7
|
//#region ../../internals/utils/src/casing.ts
|
|
9
8
|
/**
|
|
10
9
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -756,7 +755,7 @@ function buildTupleNode(node, print) {
|
|
|
756
755
|
*/
|
|
757
756
|
function buildPropertyType(schema, baseType, optionalType, optional) {
|
|
758
757
|
const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
|
|
759
|
-
const meta = syncSchemaRef(schema);
|
|
758
|
+
const meta = ast.syncSchemaRef(schema);
|
|
760
759
|
let type = baseType;
|
|
761
760
|
if (meta.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
|
|
762
761
|
if ((optional || meta.nullish || meta.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
|
|
@@ -827,10 +826,10 @@ function Enum({ node, enum: enumOptions, resolver }) {
|
|
|
827
826
|
name: enumName,
|
|
828
827
|
typeName,
|
|
829
828
|
enums: node.namedEnumValues?.map((v) => [
|
|
830
|
-
trimQuotes(v.name.toString()),
|
|
829
|
+
ast.trimQuotes(v.name.toString()),
|
|
831
830
|
v.value,
|
|
832
831
|
v.description
|
|
833
|
-
]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
|
|
832
|
+
]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [ast.trimQuotes(v.toString()), v]) ?? [],
|
|
834
833
|
type: enumOptions.type,
|
|
835
834
|
enumKeyCasing: enumOptions.keyCasing
|
|
836
835
|
});
|
|
@@ -1002,19 +1001,19 @@ function isSchemaOptional(schema) {
|
|
|
1002
1001
|
return Boolean("optional" in schema && schema.optional || "nullish" in schema && schema.nullish);
|
|
1003
1002
|
}
|
|
1004
1003
|
function buildPropertyJSDocComments(schema, optional) {
|
|
1005
|
-
const meta = syncSchemaRef(schema);
|
|
1004
|
+
const meta = ast.syncSchemaRef(schema);
|
|
1006
1005
|
const isArray = meta?.primitive === "array";
|
|
1007
1006
|
const hasDescription = meta && "description" in meta && meta.description;
|
|
1008
1007
|
const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
|
|
1009
1008
|
const exampleValues = meta?.examples ?? [];
|
|
1010
1009
|
return [
|
|
1011
|
-
hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
|
|
1010
|
+
hasDescription ? `@description ${ast.jsStringEscape(meta.description)}` : null,
|
|
1012
1011
|
...formatComment,
|
|
1013
1012
|
meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
|
|
1014
1013
|
!isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
|
|
1015
1014
|
!isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
|
|
1016
1015
|
meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
|
|
1017
|
-
meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" ? stringify(meta.default) : meta.default}` : null,
|
|
1016
|
+
meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" ? ast.stringify(meta.default) : meta.default}` : null,
|
|
1018
1017
|
...exampleValues.map((example) => `@example ${example}`),
|
|
1019
1018
|
meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null
|
|
1020
1019
|
].filter(Boolean);
|
|
@@ -1248,7 +1247,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1248
1247
|
time: dateOrStringNode,
|
|
1249
1248
|
ref(node) {
|
|
1250
1249
|
if (!node.name) return null;
|
|
1251
|
-
const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? extractRefName(node.ref) ?? node.name : node.name;
|
|
1250
|
+
const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
1252
1251
|
return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.resolveEnumKeyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.resolveTypeName(refName) : refName, void 0);
|
|
1253
1252
|
},
|
|
1254
1253
|
enum(node) {
|
|
@@ -1264,11 +1263,11 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1264
1263
|
const hasStringLiteral = members.some((m) => {
|
|
1265
1264
|
return ast.narrowSchema(m, ast.schemaTypes.enum)?.primitive === "string";
|
|
1266
1265
|
});
|
|
1267
|
-
const hasPlainString = members.some((m) => isStringType(m));
|
|
1266
|
+
const hasPlainString = members.some((m) => ast.isStringType(m));
|
|
1268
1267
|
if (hasStringLiteral && hasPlainString) return createUnionDeclaration({
|
|
1269
1268
|
withParentheses: true,
|
|
1270
1269
|
nodes: members.map((m) => {
|
|
1271
|
-
if (isStringType(m)) return createIntersectionDeclaration({
|
|
1270
|
+
if (ast.isStringType(m)) return createIntersectionDeclaration({
|
|
1272
1271
|
nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
|
|
1273
1272
|
withParentheses: true
|
|
1274
1273
|
});
|
|
@@ -1288,7 +1287,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1288
1287
|
},
|
|
1289
1288
|
array(node) {
|
|
1290
1289
|
return createArrayDeclaration({
|
|
1291
|
-
nodes: mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(isNonNullable),
|
|
1290
|
+
nodes: ast.mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(isNonNullable),
|
|
1292
1291
|
arrayType: this.options.arrayType
|
|
1293
1292
|
}) ?? null;
|
|
1294
1293
|
},
|
|
@@ -1298,11 +1297,11 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1298
1297
|
object(node) {
|
|
1299
1298
|
const { transform, options } = this;
|
|
1300
1299
|
const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options.optionalType);
|
|
1301
|
-
const propertyNodes = mapSchemaProperties(node, (schema) => transform(schema)).map(({ name, property, output }) => {
|
|
1300
|
+
const propertyNodes = ast.mapSchemaProperties(node, (schema) => transform(schema)).map(({ name, property, output }) => {
|
|
1302
1301
|
const baseType = output ?? keywordTypeNodes.unknown;
|
|
1303
1302
|
const optional = !property.required || !!property.schema.optional || !!property.schema.nullish;
|
|
1304
1303
|
const type = buildPropertyType(property.schema, baseType, options.optionalType, optional);
|
|
1305
|
-
const propMeta = syncSchemaRef(property.schema);
|
|
1304
|
+
const propMeta = ast.syncSchemaRef(property.schema);
|
|
1306
1305
|
return appendJSDocToNode({
|
|
1307
1306
|
node: createPropertySignature({
|
|
1308
1307
|
questionToken: optional ? addsQuestionToken : false,
|
|
@@ -1323,7 +1322,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1323
1322
|
const { name, syntaxType = "type", description, keysToOmit } = this.options;
|
|
1324
1323
|
const transformed = this.transform(node);
|
|
1325
1324
|
if (!transformed) return null;
|
|
1326
|
-
const meta = syncSchemaRef(node);
|
|
1325
|
+
const meta = ast.syncSchemaRef(node);
|
|
1327
1326
|
if (!name) {
|
|
1328
1327
|
const withNullable = meta.nullable ? createUnionDeclaration({ nodes: [transformed, keywordTypeNodes.null] }) : transformed;
|
|
1329
1328
|
const result = (meta.nullish || meta.optional) && addsUndefined ? createUnionDeclaration({ nodes: [withNullable, keywordTypeNodes.undefined] }) : withNullable;
|
|
@@ -1712,7 +1711,7 @@ const pluginTsName = "plugin-ts";
|
|
|
1712
1711
|
*
|
|
1713
1712
|
* @example
|
|
1714
1713
|
* ```ts
|
|
1715
|
-
* import { defineConfig } from 'kubb'
|
|
1714
|
+
* import { defineConfig } from 'kubb/config'
|
|
1716
1715
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1717
1716
|
*
|
|
1718
1717
|
* export default defineConfig({
|