@kubb/ast 5.0.0-beta.62 → 5.0.0-beta.64

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 (92) hide show
  1. package/dist/{defineMacro-CNkUpxia.js → defineMacro-B76LsJwO.js} +4 -4
  2. package/dist/defineMacro-B76LsJwO.js.map +1 -0
  3. package/dist/{defineMacro-Vw-xQvq7.d.ts → defineMacro-B7qm3zTd.d.ts} +5 -6
  4. package/dist/{defineMacro-BryDiuQl.cjs → defineMacro-CEZHaCXE.cjs} +5 -5
  5. package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
  6. package/dist/factory-wJLzHeXT.d.ts +27 -0
  7. package/dist/factory.cjs +56 -56
  8. package/dist/factory.cjs.map +1 -1
  9. package/dist/factory.d.ts +3 -27
  10. package/dist/factory.js +6 -6
  11. package/dist/factory.js.map +1 -1
  12. package/dist/{index-CTaN_ee_.d.ts → index-BKD4drsX.d.ts} +47 -114
  13. package/dist/index.cjs +193 -270
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +31 -21
  16. package/dist/index.js +154 -236
  17. package/dist/index.js.map +1 -1
  18. package/dist/macros.cjs +12 -12
  19. package/dist/macros.cjs.map +1 -1
  20. package/dist/macros.d.ts +3 -3
  21. package/dist/macros.js +5 -5
  22. package/dist/macros.js.map +1 -1
  23. package/dist/{operationParams-B44p6EQy.d.ts → operationParams-ByVfpYr7.d.ts} +10 -3
  24. package/dist/{visitor-DepQEKyp.js → refs-Dx6U5LoE.js} +116 -121
  25. package/dist/refs-Dx6U5LoE.js.map +1 -0
  26. package/dist/{visitor-B7Zlnp4c.cjs → refs-u5SDdyV7.cjs} +139 -144
  27. package/dist/refs-u5SDdyV7.cjs.map +1 -0
  28. package/dist/{response-BeG6hq2D.cjs → schema-BkvrrOAr.cjs} +171 -153
  29. package/dist/schema-BkvrrOAr.cjs.map +1 -0
  30. package/dist/{response-Rd1uisM1.js → schema-YNbOtTCM.js} +167 -155
  31. package/dist/schema-YNbOtTCM.js.map +1 -0
  32. package/dist/{types-DQTgVSwE.d.ts → types-BP9BZoq-.d.ts} +56 -80
  33. package/dist/types.d.ts +5 -5
  34. package/dist/{utils-DW9rnfsD.js → utils-BJi0y-xg.js} +57 -50
  35. package/dist/utils-BJi0y-xg.js.map +1 -0
  36. package/dist/{utils-BDI3kXlb.cjs → utils-CEepwqmb.cjs} +74 -67
  37. package/dist/utils-CEepwqmb.cjs.map +1 -0
  38. package/dist/utils.cjs +11 -11
  39. package/dist/utils.d.ts +45 -30
  40. package/dist/utils.js +3 -3
  41. package/package.json +1 -2
  42. package/dist/defineMacro-BryDiuQl.cjs.map +0 -1
  43. package/dist/defineMacro-CNkUpxia.js.map +0 -1
  44. package/dist/response-BeG6hq2D.cjs.map +0 -1
  45. package/dist/response-Rd1uisM1.js.map +0 -1
  46. package/dist/utils-BDI3kXlb.cjs.map +0 -1
  47. package/dist/utils-DW9rnfsD.js.map +0 -1
  48. package/dist/visitor-B7Zlnp4c.cjs.map +0 -1
  49. package/dist/visitor-DepQEKyp.js.map +0 -1
  50. package/src/constants.ts +0 -153
  51. package/src/dedupe.ts +0 -231
  52. package/src/defineMacro.ts +0 -139
  53. package/src/defineNode.ts +0 -105
  54. package/src/definePrinter.ts +0 -256
  55. package/src/dialect.ts +0 -76
  56. package/src/factory.ts +0 -44
  57. package/src/guards.ts +0 -28
  58. package/src/index.ts +0 -13
  59. package/src/infer.ts +0 -132
  60. package/src/macros/index.ts +0 -3
  61. package/src/macros/macroDiscriminatorEnum.ts +0 -50
  62. package/src/macros/macroEnumName.ts +0 -33
  63. package/src/macros/macroSimplifyUnion.ts +0 -60
  64. package/src/nodes/base.ts +0 -49
  65. package/src/nodes/code.ts +0 -352
  66. package/src/nodes/content.ts +0 -51
  67. package/src/nodes/file.ts +0 -379
  68. package/src/nodes/function.ts +0 -283
  69. package/src/nodes/index.ts +0 -93
  70. package/src/nodes/input.ts +0 -144
  71. package/src/nodes/operation.ts +0 -165
  72. package/src/nodes/output.ts +0 -49
  73. package/src/nodes/parameter.ts +0 -71
  74. package/src/nodes/property.ts +0 -67
  75. package/src/nodes/requestBody.ts +0 -54
  76. package/src/nodes/response.ts +0 -173
  77. package/src/nodes/schema.ts +0 -732
  78. package/src/registry.ts +0 -75
  79. package/src/signature.ts +0 -207
  80. package/src/types.ts +0 -9
  81. package/src/utils/codegen.ts +0 -104
  82. package/src/utils/extractStringsFromNodes.ts +0 -35
  83. package/src/utils/fileMerge.ts +0 -184
  84. package/src/utils/index.ts +0 -11
  85. package/src/utils/operationParams.ts +0 -353
  86. package/src/utils/refs.ts +0 -138
  87. package/src/utils/schemaGraph.ts +0 -169
  88. package/src/utils/schemaMerge.ts +0 -34
  89. package/src/utils/schemaTraversal.ts +0 -86
  90. package/src/utils/strings.ts +0 -139
  91. package/src/visitor.ts +0 -519
  92. /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
@@ -1,93 +0,0 @@
1
- import type { ArrowFunctionNode, ConstNode, FunctionNode, TypeNode } from './code.ts'
2
- import type { ContentNode } from './content.ts'
3
- import type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
4
- import type { FunctionParamNode } from './function.ts'
5
- import type { InputNode } from './input.ts'
6
- import type { OperationNode } from './operation.ts'
7
- import type { OutputNode } from './output.ts'
8
- import type { ParameterNode } from './parameter.ts'
9
- import type { PropertyNode } from './property.ts'
10
- import type { RequestBodyNode } from './requestBody.ts'
11
- import type { ResponseNode } from './response.ts'
12
- import type { SchemaNode } from './schema.ts'
13
-
14
- export type { NodeKind } from './base.ts'
15
- export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, JSDocNode, JsxNode, TextNode, TypeNode } from './code.ts'
16
- export type { ContentNode } from './content.ts'
17
- export type { ExportNode, FileNode, ImportNode, SourceNode, UserFileNode } from './file.ts'
18
- export type {
19
- FunctionParamKind,
20
- FunctionParameterNode,
21
- FunctionParametersNode,
22
- FunctionParamNode,
23
- IndexedAccessTypeNode,
24
- ObjectBindingPatternNode,
25
- TypeExpression,
26
- TypeLiteralNode,
27
- } from './function.ts'
28
- export type { InputMeta, InputNode } from './input.ts'
29
- export type { GenericOperationNode, HttpMethod, HttpOperationNode, OperationNode } from './operation.ts'
30
- export type { OutputNode } from './output.ts'
31
- export type { ParameterLocation, ParameterNode } from './parameter.ts'
32
- export type { PropertyNode } from './property.ts'
33
- export type { RequestBodyNode } from './requestBody.ts'
34
- export type { ResponseNode, StatusCode } from './response.ts'
35
- export type {
36
- ArraySchemaNode,
37
- DateSchemaNode,
38
- DatetimeSchemaNode,
39
- EnumSchemaNode,
40
- IntersectionSchemaNode,
41
- NumberSchemaNode,
42
- ObjectSchemaNode,
43
- PrimitiveSchemaType,
44
- RefSchemaNode,
45
- ScalarSchemaNode,
46
- ScalarSchemaType,
47
- SchemaNode,
48
- SchemaNodeByType,
49
- SchemaType,
50
- StringSchemaNode,
51
- TimeSchemaNode,
52
- UnionSchemaNode,
53
- UrlSchemaNode,
54
- } from './schema.ts'
55
-
56
- /**
57
- * Union of all AST node types.
58
- *
59
- * This lets TypeScript narrow types in `switch (node.kind)` blocks.
60
- *
61
- * @example
62
- * ```ts
63
- * function getKind(node: Node): string {
64
- * switch (node.kind) {
65
- * case 'Input':
66
- * return 'input'
67
- * case 'Output':
68
- * return 'output'
69
- * default:
70
- * return 'other'
71
- * }
72
- * }
73
- * ```
74
- */
75
- export type Node =
76
- | InputNode
77
- | OutputNode
78
- | OperationNode
79
- | SchemaNode
80
- | PropertyNode
81
- | ParameterNode
82
- | ResponseNode
83
- | RequestBodyNode
84
- | ContentNode
85
- | FunctionParamNode
86
- | FileNode
87
- | ImportNode
88
- | ExportNode
89
- | SourceNode
90
- | ConstNode
91
- | TypeNode
92
- | FunctionNode
93
- | ArrowFunctionNode
@@ -1,144 +0,0 @@
1
- import type { Streamable } from '@internals/utils'
2
- import { defineNode } from '../defineNode.ts'
3
- import type { BaseNode } from './base.ts'
4
- import type { OperationNode } from './operation.ts'
5
- import type { SchemaNode } from './schema.ts'
6
-
7
- /**
8
- * Metadata for an API document, populated by the adapter and available to every generator.
9
- *
10
- * All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.
11
- * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
12
- * pre-scan so generators never need to iterate the full schema list themselves.
13
- *
14
- * @example
15
- * ```ts
16
- * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://petstore.swagger.io/v2', circularNames: [], enumNames: [] }
17
- * ```
18
- */
19
- export type InputMeta = {
20
- /**
21
- * API title from `info.title` in the source document.
22
- */
23
- title?: string
24
- /**
25
- * API description from `info.description` in the source document.
26
- */
27
- description?: string
28
- /**
29
- * API version string from `info.version` in the source document.
30
- */
31
- version?: string
32
- /**
33
- * Resolved base URL from the first matching server entry in the source document.
34
- */
35
- baseURL?: string | null
36
- /**
37
- * Names of schemas that participate in a circular reference chain.
38
- * Computed once during the adapter pre-scan, so a generator never has to
39
- * call `findCircularSchemas` itself.
40
- *
41
- * Convert to a `Set` once at the start of a generator, not per-schema,
42
- * so lookups stay O(1) without repeated allocations.
43
- *
44
- * @example Wrap a circular schema in z.lazy()
45
- * ```ts
46
- * const circular = new Set(meta.circularNames)
47
- * if (circular.has(schema.name)) { ... }
48
- * ```
49
- */
50
- circularNames: ReadonlyArray<string>
51
- /**
52
- * Names of schemas whose type is `enum`.
53
- * Computed once during the adapter pre-scan, so a generator never has to
54
- * filter the schema list itself.
55
- *
56
- * Convert to a `Set` once at the start of a generator when you need repeated
57
- * membership checks, so each check stays O(1) instead of an array scan.
58
- *
59
- * @example Check if a referenced schema is an enum
60
- * `const enums = new Set(meta.enumNames)`
61
- * `const isEnum = enums.has(schemaName)`
62
- */
63
- enumNames: ReadonlyArray<string>
64
- }
65
-
66
- /**
67
- * Input AST node that contains all schemas and operations for one API document.
68
- * Produced by the adapter and consumed by all Kubb plugins.
69
- *
70
- * `Stream` switches `schemas` and `operations` between eager `Array`s (the default) and lazy
71
- * `AsyncIterable`s. The streaming variant `InputNode<true>` yields nodes one at a time.
72
- *
73
- * @example
74
- * ```ts
75
- * const input: InputNode = {
76
- * kind: 'Input',
77
- * schemas: [],
78
- * operations: [],
79
- * meta: { circularNames: [], enumNames: [] },
80
- * }
81
- * ```
82
- *
83
- * @example Streaming variant for large specs
84
- * ```ts
85
- * for await (const schema of inputNode.schemas) {
86
- * // only this one SchemaNode is live here. Previous ones are GC-eligible
87
- * }
88
- * ```
89
- */
90
- export type InputNode<Stream extends boolean = false> = BaseNode & {
91
- /**
92
- * Node kind.
93
- */
94
- kind: 'Input'
95
- /**
96
- * All schema nodes in the document.
97
- */
98
- schemas: Streamable<SchemaNode, Stream>
99
- /**
100
- * All operation nodes in the document.
101
- */
102
- operations: Streamable<OperationNode, Stream>
103
- /**
104
- * Document metadata populated by the adapter.
105
- */
106
- meta: InputMeta
107
- }
108
-
109
- /**
110
- * Definition for the {@link InputNode}.
111
- */
112
- export const inputDef = defineNode<InputNode, Partial<Omit<InputNode, 'kind'>>>({
113
- kind: 'Input',
114
- defaults: { schemas: [], operations: [], meta: { circularNames: [], enumNames: [] } },
115
- children: ['schemas', 'operations'],
116
- visitorKey: 'input',
117
- })
118
-
119
- /**
120
- * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
121
- * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array
122
- * `schemas`/`operations`. Both variants get the defaulted `meta`.
123
- *
124
- * @example Eager
125
- * ```ts
126
- * const input = createInput()
127
- * // { kind: 'Input', schemas: [], operations: [] }
128
- * ```
129
- *
130
- * @example Streaming
131
- * ```ts
132
- * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
133
- * ```
134
- */
135
- export function createInput<Stream extends boolean = false>(options: Partial<Omit<InputNode<Stream>, 'kind'>> & { stream?: Stream } = {}): InputNode<Stream> {
136
- const { stream, ...overrides } = options
137
- // Streaming inputs carry AsyncIterable sources, so skip the array defaults that
138
- // inputDef.create applies for the eager variant. Keep the meta default.
139
- if (stream) {
140
- return { kind: 'Input', meta: { circularNames: [], enumNames: [] }, ...overrides } as InputNode<Stream>
141
- }
142
-
143
- return inputDef.create(overrides as Partial<Omit<InputNode, 'kind'>>) as InputNode<Stream>
144
- }
@@ -1,165 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { ParameterNode } from './parameter.ts'
4
- import { createRequestBody, type RequestBodyNode } from './requestBody.ts'
5
- import type { ResponseNode } from './response.ts'
6
-
7
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE'
8
-
9
- /**
10
- * Transport an operation belongs to.
11
- */
12
- type OperationProtocol = 'http'
13
-
14
- /**
15
- * Fields shared by every operation, regardless of transport.
16
- */
17
- type OperationNodeBase = BaseNode & {
18
- /**
19
- * Node kind.
20
- */
21
- kind: 'Operation'
22
- /**
23
- * Operation identifier, usually from OpenAPI `operationId`.
24
- */
25
- operationId: string
26
- /**
27
- * Group labels for the operation.
28
- * Usually copied from OpenAPI `tags`.
29
- */
30
- tags: Array<string>
31
- /**
32
- * Short one-line operation summary.
33
- */
34
- summary?: string
35
- /**
36
- * Full operation description.
37
- */
38
- description?: string
39
- /**
40
- * Marks the operation as deprecated.
41
- */
42
- deprecated?: boolean
43
- /**
44
- * Query, path, header, and cookie parameters for the operation.
45
- */
46
- parameters: Array<ParameterNode>
47
- /**
48
- * Request body for the operation.
49
- */
50
- requestBody?: RequestBodyNode
51
- /**
52
- * Operation responses.
53
- */
54
- responses: Array<ResponseNode>
55
- }
56
-
57
- /**
58
- * Operation served over HTTP/REST (OpenAPI). `method` and `path` are guaranteed.
59
- *
60
- * @example
61
- * ```ts
62
- * const operation: HttpOperationNode = {
63
- * kind: 'Operation',
64
- * operationId: 'listPets',
65
- * protocol: 'http',
66
- * method: 'GET',
67
- * path: '/pets',
68
- * tags: [],
69
- * parameters: [],
70
- * responses: [],
71
- * }
72
- * ```
73
- */
74
- export type HttpOperationNode = OperationNodeBase & {
75
- /**
76
- * Transport the operation belongs to.
77
- */
78
- protocol?: 'http'
79
- /**
80
- * HTTP method like `'GET'`.
81
- */
82
- method: HttpMethod
83
- /**
84
- * OpenAPI-style path string, for example `/pets/{petId}`, with `{param}` notation preserved.
85
- */
86
- path: string
87
- }
88
-
89
- /**
90
- * Operation for a non-HTTP transport. HTTP-only fields are forbidden.
91
- */
92
- export type GenericOperationNode = OperationNodeBase & {
93
- /**
94
- * Transport the operation belongs to.
95
- */
96
- protocol?: Exclude<OperationProtocol, 'http'>
97
- method?: never
98
- path?: never
99
- }
100
-
101
- /**
102
- * AST node representing one API operation.
103
- *
104
- * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
105
- * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
106
- * `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
107
- */
108
- export type OperationNode = HttpOperationNode | GenericOperationNode
109
-
110
- type OperationInput = {
111
- operationId: string
112
- method?: HttpOperationNode['method']
113
- path?: HttpOperationNode['path']
114
- requestBody?: Omit<RequestBodyNode, 'kind'>
115
- [key: string]: unknown
116
- }
117
-
118
- /**
119
- * Definition for the {@link OperationNode}. HTTP operations (those carrying both
120
- * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
121
- * normalized into a `RequestBodyNode`.
122
- */
123
- export const operationDef = defineNode<OperationNode, OperationInput>({
124
- kind: 'Operation',
125
- build: (props) => {
126
- const { requestBody, ...rest } = props
127
- const isHttp = rest.method !== undefined && rest.path !== undefined
128
-
129
- return {
130
- tags: [],
131
- parameters: [],
132
- responses: [],
133
- ...rest,
134
- ...(isHttp ? { protocol: 'http' as const } : {}),
135
- requestBody: requestBody ? createRequestBody(requestBody) : undefined,
136
- }
137
- },
138
- children: ['parameters', 'requestBody', 'responses'],
139
- visitorKey: 'operation',
140
- })
141
-
142
- /**
143
- * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
144
- *
145
- * @example
146
- * ```ts
147
- * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })
148
- * // tags, parameters, and responses are []
149
- * ```
150
- */
151
- export function createOperation(
152
- props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &
153
- Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {
154
- requestBody?: Omit<RequestBodyNode, 'kind'>
155
- },
156
- ): HttpOperationNode
157
- export function createOperation(
158
- props: Pick<GenericOperationNode, 'operationId'> &
159
- Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {
160
- requestBody?: Omit<RequestBodyNode, 'kind'>
161
- },
162
- ): GenericOperationNode
163
- export function createOperation(props: OperationInput): OperationNode {
164
- return operationDef.create(props)
165
- }
@@ -1,49 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { FileNode } from './file.ts'
4
-
5
- /**
6
- * Output AST node that groups all generated file output for one API document.
7
- *
8
- * Produced by generators and consumed by the build pipeline to write files.
9
- *
10
- * @example
11
- * ```ts
12
- * const output: OutputNode = {
13
- * kind: 'Output',
14
- * files: [],
15
- * }
16
- * ```
17
- */
18
- export type OutputNode = BaseNode & {
19
- /**
20
- * Node kind.
21
- */
22
- kind: 'Output'
23
- /**
24
- * Generated file nodes.
25
- */
26
- files: Array<FileNode>
27
- }
28
-
29
- /**
30
- * Definition for the {@link OutputNode}.
31
- */
32
- export const outputDef = defineNode<OutputNode, Partial<Omit<OutputNode, 'kind'>>>({
33
- kind: 'Output',
34
- defaults: { files: [] },
35
- visitorKey: 'output',
36
- })
37
-
38
- /**
39
- * Creates an `OutputNode` with a stable default for `files`.
40
- *
41
- * @example
42
- * ```ts
43
- * const output = createOutput()
44
- * // { kind: 'Output', files: [] }
45
- * ```
46
- */
47
- export function createOutput(overrides: Partial<Omit<OutputNode, 'kind'>> = {}): OutputNode {
48
- return outputDef.create(overrides)
49
- }
@@ -1,71 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { SchemaNode } from './schema.ts'
4
-
5
- export type ParameterLocation = 'path' | 'query' | 'header' | 'cookie'
6
-
7
- /**
8
- * AST node representing one operation parameter.
9
- *
10
- * @example
11
- * ```ts
12
- * const param: ParameterNode = {
13
- * kind: 'Parameter',
14
- * name: 'petId',
15
- * in: 'path',
16
- * schema: createSchema({ type: 'string' }),
17
- * required: true,
18
- * }
19
- * ```
20
- */
21
- export type ParameterNode = BaseNode & {
22
- kind: 'Parameter'
23
- /**
24
- * Parameter name.
25
- */
26
- name: string
27
- /**
28
- * Parameter location (`path`, `query`, `header`, or `cookie`).
29
- */
30
- in: ParameterLocation
31
- /**
32
- * Parameter schema.
33
- */
34
- schema: SchemaNode
35
- /**
36
- * Whether the parameter is required.
37
- */
38
- required: boolean
39
- }
40
-
41
- type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>
42
-
43
- /**
44
- * Definition for the {@link ParameterNode}. `required` defaults to `false`. When a `dialect` is
45
- * passed to `create`, the schema's `optional`/`nullish` flags are derived through its
46
- * `optionality`; without one, the schema is left as-is.
47
- */
48
- export const parameterDef = defineNode<ParameterNode, UserParameterNode>({
49
- kind: 'Parameter',
50
- build: (props, dialect) => {
51
- const required = props.required ?? false
52
- return { ...props, required, schema: dialect ? dialect.schema.optionality(props.schema, required) : props.schema }
53
- },
54
- children: ['schema'],
55
- visitorKey: 'parameter',
56
- })
57
-
58
- /**
59
- * Creates a `ParameterNode`.
60
- *
61
- * @example
62
- * ```ts
63
- * const param = createParameter({
64
- * name: 'petId',
65
- * in: 'path',
66
- * required: true,
67
- * schema: createSchema({ type: 'string' }),
68
- * })
69
- * ```
70
- */
71
- export const createParameter = parameterDef.create
@@ -1,67 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { SchemaNode } from './schema.ts'
4
-
5
- /**
6
- * AST node representing one named object property.
7
- *
8
- * @example
9
- * ```ts
10
- * const property: PropertyNode = {
11
- * kind: 'Property',
12
- * name: 'id',
13
- * schema: createSchema({ type: 'integer' }),
14
- * required: true,
15
- * }
16
- * ```
17
- */
18
- export type PropertyNode = BaseNode & {
19
- kind: 'Property'
20
- /**
21
- * Property key.
22
- */
23
- name: string
24
- /**
25
- * Property schema.
26
- */
27
- schema: SchemaNode
28
- /**
29
- * Whether the property is required.
30
- */
31
- required: boolean
32
- }
33
-
34
- /**
35
- * Loosely-typed property accepted by `createProperty`, with `required` optional.
36
- */
37
- export type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>
38
-
39
- /**
40
- * Definition for the {@link PropertyNode}. `required` defaults to `false`. When a `dialect` is
41
- * passed to `create`, the schema's `optional`/`nullish` flags are derived through its
42
- * `optionality`; without one, the schema is left as-is.
43
- */
44
- export const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
45
- kind: 'Property',
46
- build: (props, dialect) => {
47
- const required = props.required ?? false
48
- return { ...props, required, schema: dialect ? dialect.schema.optionality(props.schema, required) : props.schema }
49
- },
50
- children: ['schema'],
51
- visitorKey: 'property',
52
- })
53
-
54
- /**
55
- * Creates a `PropertyNode`.
56
- *
57
- * @example
58
- * ```ts
59
- * const property = createProperty({
60
- * name: 'status',
61
- * required: true,
62
- * schema: createSchema({ type: 'string', nullable: true }),
63
- * })
64
- * // required=true, no optional/nullish
65
- * ```
66
- */
67
- export const createProperty = propertyDef.create
@@ -1,54 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { ContentNode } from './content.ts'
4
-
5
- /**
6
- * AST node representing an operation request body.
7
- *
8
- * Body schemas live exclusively inside the `content` array (one entry per content type),
9
- * mirroring {@link ResponseNode}.
10
- *
11
- * @example
12
- * ```ts
13
- * const requestBody: RequestBodyNode = {
14
- * kind: 'RequestBody',
15
- * required: true,
16
- * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
17
- * }
18
- * ```
19
- */
20
- export type RequestBodyNode = BaseNode & {
21
- kind: 'RequestBody'
22
- /**
23
- * Request body description carried over from the spec.
24
- */
25
- description?: string
26
- /**
27
- * Whether the request body is required (`requestBody.required: true` in the spec).
28
- * When `false` or absent, the generated `data` parameter should be optional.
29
- */
30
- required?: boolean
31
- /**
32
- * Content type entries for this request body.
33
- *
34
- * When the adapter `contentType` option is set, this array contains exactly one entry for
35
- * that content type. Otherwise it contains one entry per content type declared in the spec,
36
- * so plugins can generate code for every variant (for example, separate hooks for
37
- * `application/json` and `multipart/form-data`).
38
- */
39
- content?: Array<ContentNode>
40
- }
41
-
42
- /**
43
- * Definition for the {@link RequestBodyNode}. Content entries are built upfront with
44
- * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
45
- */
46
- export const requestBodyDef = defineNode<RequestBodyNode>({
47
- kind: 'RequestBody',
48
- children: ['content'],
49
- })
50
-
51
- /**
52
- * Creates a `RequestBodyNode`.
53
- */
54
- export const createRequestBody = requestBodyDef.create