@kubb/fabric-core 0.5.4 → 0.5.5

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 (61) hide show
  1. package/README.md +21 -23
  2. package/dist/{Fabric-BzIhBn8t.d.cts → Fabric-CtqeUUFU.d.ts} +24 -25
  3. package/dist/{Fabric-igvWKffO.d.ts → Fabric-DlBN6CDR.d.cts} +24 -25
  4. package/dist/{defaultParser-n9VW2iVf.cjs → defaultParser-CIF-0xIK.cjs} +3 -3
  5. package/dist/{defaultParser-n9VW2iVf.cjs.map → defaultParser-CIF-0xIK.cjs.map} +1 -1
  6. package/dist/{defaultParser-Csot2aaT.js → defaultParser-DPHcM2NR.js} +3 -3
  7. package/dist/{defaultParser-Csot2aaT.js.map → defaultParser-DPHcM2NR.js.map} +1 -1
  8. package/dist/defineParser-Bxv4mb-N.js +11 -0
  9. package/dist/{createParser-D_ANHZTa.js.map → defineParser-Bxv4mb-N.js.map} +1 -1
  10. package/dist/defineParser-DODGK4rM.cjs +17 -0
  11. package/dist/{createParser-C4IkyTs5.cjs.map → defineParser-DODGK4rM.cjs.map} +1 -1
  12. package/dist/index.cjs +75 -85
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +7 -22
  15. package/dist/index.d.ts +7 -22
  16. package/dist/index.js +76 -85
  17. package/dist/index.js.map +1 -1
  18. package/dist/parsers/typescript.cjs +2 -2
  19. package/dist/parsers/typescript.d.cts +2 -2
  20. package/dist/parsers/typescript.d.ts +2 -2
  21. package/dist/parsers/typescript.js +2 -2
  22. package/dist/parsers.cjs +5 -5
  23. package/dist/parsers.cjs.map +1 -1
  24. package/dist/parsers.d.cts +6 -6
  25. package/dist/parsers.d.ts +6 -6
  26. package/dist/parsers.js +5 -5
  27. package/dist/parsers.js.map +1 -1
  28. package/dist/plugins.cjs +36 -36
  29. package/dist/plugins.cjs.map +1 -1
  30. package/dist/plugins.d.cts +4 -4
  31. package/dist/plugins.d.ts +4 -4
  32. package/dist/plugins.js +36 -36
  33. package/dist/plugins.js.map +1 -1
  34. package/dist/types.d.cts +1 -1
  35. package/dist/types.d.ts +1 -1
  36. package/dist/{typescriptParser-BN1vEX-I.d.ts → typescriptParser-BAlwCe3a.d.ts} +2 -2
  37. package/dist/{typescriptParser-Cw2wm0gX.js → typescriptParser-BLX7eX2k.js} +3 -3
  38. package/dist/{typescriptParser-Cw2wm0gX.js.map → typescriptParser-BLX7eX2k.js.map} +1 -1
  39. package/dist/{typescriptParser-BlRK18rx.d.cts → typescriptParser-CnzxSeDN.d.cts} +2 -2
  40. package/dist/{typescriptParser-DRdx9q2o.cjs → typescriptParser-OjFZ_DeI.cjs} +3 -3
  41. package/dist/{typescriptParser-DRdx9q2o.cjs.map → typescriptParser-OjFZ_DeI.cjs.map} +1 -1
  42. package/package.json +1 -1
  43. package/src/Fabric.ts +28 -24
  44. package/src/FileManager.ts +6 -6
  45. package/src/FileProcessor.ts +5 -5
  46. package/src/createFabric.ts +96 -2
  47. package/src/index.ts +0 -1
  48. package/src/parsers/defaultParser.ts +2 -2
  49. package/src/parsers/{createParser.ts → defineParser.ts} +1 -1
  50. package/src/parsers/index.ts +1 -2
  51. package/src/parsers/tsxParser.ts +2 -2
  52. package/src/parsers/typescriptParser.ts +2 -2
  53. package/src/plugins/barrelPlugin.ts +3 -3
  54. package/src/plugins/{createPlugin.ts → definePlugin.ts} +1 -1
  55. package/src/plugins/fsPlugin.ts +3 -3
  56. package/src/plugins/graphPlugin.ts +3 -3
  57. package/src/plugins/index.ts +1 -1
  58. package/src/plugins/loggerPlugin.ts +41 -31
  59. package/dist/createParser-C4IkyTs5.cjs +0 -17
  60. package/dist/createParser-D_ANHZTa.js +0 -11
  61. package/src/defineFabric.ts +0 -119
@@ -1,119 +0,0 @@
1
- import { isFunction } from 'remeda'
2
- import type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'
3
- import { FileManager } from './FileManager.ts'
4
- import type * as KubbFile from './KubbFile.ts'
5
- import type { Parser } from './parsers/types.ts'
6
- import type { Plugin } from './plugins/types.ts'
7
- import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
8
-
9
- /**
10
- * Function that initializes the root Fabric instance.
11
- *
12
- * Used for setting up plugins, parsers, or performing side effects
13
- * once the Fabric context is ready.
14
- */
15
- type FabricInitializer<T extends FabricOptions> = (fabric: Fabric<T>) => void | Promise<void>
16
-
17
- /**
18
- * A function returned by {@link defineFabric} that creates a Fabric instance.
19
- */
20
- export type CreateFabric<T extends FabricOptions> = (config?: FabricConfig<T>) => Fabric<T>
21
-
22
- /**
23
- * Defines a new Fabric factory function.
24
- *
25
- * @example
26
- * export const createFabric = defineFabric((fabric) => {
27
- * fabric.use(myPlugin())
28
- * })
29
- */
30
- export function defineFabric<T extends FabricOptions>(init?: FabricInitializer<T>): CreateFabric<T> {
31
- function create(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {
32
- const events = new AsyncEventEmitter<FabricEvents>()
33
- const installedPlugins = new Set<Plugin<any>>()
34
- const installedParsers = new Map<KubbFile.Extname, Parser<any>>()
35
- const installedParserNames = new Set<string>()
36
- const fileManager = new FileManager({ events })
37
-
38
- const context: FabricContext<T> = {
39
- get files() {
40
- return fileManager.files
41
- },
42
- async addFile(...files) {
43
- await fileManager.add(...files)
44
- },
45
- config,
46
- fileManager,
47
- installedPlugins,
48
- installedParsers,
49
- on: events.on.bind(events),
50
- off: events.off.bind(events),
51
- onOnce: events.onOnce.bind(events),
52
- removeAll: events.removeAll.bind(events),
53
- emit: events.emit.bind(events),
54
- } as FabricContext<T>
55
-
56
- const fabric: Fabric<T> = {
57
- context,
58
- get files() {
59
- return fileManager.files
60
- },
61
- async addFile(...files) {
62
- await fileManager.add(...files)
63
- },
64
- async upsertFile(...files) {
65
- await fileManager.upsert(...files)
66
- },
67
- async use(pluginOrParser, ...options) {
68
- if (pluginOrParser.type === 'plugin') {
69
- if (installedPlugins.has(pluginOrParser)) {
70
- console.warn(`Plugin "${pluginOrParser.name}" already applied.`)
71
- } else {
72
- installedPlugins.add(pluginOrParser)
73
- }
74
-
75
- if (isFunction(pluginOrParser.inject)) {
76
- const injecter = pluginOrParser.inject
77
-
78
- const injected = (injecter as any)(context, ...options)
79
- Object.assign(fabric, injected)
80
- }
81
- }
82
-
83
- if (pluginOrParser.type === 'parser') {
84
- if (installedParserNames.has(pluginOrParser.name)) {
85
- console.warn(`Parser "${pluginOrParser.name}" already applied.`)
86
- } else {
87
- installedParserNames.add(pluginOrParser.name)
88
- }
89
-
90
- if (pluginOrParser.extNames) {
91
- for (const extName of pluginOrParser.extNames) {
92
- const existing = installedParsers.get(extName)
93
- if (existing && existing.name !== pluginOrParser.name) {
94
- console.warn(`Parser "${pluginOrParser.name}" is overriding parser "${existing.name}" for extension "${extName}".`)
95
- }
96
- installedParsers.set(extName, pluginOrParser)
97
- }
98
- }
99
- }
100
-
101
- if (isFunction(pluginOrParser.install)) {
102
- const installer = pluginOrParser.install
103
-
104
- await (installer as any)(context, ...options)
105
- }
106
-
107
- return fabric
108
- },
109
- } as Fabric<T>
110
-
111
- if (init) {
112
- init(fabric)
113
- }
114
-
115
- return fabric
116
- }
117
-
118
- return create
119
- }