@kubb/ast 5.0.0-beta.56 → 5.0.0-beta.58
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 +13 -9
- package/dist/{types-BL7RpQAE.d.ts → ast-ClnJg9BN.d.ts} +1630 -2443
- package/dist/chunk-CNktS9qV.js +17 -0
- package/dist/extractStringsFromNodes-Bn9cOos9.d.ts +14 -0
- package/dist/factory-C5gHvtLU.js +138 -0
- package/dist/factory-C5gHvtLU.js.map +1 -0
- package/dist/factory-JN-Ylfl6.cjs +155 -0
- package/dist/factory-JN-Ylfl6.cjs.map +1 -0
- package/dist/factory.cjs +31 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.js +3 -0
- package/dist/index.cjs +56 -1751
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -47
- package/dist/index.js +7 -1697
- package/dist/index.js.map +1 -1
- package/dist/types-CB2oY8Dw.d.ts +769 -0
- package/dist/types.d.ts +4 -2
- package/dist/utils-C8bWAzhv.cjs +2696 -0
- package/dist/utils-C8bWAzhv.cjs.map +1 -0
- package/dist/utils-DN4XLVqz.js +2099 -0
- package/dist/utils-DN4XLVqz.js.map +1 -0
- package/dist/utils.cjs +12 -1
- package/dist/utils.d.ts +21 -2
- package/dist/utils.js +2 -2
- package/package.json +5 -1
- package/src/dedupe.ts +1 -1
- package/src/factory.ts +22 -764
- package/src/guards.ts +1 -53
- package/src/index.ts +20 -39
- package/src/mocks.ts +6 -1
- package/src/node.ts +128 -0
- package/src/nodes/base.ts +3 -12
- package/src/nodes/code.ts +115 -0
- package/src/nodes/content.ts +19 -0
- package/src/nodes/file.ts +54 -0
- package/src/nodes/function.ts +222 -147
- package/src/nodes/index.ts +11 -3
- package/src/nodes/input.ts +37 -0
- package/src/nodes/operation.ts +59 -1
- package/src/nodes/output.ts +23 -0
- package/src/nodes/parameter.ts +33 -0
- package/src/nodes/property.ts +36 -0
- package/src/nodes/requestBody.ts +23 -1
- package/src/nodes/response.ts +39 -1
- package/src/nodes/schema.ts +72 -0
- package/src/printer.ts +3 -3
- package/src/registry.ts +70 -0
- package/src/transformers.ts +2 -2
- package/src/types.ts +6 -4
- package/src/utils/ast.ts +103 -243
- package/src/utils/extractStringsFromNodes.ts +34 -0
- package/src/utils/index.ts +44 -0
- package/src/visitor.ts +3 -47
- package/dist/chunk-C0LytTxp.js +0 -8
- package/dist/utils-0p8ZO287.js +0 -570
- package/dist/utils-0p8ZO287.js.map +0 -1
- package/dist/utils-cdQ6Pzyi.cjs +0 -726
- package/dist/utils-cdQ6Pzyi.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -28,10 +28,12 @@ Defines the node tree, visitor pattern, factory functions, and type guards used
|
|
|
28
28
|
|
|
29
29
|
## Imports
|
|
30
30
|
|
|
31
|
-
| Path
|
|
32
|
-
|
|
|
33
|
-
| `@kubb/ast`
|
|
34
|
-
| `@kubb/ast/
|
|
31
|
+
| Path | Contents |
|
|
32
|
+
| ------------------- | ---------------------------------------------------------------------------------------- |
|
|
33
|
+
| `@kubb/ast` | Runtime: node definitions, guards, visitor, transformers, constants |
|
|
34
|
+
| `@kubb/ast/factory` | Node constructors (`createSchema`, `createFile`, and friends), the `ts.factory` analogue |
|
|
35
|
+
| `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
|
|
36
|
+
| `@kubb/ast/utils` | Spec-agnostic string and identifier helpers, ref helpers |
|
|
35
37
|
|
|
36
38
|
## Node tree
|
|
37
39
|
|
|
@@ -56,10 +58,12 @@ SchemaNode (discriminated union)
|
|
|
56
58
|
|
|
57
59
|
### Factory
|
|
58
60
|
|
|
61
|
+
Constructors live on the `@kubb/ast/factory` subpath, mirroring `ts.factory.createX`. Through `@kubb/core` the same set is reachable as `ast.factory.createSchema(...)`.
|
|
62
|
+
|
|
59
63
|
```ts
|
|
60
|
-
import {
|
|
64
|
+
import { createInput, createSchema, createProperty } from '@kubb/ast/factory'
|
|
61
65
|
|
|
62
|
-
const root =
|
|
66
|
+
const root = createInput({
|
|
63
67
|
schemas: [
|
|
64
68
|
createSchema({
|
|
65
69
|
name: 'Pet',
|
|
@@ -111,11 +115,11 @@ const types = collect<string>(root, {
|
|
|
111
115
|
### Guards
|
|
112
116
|
|
|
113
117
|
```ts
|
|
114
|
-
import {
|
|
118
|
+
import { narrowSchema, schemaDef } from '@kubb/ast'
|
|
115
119
|
import type { Node } from '@kubb/ast/types'
|
|
116
120
|
|
|
117
121
|
function process(node: Node) {
|
|
118
|
-
if (
|
|
122
|
+
if (schemaDef.is(node)) {
|
|
119
123
|
const obj = narrowSchema(node, 'object')
|
|
120
124
|
obj?.properties?.forEach((p) => console.log(p.name))
|
|
121
125
|
}
|
|
@@ -125,7 +129,7 @@ function process(node: Node) {
|
|
|
125
129
|
### Refs
|
|
126
130
|
|
|
127
131
|
```ts
|
|
128
|
-
import { extractRefName } from '@kubb/ast'
|
|
132
|
+
import { extractRefName } from '@kubb/ast/utils'
|
|
129
133
|
|
|
130
134
|
extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
131
135
|
```
|