@kubb/fabric-core 0.0.0-canary-20260111130736 → 0.0.0-canary-20260113205926

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 (62) hide show
  1. package/dist/{Fabric-CDFwTDyP.d.ts → Fabric-4XbXcu8_.d.cts} +4 -118
  2. package/dist/{Fabric-BXYWK9V4.d.cts → Fabric-BTRMItqi.d.ts} +4 -118
  3. package/dist/FileCollector-8RJHS5I3.d.ts +26 -0
  4. package/dist/FileCollector-lJGpddxr.d.cts +26 -0
  5. package/dist/KubbFile-BqiYGIzl.d.cts +118 -0
  6. package/dist/KubbFile-DSLdZhaI.d.ts +118 -0
  7. package/dist/classPrivateFieldSet2-DrVq6yr-.cjs +62 -0
  8. package/dist/classPrivateFieldSet2-Dy82u8wh.js +32 -0
  9. package/dist/{defaultParser-DPHcM2NR.js → defaultParser-CQ-4-EIF.js} +2 -2
  10. package/dist/{defaultParser-DPHcM2NR.js.map → defaultParser-CQ-4-EIF.js.map} +1 -1
  11. package/dist/{defineParser-Bxv4mb-N.js → defineParser-_trfFm28.js} +1 -1
  12. package/dist/{defineParser-Bxv4mb-N.js.map → defineParser-_trfFm28.js.map} +1 -1
  13. package/dist/{defineProperty-hUmuXj5B.cjs → defineProperty-BAD-J6vV.cjs} +5 -66
  14. package/dist/{defineProperty-hUmuXj5B.cjs.map → defineProperty-BAD-J6vV.cjs.map} +1 -1
  15. package/dist/{defineProperty-CS9Uk_6Q.js → defineProperty-DMYokRGX.js} +7 -38
  16. package/dist/{defineProperty-CS9Uk_6Q.js.map → defineProperty-DMYokRGX.js.map} +1 -1
  17. package/dist/{getRelativePath-DayVrg5k.js → getRelativePath-CHV9GNVv.js} +1 -1
  18. package/dist/{getRelativePath-DayVrg5k.js.map → getRelativePath-CHV9GNVv.js.map} +1 -1
  19. package/dist/{getRelativePath-CLj7Ou6d.cjs → getRelativePath-CMRL1NPO.cjs} +1 -1
  20. package/dist/{getRelativePath-CLj7Ou6d.cjs.map → getRelativePath-CMRL1NPO.cjs.map} +1 -1
  21. package/dist/index.cjs +173 -41
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +105 -3
  24. package/dist/index.d.ts +105 -3
  25. package/dist/index.js +126 -5
  26. package/dist/index.js.map +1 -1
  27. package/dist/parsers/typescript.cjs +1 -1
  28. package/dist/parsers/typescript.d.cts +1 -1
  29. package/dist/parsers/typescript.d.ts +1 -1
  30. package/dist/parsers/typescript.js +3 -3
  31. package/dist/parsers.d.cts +1 -1
  32. package/dist/parsers.d.ts +1 -1
  33. package/dist/parsers.js +2 -2
  34. package/dist/plugins.cjs +10 -9
  35. package/dist/plugins.cjs.map +1 -1
  36. package/dist/plugins.d.cts +2 -1
  37. package/dist/plugins.d.ts +2 -1
  38. package/dist/plugins.js +3 -2
  39. package/dist/plugins.js.map +1 -1
  40. package/dist/{trimExtName-Dq2Z7SCT.js → trimExtName-C94zbVlg.js} +1 -1
  41. package/dist/{trimExtName-Dq2Z7SCT.js.map → trimExtName-C94zbVlg.js.map} +1 -1
  42. package/dist/types.d.cts +2 -1
  43. package/dist/types.d.ts +2 -1
  44. package/dist/utils.cjs +52 -0
  45. package/dist/utils.cjs.map +1 -0
  46. package/dist/utils.d.cts +14 -0
  47. package/dist/utils.d.ts +14 -0
  48. package/dist/utils.js +51 -0
  49. package/dist/utils.js.map +1 -0
  50. package/package.json +8 -1
  51. package/src/composables/useApp.ts +15 -0
  52. package/src/composables/useContext.ts +16 -0
  53. package/src/composables/useFile.ts +16 -0
  54. package/src/composables/useLifecycle.ts +13 -0
  55. package/src/context.ts +82 -0
  56. package/src/contexts/AppContext.ts +11 -0
  57. package/src/contexts/FileCollectorContext.ts +18 -0
  58. package/src/contexts/RootContext.ts +12 -0
  59. package/src/index.ts +10 -0
  60. package/src/utils/FileCollector.ts +30 -0
  61. package/src/utils/createJSDoc.ts +15 -0
  62. package/src/utils/index.ts +2 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../src/utils/createJSDoc.ts","../src/utils/FileCollector.ts"],"sourcesContent":["/**\n * Create JSDoc comment block from comments array\n */\nexport function createJSDoc({ comments }: { comments: string[] }): string {\n if (!comments || comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => String(c ?? '').split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '*\\\\/').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n","import type * as KubbFile from '../KubbFile.ts'\n\n/**\n * FileCollector is used to collect files from components via context\n * instead of walking the DOM tree.\n */\nexport class FileCollector {\n #files: Array<KubbFile.File> = []\n\n /**\n * Add a file to the collector\n */\n add(file: KubbFile.File): void {\n this.#files.push(file)\n }\n\n /**\n * Get all collected files\n */\n get files(): Array<KubbFile.File> {\n return [...this.#files]\n }\n\n /**\n * Clear all collected files\n */\n clear(): void {\n this.#files = []\n }\n}\n"],"mappings":";;;;;;AAGA,SAAgB,YAAY,EAAE,YAA4C;AACxE,KAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;CAE/C,MAAM,QAAQ,SACX,SAAS,MAAM,OAAO,iCAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,CAC9C,KAAK,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC,QAAQ,OAAO,GAAG,CAAC,CACzD,QAAQ,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;AAErC,KAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,QAAO;EAAC;EAAO,GAAG,MAAM,KAAK,MAAM,MAAM,IAAI;EAAE;EAAM,CAAC,KAAK,KAAK;;;;;;;;;;ACPlE,IAAa,gBAAb,MAA2B;;2CACM,EAAE;;;;;CAKjC,IAAI,MAA2B;AAC7B,sCAAW,CAAC,KAAK,KAAK;;;;;CAMxB,IAAI,QAA8B;AAChC,SAAO,CAAC,kCAAG,KAAW,CAAC;;;;;CAMzB,QAAc;AACZ,uCAAc,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.0.0-canary-20260111130736",
3
+ "version": "0.0.0-canary-20260113205926",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -42,6 +42,10 @@
42
42
  "require": "./dist/types.cjs",
43
43
  "import": "./dist/types.js"
44
44
  },
45
+ "./utils": {
46
+ "require": "./dist/utils.cjs",
47
+ "import": "./dist/utils.js"
48
+ },
45
49
  "./package.json": "./package.json"
46
50
  },
47
51
  "main": "./dist/index.cjs",
@@ -58,6 +62,9 @@
58
62
  "plugins": [
59
63
  "./dist/plugins.d.ts"
60
64
  ],
65
+ "utils": [
66
+ "./dist/utils.d.ts"
67
+ ],
61
68
  "types": [
62
69
  "./dist/types.d.ts"
63
70
  ]
@@ -0,0 +1,15 @@
1
+ import { inject } from '../context.ts'
2
+ import { AppContext, type AppContextProps } from '../contexts/AppContext.ts'
3
+
4
+ /**
5
+ * `useApp` will return the current App with meta and exit function.
6
+ */
7
+ export function useApp<TMeta = unknown>(): AppContextProps<TMeta> {
8
+ const app = inject(AppContext, undefined)
9
+
10
+ if (!app) {
11
+ throw new Error('App context should be provided')
12
+ }
13
+
14
+ return app as AppContextProps<TMeta>
15
+ }
@@ -0,0 +1,16 @@
1
+ import type { Context } from '../context.ts'
2
+ import { inject } from '../context.ts'
3
+
4
+ /**
5
+ * React-style alias for inject
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const theme = useContext(ThemeContext) // type is inferred from ThemeContext
10
+ * ```
11
+ */
12
+ export function useContext<T>(key: Context<T>): T
13
+ export function useContext<T>(key: Context<T>, defaultValue: T): T
14
+ export function useContext<T>(key: Context<T>, defaultValue?: T): T {
15
+ return inject(key, defaultValue)
16
+ }
@@ -0,0 +1,16 @@
1
+ import { inject } from '../context.ts'
2
+ import { FileCollectorContext } from '../contexts/FileCollectorContext.ts'
3
+ import type { FileCollector } from '../utils/FileCollector.ts'
4
+
5
+ /**
6
+ * `useFile` will return the current FileCollector for registering files.
7
+ */
8
+ export function useFile(): FileCollector {
9
+ const collector = inject(FileCollectorContext, null)
10
+
11
+ if (!collector) {
12
+ throw new Error('No FileCollector found in context. Make sure you are using a Fabric that provides a FileCollector.')
13
+ }
14
+
15
+ return collector
16
+ }
@@ -0,0 +1,13 @@
1
+ import { inject } from '../context.ts'
2
+ import { RootContext } from '../contexts/RootContext.ts'
3
+
4
+ /**
5
+ * `useLifecycle` will return some helpers to exit/restart the generation.
6
+ */
7
+ export function useLifecycle() {
8
+ const { exit } = inject(RootContext, { exit: () => {} })
9
+
10
+ return {
11
+ exit,
12
+ }
13
+ }
package/src/context.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Context type that carries type information about its value
3
+ * This is a branded symbol type that enables type-safe context usage
4
+ */
5
+ export type Context<T> = symbol & { readonly __type: T }
6
+
7
+ /**
8
+ * Context stack for tracking the current context values
9
+ *
10
+ * Note: This uses a global Map for simplicity in code generation scenarios.
11
+ * For concurrent runtime execution, consider using AsyncLocalStorage or
12
+ * instance-based context management.
13
+ */
14
+ const contextStack = new Map<symbol, unknown[]>()
15
+ const contextDefaults = new Map<symbol, unknown>()
16
+
17
+ /**
18
+ * Provides a value to descendant components (Vue 3 style)
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const ThemeKey = Symbol('theme')
23
+ * provide(ThemeKey, { color: 'blue' })
24
+ * ```
25
+ */
26
+ export function provide<T>(key: symbol | Context<T>, value: T): void {
27
+ if (!contextStack.has(key)) {
28
+ contextStack.set(key, [])
29
+ }
30
+ contextStack.get(key)!.push(value)
31
+ }
32
+
33
+ /**
34
+ * Injects a value provided by an ancestor component (Vue 3 style)
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const theme = inject(ThemeKey, { color: 'default' })
39
+ * ```
40
+ */
41
+ export function inject<T>(key: symbol | Context<T>, defaultValue?: T): T {
42
+ const stack = contextStack.get(key)
43
+ if (!stack || stack.length === 0) {
44
+ if (defaultValue !== undefined) {
45
+ return defaultValue
46
+ }
47
+ const storedDefault = contextDefaults.get(key)
48
+ if (storedDefault !== undefined) {
49
+ return storedDefault as T
50
+ }
51
+ throw new Error(`No value provided for key: ${key.toString()}`)
52
+ }
53
+ return stack[stack.length - 1] as T
54
+ }
55
+
56
+ /**
57
+ * Unprovides a value (for cleanup)
58
+ * @internal
59
+ */
60
+ export function unprovide<T>(key: symbol | Context<T>): void {
61
+ const stack = contextStack.get(key)
62
+ if (stack && stack.length > 0) {
63
+ stack.pop()
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Creates a context key with a default value (React-style compatibility)
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const ThemeContext = createContext({ color: 'blue' })
73
+ * // ThemeContext is now typed as Context<{ color: string }>
74
+ * const theme = useContext(ThemeContext) // theme is { color: string }
75
+ * ```
76
+ */
77
+ export function createContext<T>(defaultValue: T): Context<T> {
78
+ const key = Symbol('context') as Context<T>
79
+ contextDefaults.set(key, defaultValue)
80
+
81
+ return key
82
+ }
@@ -0,0 +1,11 @@
1
+ import { createContext } from '../context.ts'
2
+
3
+ export type AppContextProps<TMeta = unknown> = {
4
+ /**
5
+ * Exit (unmount)
6
+ */
7
+ readonly exit: (error?: Error) => void
8
+ readonly meta: TMeta
9
+ }
10
+
11
+ export const AppContext = createContext<AppContextProps | undefined>(undefined)
@@ -0,0 +1,18 @@
1
+ import { createContext } from '../context.ts'
2
+ import type * as KubbFile from '../KubbFile.ts'
3
+ import type { FileCollector } from '../utils/FileCollector.ts'
4
+
5
+ /**
6
+ * Context for collecting files - provided by createFsxFabric
7
+ */
8
+ export const FileCollectorContext = createContext<FileCollector | null>(null)
9
+
10
+ /**
11
+ * Context for the current file being processed
12
+ */
13
+ type CurrentFileContext = {
14
+ sources: KubbFile.Source[]
15
+ imports: KubbFile.Import[]
16
+ exports: KubbFile.Export[]
17
+ }
18
+ export const CurrentFileContext = createContext<CurrentFileContext | null>(null)
@@ -0,0 +1,12 @@
1
+ import { createContext } from '../context.ts'
2
+
3
+ export type RootContextProps = {
4
+ /**
5
+ * Exit (unmount) the whole app.
6
+ */
7
+ readonly exit: (error?: Error) => void
8
+ }
9
+
10
+ export const RootContext = createContext<RootContextProps>({
11
+ exit: () => {},
12
+ })
package/src/index.ts CHANGED
@@ -1,3 +1,13 @@
1
+ export { useApp } from './composables/useApp.ts'
2
+ export { useContext } from './composables/useContext.ts'
3
+ export { useFile } from './composables/useFile.ts'
4
+ export { useLifecycle } from './composables/useLifecycle.ts'
5
+ // context api
6
+ export type { Context } from './context.ts'
7
+ export { createContext, inject, provide, unprovide } from './context.ts'
8
+ export { AppContext } from './contexts/AppContext.ts'
9
+ export { FileCollectorContext } from './contexts/FileCollectorContext.ts'
10
+ export { RootContext } from './contexts/RootContext.ts'
1
11
  export { createFabric } from './createFabric.ts'
2
12
  export { createFile } from './createFile.ts'
3
13
  // we need this to override the globals of `fabric.use`
@@ -0,0 +1,30 @@
1
+ import type * as KubbFile from '../KubbFile.ts'
2
+
3
+ /**
4
+ * FileCollector is used to collect files from components via context
5
+ * instead of walking the DOM tree.
6
+ */
7
+ export class FileCollector {
8
+ #files: Array<KubbFile.File> = []
9
+
10
+ /**
11
+ * Add a file to the collector
12
+ */
13
+ add(file: KubbFile.File): void {
14
+ this.#files.push(file)
15
+ }
16
+
17
+ /**
18
+ * Get all collected files
19
+ */
20
+ get files(): Array<KubbFile.File> {
21
+ return [...this.#files]
22
+ }
23
+
24
+ /**
25
+ * Clear all collected files
26
+ */
27
+ clear(): void {
28
+ this.#files = []
29
+ }
30
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Create JSDoc comment block from comments array
3
+ */
4
+ export function createJSDoc({ comments }: { comments: string[] }): string {
5
+ if (!comments || comments.length === 0) return ''
6
+
7
+ const lines = comments
8
+ .flatMap((c) => String(c ?? '').split(/\r?\n/))
9
+ .map((l) => l.replace(/\*\//g, '*\\/').replace(/\r/g, ''))
10
+ .filter((l) => l.trim().length > 0)
11
+
12
+ if (lines.length === 0) return ''
13
+
14
+ return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\n')
15
+ }
@@ -0,0 +1,2 @@
1
+ export { createJSDoc } from './createJSDoc.ts'
2
+ export { FileCollector } from './FileCollector.ts'