@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.
Files changed (78) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +50 -27
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
  5. package/dist/factory-Cl8Z7mcc.cjs +299 -0
  6. package/dist/factory-Cl8Z7mcc.cjs.map +1 -0
  7. package/dist/factory-Du7nEP4B.js +282 -0
  8. package/dist/factory-Du7nEP4B.js.map +1 -0
  9. package/dist/factory.cjs +29 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index-BzjwdK2M.d.ts +2433 -0
  13. package/dist/index.cjs +442 -2180
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +93 -3408
  16. package/dist/index.js +392 -2101
  17. package/dist/index.js.map +1 -1
  18. package/dist/operationParams-BZ07xDm0.d.ts +204 -0
  19. package/dist/response-DKxTr522.js +683 -0
  20. package/dist/response-DKxTr522.js.map +1 -0
  21. package/dist/response-DS5S3IG4.cjs +1058 -0
  22. package/dist/response-DS5S3IG4.cjs.map +1 -0
  23. package/dist/types-olVl9v5p.d.ts +764 -0
  24. package/dist/types.cjs +0 -0
  25. package/dist/types.d.ts +5 -0
  26. package/dist/types.js +1 -0
  27. package/dist/utils-D83JA6Xx.cjs +1645 -0
  28. package/dist/utils-D83JA6Xx.cjs.map +1 -0
  29. package/dist/utils-Dj_KoXMv.js +1389 -0
  30. package/dist/utils-Dj_KoXMv.js.map +1 -0
  31. package/dist/utils.cjs +34 -0
  32. package/dist/utils.d.ts +332 -0
  33. package/dist/utils.js +3 -0
  34. package/package.json +17 -6
  35. package/src/constants.ts +19 -64
  36. package/src/dedupe.ts +239 -0
  37. package/src/dialect.ts +53 -0
  38. package/src/factory.ts +67 -678
  39. package/src/guards.ts +10 -92
  40. package/src/index.ts +16 -43
  41. package/src/infer.ts +16 -14
  42. package/src/mocks.ts +7 -127
  43. package/src/node.ts +128 -0
  44. package/src/nodes/base.ts +5 -12
  45. package/src/nodes/code.ts +165 -74
  46. package/src/nodes/content.ts +56 -0
  47. package/src/nodes/file.ts +97 -36
  48. package/src/nodes/function.ts +216 -156
  49. package/src/nodes/http.ts +1 -35
  50. package/src/nodes/index.ts +23 -15
  51. package/src/nodes/input.ts +140 -0
  52. package/src/nodes/operation.ts +122 -68
  53. package/src/nodes/output.ts +23 -0
  54. package/src/nodes/parameter.ts +33 -3
  55. package/src/nodes/property.ts +36 -3
  56. package/src/nodes/requestBody.ts +61 -0
  57. package/src/nodes/response.ts +58 -13
  58. package/src/nodes/schema.ts +93 -17
  59. package/src/printer.ts +48 -42
  60. package/src/registry.ts +75 -0
  61. package/src/signature.ts +207 -0
  62. package/src/transformers.ts +50 -18
  63. package/src/types.ts +7 -68
  64. package/src/utils/codegen.ts +104 -0
  65. package/src/utils/extractStringsFromNodes.ts +34 -0
  66. package/src/utils/fileMerge.ts +184 -0
  67. package/src/utils/index.ts +11 -0
  68. package/src/utils/operationParams.ts +353 -0
  69. package/src/utils/refs.ts +112 -0
  70. package/src/utils/schemaGraph.ts +169 -0
  71. package/src/utils/schemaTraversal.ts +86 -0
  72. package/src/utils/strings.ts +139 -0
  73. package/src/visitor.ts +227 -289
  74. package/dist/chunk--u3MIqq1.js +0 -8
  75. package/src/nodes/root.ts +0 -64
  76. package/src/refs.ts +0 -67
  77. package/src/resolvers.ts +0 -45
  78. 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
- }