@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.42",
|
|
4
4
|
"description": "Generate TypeScript types, interfaces, and enums from your OpenAPI specification. The foundational plugin that powers type safety across the entire Kubb ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -46,10 +46,9 @@
|
|
|
46
46
|
"registry": "https://registry.npmjs.org/"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@kubb/core": "5.0.0-beta.
|
|
50
|
-
"@kubb/parser-ts": "5.0.0-beta.
|
|
51
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
52
|
-
"remeda": "^2.37.0",
|
|
49
|
+
"@kubb/core": "5.0.0-beta.42",
|
|
50
|
+
"@kubb/parser-ts": "5.0.0-beta.42",
|
|
51
|
+
"@kubb/renderer-jsx": "5.0.0-beta.42",
|
|
53
52
|
"typescript": "^6.0.3"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
"@internals/utils": "0.0.0"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
59
|
+
"@kubb/renderer-jsx": "5.0.0-beta.42"
|
|
61
60
|
},
|
|
62
61
|
"size-limit": [
|
|
63
62
|
{
|
package/src/factory.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { camelCase, pascalCase, screamingSnakeCase, snakeCase } from '@internals/utils'
|
|
2
2
|
import { ast } from '@kubb/core'
|
|
3
|
-
import { isNumber, sortBy } from 'remeda'
|
|
4
3
|
import ts from 'typescript'
|
|
5
4
|
import { OPTIONAL_ADDS_UNDEFINED } from './constants.ts'
|
|
6
5
|
|
|
7
6
|
const { SyntaxKind, factory } = ts
|
|
8
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Compares two strings by UTF-16 code unit, keeping sorted output identical across platforms
|
|
10
|
+
* regardless of locale.
|
|
11
|
+
*/
|
|
12
|
+
function compareStrings(a: string, b: string): number {
|
|
13
|
+
if (a < b) return -1
|
|
14
|
+
if (a > b) return 1
|
|
15
|
+
return 0
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isNumber(value: unknown): value is number {
|
|
19
|
+
return typeof value === 'number' && !Number.isNaN(value)
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
// https://ts-ast-viewer.com/
|
|
10
23
|
|
|
11
24
|
/**
|
|
@@ -35,9 +48,22 @@ function isValidIdentifier(str: string): boolean {
|
|
|
35
48
|
if (!str.length || str.trim() !== str) {
|
|
36
49
|
return false
|
|
37
50
|
}
|
|
38
|
-
const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)
|
|
39
51
|
|
|
40
|
-
|
|
52
|
+
// Mirrors `ts.isIdentifierText`, which is not in the public type declarations.
|
|
53
|
+
// Walking by code point with `isIdentifierStart`/`isIdentifierPart` rejects
|
|
54
|
+
// invalid names such as private identifiers (`#FOO`), forcing `propertyName`
|
|
55
|
+
// to quote them.
|
|
56
|
+
let ch = str.codePointAt(0)!
|
|
57
|
+
if (!ts.isIdentifierStart(ch, ts.ScriptTarget.Latest)) {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
for (let i = ch > 0xffff ? 2 : 1; i < str.length; i += ch > 0xffff ? 2 : 1) {
|
|
61
|
+
ch = str.codePointAt(i)!
|
|
62
|
+
if (!ts.isIdentifierPart(ch, ts.ScriptTarget.Latest)) {
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
function propertyName(name: string | ts.PropertyName): ts.PropertyName {
|
|
@@ -384,7 +410,7 @@ export function createImportDeclaration({
|
|
|
384
410
|
}
|
|
385
411
|
|
|
386
412
|
// Sort the imports alphabetically for consistent output across platforms
|
|
387
|
-
const sortedName =
|
|
413
|
+
const sortedName = name.toSorted((a, b) => compareStrings(typeof a === 'object' ? a.propertyName : a, typeof b === 'object' ? b.propertyName : b))
|
|
388
414
|
|
|
389
415
|
return factory.createImportDeclaration(
|
|
390
416
|
undefined,
|
|
@@ -443,7 +469,7 @@ export function createExportDeclaration({
|
|
|
443
469
|
}
|
|
444
470
|
|
|
445
471
|
// Sort the exports alphabetically for consistent output across platforms
|
|
446
|
-
const sortedName =
|
|
472
|
+
const sortedName = name.toSorted((a, b) => compareStrings(typeof a === 'string' ? a : a.text, typeof b === 'string' ? b : b.text))
|
|
447
473
|
|
|
448
474
|
return factory.createExportDeclaration(
|
|
449
475
|
undefined,
|
|
@@ -64,11 +64,11 @@ function rank(param: ast.FunctionParameterNode | ast.ParameterGroupNode): number
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function sortParams(params: ReadonlyArray<ast.FunctionParameterNode | ast.ParameterGroupNode>): Array<ast.FunctionParameterNode | ast.ParameterGroupNode> {
|
|
67
|
-
return
|
|
67
|
+
return params.toSorted((a, b) => rank(a) - rank(b))
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function sortChildParams(params: Array<ast.FunctionParameterNode>): Array<ast.FunctionParameterNode> {
|
|
71
|
-
return
|
|
71
|
+
return params.toSorted((a, b) => rank(a) - rank(b))
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|