@kubb/ast 5.0.0-beta.6 → 5.0.0-beta.60
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/LICENSE +17 -10
- package/README.md +50 -27
- package/dist/chunk-CNktS9qV.js +17 -0
- package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
- package/dist/factory-Cl8Z7mcc.cjs +299 -0
- package/dist/factory-Cl8Z7mcc.cjs.map +1 -0
- package/dist/factory-Du7nEP4B.js +282 -0
- package/dist/factory-Du7nEP4B.js.map +1 -0
- package/dist/factory.cjs +29 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.js +3 -0
- package/dist/index-BzjwdK2M.d.ts +2433 -0
- package/dist/index.cjs +442 -2180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +93 -3408
- package/dist/index.js +392 -2101
- package/dist/index.js.map +1 -1
- package/dist/operationParams-BZ07xDm0.d.ts +204 -0
- package/dist/response-DKxTr522.js +683 -0
- package/dist/response-DKxTr522.js.map +1 -0
- package/dist/response-DS5S3IG4.cjs +1058 -0
- package/dist/response-DS5S3IG4.cjs.map +1 -0
- package/dist/types-olVl9v5p.d.ts +764 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +1 -0
- package/dist/utils-D83JA6Xx.cjs +1645 -0
- package/dist/utils-D83JA6Xx.cjs.map +1 -0
- package/dist/utils-Dj_KoXMv.js +1389 -0
- package/dist/utils-Dj_KoXMv.js.map +1 -0
- package/dist/utils.cjs +34 -0
- package/dist/utils.d.ts +332 -0
- package/dist/utils.js +3 -0
- package/package.json +17 -6
- package/src/constants.ts +19 -64
- package/src/dedupe.ts +239 -0
- package/src/dialect.ts +53 -0
- package/src/factory.ts +67 -678
- package/src/guards.ts +10 -92
- package/src/index.ts +16 -43
- package/src/infer.ts +16 -14
- package/src/mocks.ts +7 -127
- package/src/node.ts +128 -0
- package/src/nodes/base.ts +5 -12
- package/src/nodes/code.ts +165 -74
- package/src/nodes/content.ts +56 -0
- package/src/nodes/file.ts +97 -36
- package/src/nodes/function.ts +216 -156
- package/src/nodes/http.ts +1 -35
- package/src/nodes/index.ts +23 -15
- package/src/nodes/input.ts +140 -0
- package/src/nodes/operation.ts +122 -68
- package/src/nodes/output.ts +23 -0
- package/src/nodes/parameter.ts +33 -3
- package/src/nodes/property.ts +36 -3
- package/src/nodes/requestBody.ts +61 -0
- package/src/nodes/response.ts +58 -13
- package/src/nodes/schema.ts +93 -17
- package/src/printer.ts +48 -42
- package/src/registry.ts +75 -0
- package/src/signature.ts +207 -0
- package/src/transformers.ts +50 -18
- package/src/types.ts +7 -68
- package/src/utils/codegen.ts +104 -0
- package/src/utils/extractStringsFromNodes.ts +34 -0
- package/src/utils/fileMerge.ts +184 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/operationParams.ts +353 -0
- package/src/utils/refs.ts +112 -0
- package/src/utils/schemaGraph.ts +169 -0
- package/src/utils/schemaTraversal.ts +86 -0
- package/src/utils/strings.ts +139 -0
- package/src/visitor.ts +227 -289
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/nodes/root.ts +0 -64
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/utils.ts +0 -915
package/src/nodes/root.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { BaseNode } from './base.ts'
|
|
2
|
-
import type { OperationNode } from './operation.ts'
|
|
3
|
-
import type { SchemaNode } from './schema.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Basic metadata for an API document.
|
|
7
|
-
* Adapters fill fields that exist in their source format.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const meta: InputMeta = { title: 'Pet API', version: '1.0.0' }
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export type InputMeta = {
|
|
15
|
-
/**
|
|
16
|
-
* API title (from `info.title` in OAS/AsyncAPI).
|
|
17
|
-
*/
|
|
18
|
-
title?: string
|
|
19
|
-
/**
|
|
20
|
-
* API description (from `info.description` in OAS/AsyncAPI).
|
|
21
|
-
*/
|
|
22
|
-
description?: string
|
|
23
|
-
/**
|
|
24
|
-
* API version string (from `info.version` in OAS/AsyncAPI).
|
|
25
|
-
*/
|
|
26
|
-
version?: string
|
|
27
|
-
/**
|
|
28
|
-
* Resolved API base URL.
|
|
29
|
-
* For OpenAPI and AsyncAPI, this comes from the selected server URL.
|
|
30
|
-
*/
|
|
31
|
-
baseURL?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Input AST node that contains all schemas and operations for one API document.
|
|
36
|
-
* Produced by the adapter and consumed by all Kubb plugins.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* const input: InputNode = {
|
|
41
|
-
* kind: 'Input',
|
|
42
|
-
* schemas: [],
|
|
43
|
-
* operations: [],
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export type InputNode = BaseNode & {
|
|
48
|
-
/**
|
|
49
|
-
* Node kind.
|
|
50
|
-
*/
|
|
51
|
-
kind: 'Input'
|
|
52
|
-
/**
|
|
53
|
-
* All schema nodes in the document.
|
|
54
|
-
*/
|
|
55
|
-
schemas: Array<SchemaNode>
|
|
56
|
-
/**
|
|
57
|
-
* All operation nodes in the document.
|
|
58
|
-
*/
|
|
59
|
-
operations: Array<OperationNode>
|
|
60
|
-
/**
|
|
61
|
-
* Optional document metadata populated by the adapter.
|
|
62
|
-
*/
|
|
63
|
-
meta?: InputMeta
|
|
64
|
-
}
|
package/src/refs.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { InputNode } from './nodes/root.ts'
|
|
2
|
-
import type { SchemaNode } from './nodes/schema.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Lookup map from schema name to `SchemaNode`.
|
|
6
|
-
*/
|
|
7
|
-
export type RefMap = Map<string, SchemaNode>
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Returns the last path segment of a reference string.
|
|
11
|
-
*
|
|
12
|
-
* Example: `#/components/schemas/Pet` becomes `Pet`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export function extractRefName(ref: string): string {
|
|
20
|
-
return ref.split('/').at(-1) ?? ref
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Builds a `RefMap` from `input.schemas` using each schema's `name`.
|
|
25
|
-
*
|
|
26
|
-
* Unnamed schemas are skipped.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const refMap = buildRefMap(input)
|
|
31
|
-
* const pet = refMap.get('Pet')
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export function buildRefMap(input: InputNode): RefMap {
|
|
35
|
-
const map: RefMap = new Map()
|
|
36
|
-
|
|
37
|
-
for (const schema of input.schemas) {
|
|
38
|
-
if (schema.name) {
|
|
39
|
-
map.set(schema.name, schema)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return map
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Resolves a schema by name from a `RefMap`.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const petSchema = resolveRef(refMap, 'Pet')
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined {
|
|
54
|
-
return refMap.get(ref)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Converts a `RefMap` into a plain object.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* const refsObject = refMapToObject(refMap)
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export function refMapToObject(refMap: RefMap): Record<string, SchemaNode> {
|
|
66
|
-
return Object.fromEntries(refMap)
|
|
67
|
-
}
|
package/src/resolvers.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from '@internals/utils'
|
|
2
|
-
import { narrowSchema } from './guards.ts'
|
|
3
|
-
import type { SchemaNode } from './nodes/schema.ts'
|
|
4
|
-
import { extractRefName } from './refs.ts'
|
|
5
|
-
import { collect } from './visitor.ts'
|
|
6
|
-
|
|
7
|
-
export function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null {
|
|
8
|
-
if (!mapping || !ref) return null
|
|
9
|
-
return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function childName(parentName: string | null | undefined, propName: string): string | null {
|
|
13
|
-
return parentName ? pascalCase([parentName, propName].join(' ')) : null
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {
|
|
17
|
-
return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Collects import entries for all `ref` schema nodes in `node`.
|
|
22
|
-
*/
|
|
23
|
-
export function collectImports<TImport>({
|
|
24
|
-
node,
|
|
25
|
-
nameMapping,
|
|
26
|
-
resolve,
|
|
27
|
-
}: {
|
|
28
|
-
node: SchemaNode
|
|
29
|
-
nameMapping: Map<string, string>
|
|
30
|
-
resolve: (schemaName: string) => TImport | undefined
|
|
31
|
-
}): Array<TImport> {
|
|
32
|
-
return collect<TImport>(node, {
|
|
33
|
-
schema(schemaNode): TImport | undefined {
|
|
34
|
-
const schemaRef = narrowSchema(schemaNode, 'ref')
|
|
35
|
-
if (!schemaRef?.ref) return
|
|
36
|
-
|
|
37
|
-
const rawName = extractRefName(schemaRef.ref)
|
|
38
|
-
const schemaName = nameMapping.get(rawName) ?? rawName
|
|
39
|
-
const result = resolve(schemaName)
|
|
40
|
-
if (!result) return
|
|
41
|
-
|
|
42
|
-
return result
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
}
|