@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.
- package/README.md +21 -23
- package/dist/{Fabric-BzIhBn8t.d.cts → Fabric-CtqeUUFU.d.ts} +24 -25
- package/dist/{Fabric-igvWKffO.d.ts → Fabric-DlBN6CDR.d.cts} +24 -25
- package/dist/{defaultParser-n9VW2iVf.cjs → defaultParser-CIF-0xIK.cjs} +3 -3
- package/dist/{defaultParser-n9VW2iVf.cjs.map → defaultParser-CIF-0xIK.cjs.map} +1 -1
- package/dist/{defaultParser-Csot2aaT.js → defaultParser-DPHcM2NR.js} +3 -3
- package/dist/{defaultParser-Csot2aaT.js.map → defaultParser-DPHcM2NR.js.map} +1 -1
- package/dist/defineParser-Bxv4mb-N.js +11 -0
- package/dist/{createParser-D_ANHZTa.js.map → defineParser-Bxv4mb-N.js.map} +1 -1
- package/dist/defineParser-DODGK4rM.cjs +17 -0
- package/dist/{createParser-C4IkyTs5.cjs.map → defineParser-DODGK4rM.cjs.map} +1 -1
- package/dist/index.cjs +75 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/index.js +76 -85
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.cjs +2 -2
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers/typescript.js +2 -2
- package/dist/parsers.cjs +5 -5
- package/dist/parsers.cjs.map +1 -1
- package/dist/parsers.d.cts +6 -6
- package/dist/parsers.d.ts +6 -6
- package/dist/parsers.js +5 -5
- package/dist/parsers.js.map +1 -1
- package/dist/plugins.cjs +36 -36
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +4 -4
- package/dist/plugins.d.ts +4 -4
- package/dist/plugins.js +36 -36
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{typescriptParser-BN1vEX-I.d.ts → typescriptParser-BAlwCe3a.d.ts} +2 -2
- package/dist/{typescriptParser-Cw2wm0gX.js → typescriptParser-BLX7eX2k.js} +3 -3
- package/dist/{typescriptParser-Cw2wm0gX.js.map → typescriptParser-BLX7eX2k.js.map} +1 -1
- package/dist/{typescriptParser-BlRK18rx.d.cts → typescriptParser-CnzxSeDN.d.cts} +2 -2
- package/dist/{typescriptParser-DRdx9q2o.cjs → typescriptParser-OjFZ_DeI.cjs} +3 -3
- package/dist/{typescriptParser-DRdx9q2o.cjs.map → typescriptParser-OjFZ_DeI.cjs.map} +1 -1
- package/package.json +1 -1
- package/src/Fabric.ts +28 -24
- package/src/FileManager.ts +6 -6
- package/src/FileProcessor.ts +5 -5
- package/src/createFabric.ts +96 -2
- package/src/index.ts +0 -1
- package/src/parsers/defaultParser.ts +2 -2
- package/src/parsers/{createParser.ts → defineParser.ts} +1 -1
- package/src/parsers/index.ts +1 -2
- package/src/parsers/tsxParser.ts +2 -2
- package/src/parsers/typescriptParser.ts +2 -2
- package/src/plugins/barrelPlugin.ts +3 -3
- package/src/plugins/{createPlugin.ts → definePlugin.ts} +1 -1
- package/src/plugins/fsPlugin.ts +3 -3
- package/src/plugins/graphPlugin.ts +3 -3
- package/src/plugins/index.ts +1 -1
- package/src/plugins/loggerPlugin.ts +41 -31
- package/dist/createParser-C4IkyTs5.cjs +0 -17
- package/dist/createParser-D_ANHZTa.js +0 -11
- package/src/defineFabric.ts +0 -119
package/src/defineFabric.ts
DELETED
|
@@ -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
|
-
}
|