@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.
Files changed (59) hide show
  1. package/README.md +13 -9
  2. package/dist/{types-BL7RpQAE.d.ts → ast-ClnJg9BN.d.ts} +1630 -2443
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-Bn9cOos9.d.ts +14 -0
  5. package/dist/factory-C5gHvtLU.js +138 -0
  6. package/dist/factory-C5gHvtLU.js.map +1 -0
  7. package/dist/factory-JN-Ylfl6.cjs +155 -0
  8. package/dist/factory-JN-Ylfl6.cjs.map +1 -0
  9. package/dist/factory.cjs +31 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index.cjs +56 -1751
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +6 -47
  15. package/dist/index.js +7 -1697
  16. package/dist/index.js.map +1 -1
  17. package/dist/types-CB2oY8Dw.d.ts +769 -0
  18. package/dist/types.d.ts +4 -2
  19. package/dist/utils-C8bWAzhv.cjs +2696 -0
  20. package/dist/utils-C8bWAzhv.cjs.map +1 -0
  21. package/dist/utils-DN4XLVqz.js +2099 -0
  22. package/dist/utils-DN4XLVqz.js.map +1 -0
  23. package/dist/utils.cjs +12 -1
  24. package/dist/utils.d.ts +21 -2
  25. package/dist/utils.js +2 -2
  26. package/package.json +5 -1
  27. package/src/dedupe.ts +1 -1
  28. package/src/factory.ts +22 -764
  29. package/src/guards.ts +1 -53
  30. package/src/index.ts +20 -39
  31. package/src/mocks.ts +6 -1
  32. package/src/node.ts +128 -0
  33. package/src/nodes/base.ts +3 -12
  34. package/src/nodes/code.ts +115 -0
  35. package/src/nodes/content.ts +19 -0
  36. package/src/nodes/file.ts +54 -0
  37. package/src/nodes/function.ts +222 -147
  38. package/src/nodes/index.ts +11 -3
  39. package/src/nodes/input.ts +37 -0
  40. package/src/nodes/operation.ts +59 -1
  41. package/src/nodes/output.ts +23 -0
  42. package/src/nodes/parameter.ts +33 -0
  43. package/src/nodes/property.ts +36 -0
  44. package/src/nodes/requestBody.ts +23 -1
  45. package/src/nodes/response.ts +39 -1
  46. package/src/nodes/schema.ts +72 -0
  47. package/src/printer.ts +3 -3
  48. package/src/registry.ts +70 -0
  49. package/src/transformers.ts +2 -2
  50. package/src/types.ts +6 -4
  51. package/src/utils/ast.ts +103 -243
  52. package/src/utils/extractStringsFromNodes.ts +34 -0
  53. package/src/utils/index.ts +44 -0
  54. package/src/visitor.ts +3 -47
  55. package/dist/chunk-C0LytTxp.js +0 -8
  56. package/dist/utils-0p8ZO287.js +0 -570
  57. package/dist/utils-0p8ZO287.js.map +0 -1
  58. package/dist/utils-cdQ6Pzyi.cjs +0 -726
  59. 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 | Contents |
32
- | ----------------- | ------------------------------------------------------------------- |
33
- | `@kubb/ast` | Runtime: factory functions, guards, visitor, ref helpers, constants |
34
- | `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
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 { createRoot, createOperation, createSchema, createProperty } from '@kubb/ast'
64
+ import { createInput, createSchema, createProperty } from '@kubb/ast/factory'
61
65
 
62
- const root = createRoot({
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 { isSchemaNode, narrowSchema } from '@kubb/ast'
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 (isSchemaNode(node)) {
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
  ```