@kubb/plugin-ts 5.0.0-beta.36 → 5.0.0-beta.42
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/README.md +11 -15
- package/dist/index.cjs +16 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/src/factory.ts +31 -5
- package/src/printers/functionPrinter.ts +2 -2
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
7
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
8
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
9
9
|
[![License][license-src]][license-href]
|
|
10
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
11
11
|
|
|
12
12
|
<h4>
|
|
13
13
|
<a href="https://kubb.dev/plugins/ts" target="_blank">Documentation</a>
|
|
@@ -58,17 +58,13 @@ Kubb is an open source project, and its development is funded entirely by sponso
|
|
|
58
58
|
|
|
59
59
|
<!-- Badges -->
|
|
60
60
|
|
|
61
|
-
[npm-version-src]: https://
|
|
62
|
-
[npm-version-href]: https://
|
|
63
|
-
[npm-downloads-src]: https://
|
|
64
|
-
[npm-downloads-href]: https://
|
|
65
|
-
[
|
|
61
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
62
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/plugin-ts
|
|
63
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
64
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-ts
|
|
65
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
66
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
67
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc
|
|
66
68
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-ts?style=flat&colorA=18181B&colorB=f58517
|
|
70
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-ts
|
|
71
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
72
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-ts
|
|
73
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
74
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
69
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
70
|
+
[node-href]: https://npmx.dev/package/@kubb/plugin-ts
|
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
let _kubb_parser_ts = require("@kubb/parser-ts");
|
|
32
32
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
33
33
|
let _kubb_core = require("@kubb/core");
|
|
34
|
-
let remeda = require("remeda");
|
|
35
34
|
let typescript = require("typescript");
|
|
36
35
|
typescript = __toESM(typescript, 1);
|
|
37
36
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
@@ -339,6 +338,9 @@ const PARAM_RANK = {
|
|
|
339
338
|
//#endregion
|
|
340
339
|
//#region src/factory.ts
|
|
341
340
|
const { SyntaxKind, factory } = typescript.default;
|
|
341
|
+
function isNumber(value) {
|
|
342
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
343
|
+
}
|
|
342
344
|
/**
|
|
343
345
|
* TypeScript AST modifiers for common keywords (async, export, const, static).
|
|
344
346
|
*/
|
|
@@ -362,8 +364,13 @@ function isNonNullable$1(value) {
|
|
|
362
364
|
__name(isNonNullable$1, "isNonNullable");
|
|
363
365
|
function isValidIdentifier(str) {
|
|
364
366
|
if (!str.length || str.trim() !== str) return false;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
+
let ch = str.codePointAt(0);
|
|
368
|
+
if (!typescript.default.isIdentifierStart(ch, typescript.default.ScriptTarget.Latest)) return false;
|
|
369
|
+
for (let i = ch > 65535 ? 2 : 1; i < str.length; i += ch > 65535 ? 2 : 1) {
|
|
370
|
+
ch = str.codePointAt(i);
|
|
371
|
+
if (!typescript.default.isIdentifierPart(ch, typescript.default.ScriptTarget.Latest)) return false;
|
|
372
|
+
}
|
|
373
|
+
return true;
|
|
367
374
|
}
|
|
368
375
|
function propertyName(name) {
|
|
369
376
|
if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
|
|
@@ -521,7 +528,7 @@ function applyEnumKeyCasing(key, casing = "none") {
|
|
|
521
528
|
*/
|
|
522
529
|
function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCasing = "none" }) {
|
|
523
530
|
if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
|
|
524
|
-
if (
|
|
531
|
+
if (isNumber(value)) {
|
|
525
532
|
if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
|
|
526
533
|
return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
|
|
527
534
|
}
|
|
@@ -530,10 +537,10 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
530
537
|
}).filter((node) => node !== void 0)))];
|
|
531
538
|
if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value]) => {
|
|
532
539
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
533
|
-
if (Number.parseInt(value.toString(), 10) === value &&
|
|
540
|
+
if (Number.parseInt(value.toString(), 10) === value && isNumber(Number.parseInt(value.toString(), 10))) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
534
541
|
else initializer = factory.createNumericLiteral(value);
|
|
535
542
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
536
|
-
if (
|
|
543
|
+
if (isNumber(Number.parseInt(key.toString(), 10))) {
|
|
537
544
|
const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
|
|
538
545
|
return factory.createEnumMember(propertyName(casingKey), initializer);
|
|
539
546
|
}
|
|
@@ -546,7 +553,7 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
546
553
|
if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
|
|
547
554
|
return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value]) => {
|
|
548
555
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
549
|
-
if (
|
|
556
|
+
if (isNumber(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
550
557
|
else initializer = factory.createNumericLiteral(value);
|
|
551
558
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
552
559
|
if (key) {
|
|
@@ -1653,10 +1660,10 @@ function rank(param) {
|
|
|
1653
1660
|
return param.optional ? PARAM_RANK.optional : PARAM_RANK.required;
|
|
1654
1661
|
}
|
|
1655
1662
|
function sortParams(params) {
|
|
1656
|
-
return
|
|
1663
|
+
return params.toSorted((a, b) => rank(a) - rank(b));
|
|
1657
1664
|
}
|
|
1658
1665
|
function sortChildParams(params) {
|
|
1659
|
-
return
|
|
1666
|
+
return params.toSorted((a, b) => rank(a) - rank(b));
|
|
1660
1667
|
}
|
|
1661
1668
|
/**
|
|
1662
1669
|
* Default function-signature printer.
|