@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/function.ts
CHANGED
|
@@ -1,84 +1,101 @@
|
|
|
1
|
+
import { defineNode } from '../node.ts'
|
|
1
2
|
import type { BaseNode } from './base.ts'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* type annotation. Each language printer renders the variant into its own syntax.
|
|
5
|
+
* A language-agnostic type expression used as a function parameter type annotation.
|
|
6
6
|
*
|
|
7
|
-
* - `
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
|
|
7
|
+
* - a plain `string` is a type reference rendered as-is, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`
|
|
8
|
+
* - a {@link TypeLiteralNode} is an inline anonymous type, e.g. `{ petId: string; name?: string }`
|
|
9
|
+
* - an {@link IndexedAccessTypeNode} is a single field accessed from a named type, e.g. `PathParams['petId']`
|
|
10
|
+
*/
|
|
11
|
+
export type TypeExpression = string | TypeLiteralNode | IndexedAccessTypeNode
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* AST node for an inline anonymous object type grouping named fields.
|
|
15
|
+
* TypeScript renders as `{ key: Type; other?: OtherType }`.
|
|
11
16
|
*
|
|
12
|
-
* @example
|
|
17
|
+
* @example
|
|
13
18
|
* ```ts
|
|
14
|
-
*
|
|
15
|
-
* //
|
|
19
|
+
* createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
|
|
20
|
+
* // { petId: string }
|
|
16
21
|
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type TypeLiteralNode = BaseNode & {
|
|
24
|
+
kind: 'TypeLiteral'
|
|
25
|
+
/**
|
|
26
|
+
* Members of the object type, rendered in order.
|
|
27
|
+
*/
|
|
28
|
+
members: Array<{
|
|
29
|
+
/**
|
|
30
|
+
* Member key.
|
|
31
|
+
*/
|
|
32
|
+
name: string
|
|
33
|
+
/**
|
|
34
|
+
* Member type expression.
|
|
35
|
+
*/
|
|
36
|
+
type: TypeExpression
|
|
37
|
+
/**
|
|
38
|
+
* Whether the member is optional, rendered with `?`.
|
|
39
|
+
*/
|
|
40
|
+
optional?: boolean
|
|
41
|
+
}>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* AST node for a single field accessed from a named group type.
|
|
46
|
+
* TypeScript renders as `objectType['indexType']`.
|
|
17
47
|
*
|
|
18
|
-
* @example
|
|
48
|
+
* @example
|
|
19
49
|
* ```ts
|
|
20
|
-
*
|
|
21
|
-
* //
|
|
50
|
+
* createIndexedAccessType({ objectType: 'GetPetPathParams', indexType: 'petId' })
|
|
51
|
+
* // GetPetPathParams['petId']
|
|
22
52
|
* ```
|
|
53
|
+
*/
|
|
54
|
+
export type IndexedAccessTypeNode = BaseNode & {
|
|
55
|
+
kind: 'IndexedAccessType'
|
|
56
|
+
/**
|
|
57
|
+
* Name of the type being indexed, e.g. `'GetPetPathParams'`.
|
|
58
|
+
*/
|
|
59
|
+
objectType: string
|
|
60
|
+
/**
|
|
61
|
+
* Field key to access, e.g. `'petId'`.
|
|
62
|
+
*/
|
|
63
|
+
indexType: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* AST node for an object destructuring binding, used as the name of a grouped function parameter.
|
|
68
|
+
* TypeScript renders as `{ id, name }` or `{ id: renamed }` when `propertyName` differs.
|
|
23
69
|
*
|
|
24
|
-
* @example
|
|
70
|
+
* @example
|
|
25
71
|
* ```ts
|
|
26
|
-
*
|
|
27
|
-
* //
|
|
72
|
+
* createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
|
|
73
|
+
* // { id, name }
|
|
28
74
|
* ```
|
|
29
75
|
*/
|
|
30
|
-
export type
|
|
76
|
+
export type ObjectBindingPatternNode = BaseNode & {
|
|
77
|
+
kind: 'ObjectBindingPattern'
|
|
31
78
|
/**
|
|
32
|
-
*
|
|
79
|
+
* Bound elements, rendered in order.
|
|
33
80
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name: string
|
|
46
|
-
}
|
|
47
|
-
| {
|
|
48
|
-
/**
|
|
49
|
-
* Struct variant — an inline anonymous type grouping named fields.
|
|
50
|
-
* TypeScript renders as `{ key: Type; other?: OtherType }`.
|
|
51
|
-
*/
|
|
52
|
-
variant: 'struct'
|
|
53
|
-
/**
|
|
54
|
-
* Properties of the struct type.
|
|
55
|
-
*/
|
|
56
|
-
properties: Array<{
|
|
57
|
-
name: string
|
|
58
|
-
optional: boolean
|
|
59
|
-
type: ParamsTypeNode
|
|
60
|
-
}>
|
|
61
|
-
}
|
|
62
|
-
| {
|
|
63
|
-
/**
|
|
64
|
-
* Member variant — a single named field accessed from a group type.
|
|
65
|
-
* TypeScript renders as `Base['key']`.
|
|
66
|
-
*/
|
|
67
|
-
variant: 'member'
|
|
68
|
-
/**
|
|
69
|
-
* Base type name, e.g. `'DeletePetPathParams'`.
|
|
70
|
-
*/
|
|
71
|
-
base: string
|
|
72
|
-
/**
|
|
73
|
-
* The field name to access, e.g. `'petId'`.
|
|
74
|
-
*/
|
|
75
|
-
key: string
|
|
76
|
-
}
|
|
77
|
-
)
|
|
81
|
+
elements: Array<{
|
|
82
|
+
/**
|
|
83
|
+
* Local binding name.
|
|
84
|
+
*/
|
|
85
|
+
name: string
|
|
86
|
+
/**
|
|
87
|
+
* Source key when it differs from the binding name, rendered as `propertyName: name`.
|
|
88
|
+
*/
|
|
89
|
+
propertyName?: string
|
|
90
|
+
}>
|
|
91
|
+
}
|
|
78
92
|
|
|
79
93
|
/**
|
|
80
94
|
* AST node for one function parameter.
|
|
81
95
|
*
|
|
96
|
+
* A simple parameter has a `string` name. A destructured group has an
|
|
97
|
+
* {@link ObjectBindingPatternNode} name paired with a {@link TypeLiteralNode} type.
|
|
98
|
+
*
|
|
82
99
|
* @example Required parameter
|
|
83
100
|
* `name: Type`
|
|
84
101
|
*
|
|
@@ -90,103 +107,32 @@ export type ParamsTypeNode = BaseNode & {
|
|
|
90
107
|
*
|
|
91
108
|
* @example Rest parameter
|
|
92
109
|
* `...name: Type[]`
|
|
110
|
+
*
|
|
111
|
+
* @example Destructured group
|
|
112
|
+
* `{ id, name? }: { id: string; name?: string } = {}`
|
|
93
113
|
*/
|
|
94
114
|
export type FunctionParameterNode = BaseNode & {
|
|
95
|
-
/**
|
|
96
|
-
* Node kind.
|
|
97
|
-
*/
|
|
98
115
|
kind: 'FunctionParameter'
|
|
99
116
|
/**
|
|
100
|
-
* Parameter name
|
|
101
|
-
*/
|
|
102
|
-
name: string
|
|
103
|
-
/**
|
|
104
|
-
* Type annotation as a structured {@link ParamsTypeNode}.
|
|
105
|
-
* Omit for untyped output.
|
|
106
|
-
*
|
|
107
|
-
* @example Reference type node
|
|
108
|
-
* `{ kind: 'ParamsType', variant: 'reference', name: 'string' }` → `petId: string`
|
|
109
|
-
*
|
|
110
|
-
* @example Struct type node
|
|
111
|
-
* `{ kind: 'ParamsType', variant: 'struct', properties: [...] }` → `{ key: Type; other?: OtherType }`
|
|
112
|
-
*
|
|
113
|
-
* @example Member type node
|
|
114
|
-
* `{ kind: 'ParamsType', variant: 'member', base: 'PathParams', key: 'petId' }` → `PathParams['petId']`
|
|
115
|
-
*/
|
|
116
|
-
type?: ParamsTypeNode
|
|
117
|
-
/**
|
|
118
|
-
* When `true` the parameter is emitted as a rest parameter.
|
|
119
|
-
*
|
|
120
|
-
* @example Rest parameter
|
|
121
|
-
* `...name: Type[]`
|
|
122
|
-
*/
|
|
123
|
-
rest?: boolean
|
|
124
|
-
} /**
|
|
125
|
-
* Optional parameter — rendered with `?` and may be omitted by the caller.
|
|
126
|
-
* Cannot be combined with `default` because a defaulted parameter is already optional.
|
|
127
|
-
*/ & (
|
|
128
|
-
| { optional: true; default?: never }
|
|
129
|
-
/**
|
|
130
|
-
* Required parameter, or a parameter with a default value.
|
|
131
|
-
*
|
|
132
|
-
* @example Required
|
|
133
|
-
* `name: Type`
|
|
134
|
-
*
|
|
135
|
-
* @example With default
|
|
136
|
-
* `name: Type = default`
|
|
137
|
-
*/
|
|
138
|
-
| { optional?: false; default?: string }
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* AST node for a group of related function parameters treated as a single unit.
|
|
143
|
-
*
|
|
144
|
-
* Each language printer decides how to render this group:
|
|
145
|
-
* - TypeScript/JS: destructured object `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}`
|
|
146
|
-
* - Python: keyword-only args or a typed dict parameter
|
|
147
|
-
* - C# / Kotlin: named record / data-class parameter
|
|
148
|
-
*
|
|
149
|
-
* When `inline` is `true`, the group is spread as individual top-level parameters
|
|
150
|
-
* rather than wrapped in a single grouped construct.
|
|
151
|
-
*
|
|
152
|
-
* @example Grouped destructuring
|
|
153
|
-
* `{ id, name }: { id: string; name: string } = {}`
|
|
154
|
-
*
|
|
155
|
-
* @example Inline (spread as individual parameters)
|
|
156
|
-
* `id: string, name: string`
|
|
157
|
-
*/
|
|
158
|
-
export type ParameterGroupNode = BaseNode & {
|
|
159
|
-
/**
|
|
160
|
-
* Node kind.
|
|
117
|
+
* Parameter name, or an {@link ObjectBindingPatternNode} for a destructured group.
|
|
161
118
|
*/
|
|
162
|
-
|
|
119
|
+
name: string | ObjectBindingPatternNode
|
|
163
120
|
/**
|
|
164
|
-
*
|
|
165
|
-
* Rendered as a destructured object or spread inline when `inline` is `true`.
|
|
121
|
+
* Type annotation as a {@link TypeExpression}. Omit for untyped output.
|
|
166
122
|
*/
|
|
167
|
-
|
|
123
|
+
type?: TypeExpression
|
|
168
124
|
/**
|
|
169
|
-
*
|
|
170
|
-
* When absent, printers auto-compute it from `properties`.
|
|
171
|
-
*/
|
|
172
|
-
type?: ParamsTypeNode
|
|
173
|
-
/**
|
|
174
|
-
* When `true`, `properties` are emitted as individual top-level parameters instead of
|
|
175
|
-
* being wrapped in a single grouped construct.
|
|
176
|
-
*
|
|
177
|
-
* @default false
|
|
178
|
-
*/
|
|
179
|
-
inline?: boolean
|
|
180
|
-
/**
|
|
181
|
-
* Whether the group as a whole is optional.
|
|
182
|
-
* If omitted, printers infer this from child properties.
|
|
125
|
+
* Whether the parameter is optional, rendered with `?`.
|
|
183
126
|
*/
|
|
184
127
|
optional?: boolean
|
|
185
128
|
/**
|
|
186
|
-
* Default value
|
|
187
|
-
* Commonly `'{}'` to allow omitting the argument entirely.
|
|
129
|
+
* Default value, written verbatim after `=`. Commonly `'{}'` for a destructured group.
|
|
188
130
|
*/
|
|
189
131
|
default?: string
|
|
132
|
+
/**
|
|
133
|
+
* When `true` the parameter is emitted as a rest parameter, e.g. `...name: Type[]`.
|
|
134
|
+
*/
|
|
135
|
+
rest?: boolean
|
|
190
136
|
}
|
|
191
137
|
|
|
192
138
|
/**
|
|
@@ -196,28 +142,142 @@ export type ParameterGroupNode = BaseNode & {
|
|
|
196
142
|
* Nodes are plain immutable data.
|
|
197
143
|
*
|
|
198
144
|
* Renders differently depending on the output mode:
|
|
199
|
-
* - `declaration` → `(id: string, config: Config = {})`
|
|
200
|
-
* - `call` → `(id, { method, url })`
|
|
201
|
-
* - `keys` → `{ id, config }` — key names only (for destructuring)
|
|
202
|
-
* - `values` → `{ id: id, config: config }` — key → value pairs
|
|
145
|
+
* - `declaration` → `(id: string, config: Config = {})` function declaration parameters
|
|
146
|
+
* - `call` → `(id, { method, url })` function call arguments
|
|
203
147
|
*/
|
|
204
148
|
export type FunctionParametersNode = BaseNode & {
|
|
205
|
-
/**
|
|
206
|
-
* Node kind.
|
|
207
|
-
*/
|
|
208
149
|
kind: 'FunctionParameters'
|
|
209
150
|
/**
|
|
210
151
|
* Ordered parameter nodes.
|
|
211
152
|
*/
|
|
212
|
-
params: ReadonlyArray<FunctionParameterNode
|
|
153
|
+
params: ReadonlyArray<FunctionParameterNode>
|
|
213
154
|
}
|
|
214
155
|
|
|
215
156
|
/**
|
|
216
157
|
* Union of all function-parameter AST node variants used by the function-parameter printer.
|
|
217
158
|
*/
|
|
218
|
-
export type FunctionParamNode = FunctionParameterNode |
|
|
159
|
+
export type FunctionParamNode = FunctionParameterNode | FunctionParametersNode | TypeLiteralNode | IndexedAccessTypeNode | ObjectBindingPatternNode
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Handler-map keys for the function-parameter printer, one per {@link FunctionParamNode} kind.
|
|
163
|
+
*/
|
|
164
|
+
export type FunctionParamKind = FunctionParamNode['kind']
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Definition for the {@link TypeLiteralNode}.
|
|
168
|
+
*/
|
|
169
|
+
export const typeLiteralDef = defineNode<TypeLiteralNode, Pick<TypeLiteralNode, 'members'>>({ kind: 'TypeLiteral' })
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
|
|
177
|
+
* // { petId: string }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export const createTypeLiteral = typeLiteralDef.create
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Definition for the {@link IndexedAccessTypeNode}.
|
|
184
|
+
*/
|
|
185
|
+
export const indexedAccessTypeDef = defineNode<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, 'kind'>>({ kind: 'IndexedAccessType' })
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })
|
|
193
|
+
* // DeletePetPathParams['petId']
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export const createIndexedAccessType = indexedAccessTypeDef.create
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Definition for the {@link ObjectBindingPatternNode}.
|
|
200
|
+
*/
|
|
201
|
+
export const objectBindingPatternDef = defineNode<ObjectBindingPatternNode, Pick<ObjectBindingPatternNode, 'elements'>>({ kind: 'ObjectBindingPattern' })
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
|
|
209
|
+
* // { id, name }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export const createObjectBindingPattern = objectBindingPatternDef.create
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Plain property descriptor for a destructured group built by {@link createFunctionParameter}.
|
|
216
|
+
*/
|
|
217
|
+
type FunctionParameterProperty = {
|
|
218
|
+
name: string
|
|
219
|
+
type: TypeExpression
|
|
220
|
+
optional?: boolean
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
type FunctionParameterInput =
|
|
224
|
+
| { name: string; type?: TypeExpression; optional?: boolean; default?: string; rest?: boolean }
|
|
225
|
+
| { properties: Array<FunctionParameterProperty>; optional?: boolean; default?: string }
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.
|
|
229
|
+
* Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
|
|
230
|
+
* paired with a {@link TypeLiteralNode} type.
|
|
231
|
+
*/
|
|
232
|
+
export const functionParameterDef = defineNode<FunctionParameterNode, FunctionParameterInput>({
|
|
233
|
+
kind: 'FunctionParameter',
|
|
234
|
+
build: (input) => {
|
|
235
|
+
if ('properties' in input) {
|
|
236
|
+
return {
|
|
237
|
+
name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),
|
|
238
|
+
type: createTypeLiteral({ members: input.properties.map((p) => ({ name: p.name, type: p.type, optional: p.optional ?? false })) }),
|
|
239
|
+
optional: input.optional ?? false,
|
|
240
|
+
...(input.default !== undefined ? { default: input.default } : {}),
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return { optional: false, ...input }
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Creates a `FunctionParameterNode`. `optional` defaults to `false`.
|
|
249
|
+
*
|
|
250
|
+
* @example Optional param
|
|
251
|
+
* ```ts
|
|
252
|
+
* createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
|
|
253
|
+
* // → params?: QueryParams
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* @example Destructured group
|
|
257
|
+
* ```ts
|
|
258
|
+
* createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
|
|
259
|
+
* // → { id, name }: { id: string; name?: string } = {}
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export const createFunctionParameter = functionParameterDef.create
|
|
219
263
|
|
|
220
264
|
/**
|
|
221
|
-
*
|
|
265
|
+
* Definition for the {@link FunctionParametersNode}.
|
|
222
266
|
*/
|
|
223
|
-
export
|
|
267
|
+
export const functionParametersDef = defineNode<FunctionParametersNode, Partial<Omit<FunctionParametersNode, 'kind'>>>({
|
|
268
|
+
kind: 'FunctionParameters',
|
|
269
|
+
defaults: { params: [] },
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Creates a `FunctionParametersNode` from an ordered list of parameters.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const empty = createFunctionParameters()
|
|
278
|
+
* // { kind: 'FunctionParameters', params: [] }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export function createFunctionParameters(props: Partial<Omit<FunctionParametersNode, 'kind'>> = {}): FunctionParametersNode {
|
|
282
|
+
return functionParametersDef.create(props)
|
|
283
|
+
}
|
package/src/nodes/http.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* All supported HTTP status code literals as strings, as used in API specs
|
|
3
3
|
* (for example, `"200"` and `"404"`).
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
type HttpStatusCode =
|
|
6
6
|
// 1xx Informational
|
|
7
7
|
| '100'
|
|
8
8
|
| '101'
|
|
@@ -83,37 +83,3 @@ export type HttpStatusCode =
|
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
85
|
export type StatusCode = HttpStatusCode | 'default'
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Supported media type strings used in request and response bodies.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* const mediaType: MediaType = 'application/json'
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export type MediaType =
|
|
96
|
-
// Application
|
|
97
|
-
| 'application/json'
|
|
98
|
-
| 'application/xml'
|
|
99
|
-
| 'application/x-www-form-urlencoded'
|
|
100
|
-
| 'application/octet-stream'
|
|
101
|
-
| 'application/pdf'
|
|
102
|
-
| 'application/zip'
|
|
103
|
-
| 'application/graphql'
|
|
104
|
-
// Multipart
|
|
105
|
-
| 'multipart/form-data'
|
|
106
|
-
// Text
|
|
107
|
-
| 'text/plain'
|
|
108
|
-
| 'text/html'
|
|
109
|
-
| 'text/csv'
|
|
110
|
-
| 'text/xml'
|
|
111
|
-
// Image
|
|
112
|
-
| 'image/png'
|
|
113
|
-
| 'image/jpeg'
|
|
114
|
-
| 'image/gif'
|
|
115
|
-
| 'image/webp'
|
|
116
|
-
| 'image/svg+xml'
|
|
117
|
-
// Audio / Video
|
|
118
|
-
| 'audio/mpeg'
|
|
119
|
-
| 'video/mp4'
|
package/src/nodes/index.ts
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
import type { ArrowFunctionNode, ConstNode, FunctionNode, TypeNode } from './code.ts'
|
|
2
|
+
import type { ContentNode } from './content.ts'
|
|
2
3
|
import type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
|
|
3
|
-
import type { FunctionParamNode
|
|
4
|
+
import type { FunctionParamNode } from './function.ts'
|
|
5
|
+
import type { InputNode } from './input.ts'
|
|
4
6
|
import type { OperationNode } from './operation.ts'
|
|
5
7
|
import type { OutputNode } from './output.ts'
|
|
6
8
|
import type { ParameterNode } from './parameter.ts'
|
|
7
9
|
import type { PropertyNode } from './property.ts'
|
|
10
|
+
import type { RequestBodyNode } from './requestBody.ts'
|
|
8
11
|
import type { ResponseNode } from './response.ts'
|
|
9
|
-
import type { InputNode } from './root.ts'
|
|
10
12
|
import type { SchemaNode } from './schema.ts'
|
|
11
13
|
|
|
12
|
-
export type {
|
|
13
|
-
export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, JSDocNode, JsxNode, TextNode,
|
|
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'
|
|
14
17
|
export type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
|
|
15
|
-
export type {
|
|
16
|
-
|
|
17
|
-
|
|
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 { StatusCode } from './http.ts'
|
|
29
|
+
export type { InputMeta, InputNode } from './input.ts'
|
|
30
|
+
export type { GenericOperationNode, HttpMethod, HttpOperationNode, OperationNode } from './operation.ts'
|
|
18
31
|
export type { OutputNode } from './output.ts'
|
|
19
32
|
export type { ParameterLocation, ParameterNode } from './parameter.ts'
|
|
20
33
|
export type { PropertyNode } from './property.ts'
|
|
34
|
+
export type { RequestBodyNode } from './requestBody.ts'
|
|
21
35
|
export type { ResponseNode } from './response.ts'
|
|
22
|
-
export type { InputMeta, InputNode } from './root.ts'
|
|
23
36
|
export type {
|
|
24
37
|
ArraySchemaNode,
|
|
25
|
-
ComplexSchemaType,
|
|
26
38
|
DateSchemaNode,
|
|
27
39
|
DatetimeSchemaNode,
|
|
28
40
|
EnumSchemaNode,
|
|
29
|
-
EnumValueNode,
|
|
30
|
-
FormatStringSchemaNode,
|
|
31
41
|
IntersectionSchemaNode,
|
|
32
|
-
Ipv4SchemaNode,
|
|
33
|
-
Ipv6SchemaNode,
|
|
34
42
|
NumberSchemaNode,
|
|
35
43
|
ObjectSchemaNode,
|
|
36
44
|
PrimitiveSchemaType,
|
|
@@ -40,7 +48,6 @@ export type {
|
|
|
40
48
|
SchemaNode,
|
|
41
49
|
SchemaNodeByType,
|
|
42
50
|
SchemaType,
|
|
43
|
-
SpecialSchemaType,
|
|
44
51
|
StringSchemaNode,
|
|
45
52
|
TimeSchemaNode,
|
|
46
53
|
UnionSchemaNode,
|
|
@@ -74,6 +81,8 @@ export type Node =
|
|
|
74
81
|
| PropertyNode
|
|
75
82
|
| ParameterNode
|
|
76
83
|
| ResponseNode
|
|
84
|
+
| RequestBodyNode
|
|
85
|
+
| ContentNode
|
|
77
86
|
| FunctionParamNode
|
|
78
87
|
| FileNode
|
|
79
88
|
| ImportNode
|
|
@@ -81,6 +90,5 @@ export type Node =
|
|
|
81
90
|
| SourceNode
|
|
82
91
|
| ConstNode
|
|
83
92
|
| TypeNode
|
|
84
|
-
| ParamsTypeNode
|
|
85
93
|
| FunctionNode
|
|
86
94
|
| ArrowFunctionNode
|