@kubb/fabric-core 0.9.5 → 0.10.0

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 (43) hide show
  1. package/dist/{Fabric-BXYWK9V4.d.cts → Fabric-BwLKB57c.d.ts} +2 -2
  2. package/dist/{Fabric-CDFwTDyP.d.ts → Fabric-DmNaPvSq.d.cts} +2 -2
  3. package/dist/{defineProperty-hUmuXj5B.cjs → defineProperty-Cs9FivAD.cjs} +36 -36
  4. package/dist/{defineProperty-hUmuXj5B.cjs.map → defineProperty-Cs9FivAD.cjs.map} +1 -1
  5. package/dist/{defineProperty-CS9Uk_6Q.js → defineProperty-DfrsyklJ.js} +37 -37
  6. package/dist/{defineProperty-CS9Uk_6Q.js.map → defineProperty-DfrsyklJ.js.map} +1 -1
  7. package/dist/index.cjs +397 -2
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +410 -4
  10. package/dist/index.d.ts +410 -4
  11. package/dist/index.js +379 -3
  12. package/dist/index.js.map +1 -1
  13. package/dist/parsers/typescript.d.cts +1 -1
  14. package/dist/parsers/typescript.d.ts +1 -1
  15. package/dist/parsers.d.cts +1 -1
  16. package/dist/parsers.d.ts +1 -1
  17. package/dist/plugins.cjs +1 -1
  18. package/dist/plugins.d.cts +1 -1
  19. package/dist/plugins.d.ts +1 -1
  20. package/dist/plugins.js +1 -1
  21. package/dist/types-B1GXvvBG.d.ts +7 -0
  22. package/dist/types-zKAit5TK.d.cts +7 -0
  23. package/dist/types.d.cts +3 -2
  24. package/dist/types.d.ts +3 -2
  25. package/package.json +1 -1
  26. package/src/components/App.ts +38 -0
  27. package/src/components/Const.ts +56 -0
  28. package/src/components/File.ts +79 -0
  29. package/src/components/Function.ts +171 -0
  30. package/src/components/Root.ts +36 -0
  31. package/src/components/Type.ts +45 -0
  32. package/src/composables/useApp.ts +17 -0
  33. package/src/composables/useContext.ts +16 -0
  34. package/src/composables/useFile.ts +19 -0
  35. package/src/composables/useLifecycle.ts +16 -0
  36. package/src/context.ts +82 -0
  37. package/src/contexts/AppContext.ts +15 -0
  38. package/src/contexts/FileCollectorContext.ts +18 -0
  39. package/src/contexts/RootContext.ts +16 -0
  40. package/src/index.ts +26 -0
  41. package/src/types.ts +5 -0
  42. package/src/utils/FileCollector.ts +30 -0
  43. package/src/utils/createJSDoc.ts +15 -0
package/dist/index.cjs CHANGED
@@ -1,12 +1,388 @@
1
1
  const require_trimExtName = require('./trimExtName-DaBSwMN-.cjs');
2
- const require_defineProperty = require('./defineProperty-hUmuXj5B.cjs');
2
+ const require_defineProperty = require('./defineProperty-Cs9FivAD.cjs');
3
3
  const require_defaultParser = require('./defaultParser-CIF-0xIK.cjs');
4
4
  let natural_orderby = require("natural-orderby");
5
5
  let p_limit = require("p-limit");
6
6
  p_limit = require_trimExtName.__toESM(p_limit);
7
7
  let node_events = require("node:events");
8
8
 
9
- //#region ../../node_modules/.pnpm/remeda@2.33.1/node_modules/remeda/dist/isFunction.js
9
+ //#region src/context.ts
10
+ /**
11
+ * Context stack for tracking the current context values
12
+ *
13
+ * Note: This uses a global Map for simplicity in code generation scenarios.
14
+ * For concurrent runtime execution, consider using AsyncLocalStorage or
15
+ * instance-based context management.
16
+ */
17
+ const contextStack = /* @__PURE__ */ new Map();
18
+ const contextDefaults = /* @__PURE__ */ new Map();
19
+ /**
20
+ * Provides a value to descendant components (Vue 3 style)
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const ThemeKey = Symbol('theme')
25
+ * provide(ThemeKey, { color: 'blue' })
26
+ * ```
27
+ */
28
+ function provide(key, value) {
29
+ if (!contextStack.has(key)) contextStack.set(key, []);
30
+ contextStack.get(key).push(value);
31
+ }
32
+ /**
33
+ * Injects a value provided by an ancestor component (Vue 3 style)
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const theme = inject(ThemeKey, { color: 'default' })
38
+ * ```
39
+ */
40
+ function inject(key, defaultValue) {
41
+ const stack = contextStack.get(key);
42
+ if (!stack || stack.length === 0) {
43
+ if (defaultValue !== void 0) return defaultValue;
44
+ const storedDefault = contextDefaults.get(key);
45
+ if (storedDefault !== void 0) return storedDefault;
46
+ throw new Error(`No value provided for key: ${key.toString()}`);
47
+ }
48
+ return stack[stack.length - 1];
49
+ }
50
+ /**
51
+ * Unprovides a value (for cleanup)
52
+ * @internal
53
+ */
54
+ function unprovide(key) {
55
+ const stack = contextStack.get(key);
56
+ if (stack && stack.length > 0) stack.pop();
57
+ }
58
+ /**
59
+ * Creates a context key with a default value (React-style compatibility)
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const ThemeContext = createContext({ color: 'blue' })
64
+ * // ThemeContext is now typed as Context<{ color: string }>
65
+ * const theme = useContext(ThemeContext) // theme is { color: string }
66
+ * ```
67
+ */
68
+ function createContext(defaultValue) {
69
+ const key = Symbol("context");
70
+ contextDefaults.set(key, defaultValue);
71
+ return key;
72
+ }
73
+
74
+ //#endregion
75
+ //#region src/composables/useContext.ts
76
+ function useContext(key, defaultValue) {
77
+ return inject(key, defaultValue);
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/contexts/RootContext.ts
82
+ /**
83
+ * Provides a top-level lifecycle hook (`exit`) for terminating the Fabric
84
+ * runtime. This context is available at the root of a Fabric app.
85
+ */
86
+ const RootContext = createContext({ exit: () => {} });
87
+
88
+ //#endregion
89
+ //#region src/components/App.ts
90
+ const AppContext$1 = createContext(void 0);
91
+ /**
92
+ * Minimal fsx app container — provides an AppContext carrying `meta` and an
93
+ * `exit` hook. In fsx mode this just returns children content.
94
+ */
95
+ function App({ children, meta }) {
96
+ const { exit } = useContext(RootContext);
97
+ provide(AppContext$1, {
98
+ exit,
99
+ meta
100
+ });
101
+ return children || "";
102
+ }
103
+ App.Context = AppContext$1;
104
+ App.displayName = "KubbApp";
105
+
106
+ //#endregion
107
+ //#region src/utils/createJSDoc.ts
108
+ /**
109
+ * Create JSDoc comment block from comments array
110
+ */
111
+ function createJSDoc({ comments }) {
112
+ if (!comments || comments.length === 0) return "";
113
+ const lines = comments.flatMap((c) => String(c !== null && c !== void 0 ? c : "").split(/\r?\n/)).map((l) => l.replace(/\*\//g, "*\\/").replace(/\r/g, "")).filter((l) => l.trim().length > 0);
114
+ if (lines.length === 0) return "";
115
+ return [
116
+ "/**",
117
+ ...lines.map((l) => ` * ${l}`),
118
+ " */"
119
+ ].join("\n");
120
+ }
121
+
122
+ //#endregion
123
+ //#region src/components/Const.ts
124
+ function Const({ name, export: canExport, type, JSDoc, asConst, children }) {
125
+ let result = "";
126
+ if (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) {
127
+ result += createJSDoc({ comments: JSDoc.comments });
128
+ result += "\n";
129
+ }
130
+ if (canExport) result += "export ";
131
+ result += `const ${name}`;
132
+ if (type) result += `: ${type}`;
133
+ result += ` = ${children || ""}`;
134
+ if (asConst) result += " as const";
135
+ return result;
136
+ }
137
+ Const.displayName = "KubbConst";
138
+
139
+ //#endregion
140
+ //#region src/contexts/FileCollectorContext.ts
141
+ /**
142
+ * Context for collecting files - provided by createFsxFabric
143
+ */
144
+ const FileCollectorContext = createContext(null);
145
+ const CurrentFileContext = createContext(null);
146
+
147
+ //#endregion
148
+ //#region src/utils/FileCollector.ts
149
+ var _files = /* @__PURE__ */ new WeakMap();
150
+ /**
151
+ * FileCollector is used to collect files from components via context
152
+ * instead of walking the DOM tree.
153
+ */
154
+ var FileCollector = class {
155
+ constructor() {
156
+ require_defineProperty._classPrivateFieldInitSpec(this, _files, []);
157
+ }
158
+ /**
159
+ * Add a file to the collector
160
+ */
161
+ add(file) {
162
+ require_defineProperty._classPrivateFieldGet2(_files, this).push(file);
163
+ }
164
+ /**
165
+ * Get all collected files
166
+ */
167
+ get files() {
168
+ return [...require_defineProperty._classPrivateFieldGet2(_files, this)];
169
+ }
170
+ /**
171
+ * Clear all collected files
172
+ */
173
+ clear() {
174
+ require_defineProperty._classPrivateFieldSet2(_files, this, []);
175
+ }
176
+ };
177
+
178
+ //#endregion
179
+ //#region src/components/File.ts
180
+ /**
181
+ * File component for fsx - registers files via context
182
+ *
183
+ * When executed this will create or reuse a FileCollector from context and
184
+ * register the file (baseName/path) so it can be emitted later. Returns the
185
+ * children string content for fsx renderers.
186
+ */
187
+ function File({ children, ...rest }) {
188
+ const collector = useContext(FileCollectorContext, new FileCollector());
189
+ provide(FileCollectorContext, collector);
190
+ collector.add({
191
+ baseName: rest.baseName,
192
+ path: rest.path,
193
+ meta: rest.meta || {},
194
+ banner: rest.banner,
195
+ footer: rest.footer,
196
+ sources: [],
197
+ imports: [],
198
+ exports: []
199
+ });
200
+ return children || "";
201
+ }
202
+ /**
203
+ * FileSource - for adding source code to a file
204
+ *
205
+ * Returns the provided children string so the fsx renderer can collect it.
206
+ */
207
+ function FileSource(props) {
208
+ return props.children || "";
209
+ }
210
+ /**
211
+ * FileExport - for adding exports to a file
212
+ *
213
+ * No-op function used by renderers to record exports.
214
+ */
215
+ function FileExport(_props) {
216
+ return "";
217
+ }
218
+ /**
219
+ * FileImport - for adding imports to a file
220
+ *
221
+ * No-op function used by renderers to record imports.
222
+ */
223
+ function FileImport(_props) {
224
+ return "";
225
+ }
226
+ File.Source = FileSource;
227
+ File.Import = FileImport;
228
+ File.Export = FileExport;
229
+
230
+ //#endregion
231
+ //#region src/components/Function.ts
232
+ /**
233
+ * Builds a function declaration string for the fsx renderer. Supports optional
234
+ * export/default/async flags, generics, params and JSDoc rendering.
235
+ */
236
+ function Function({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, children }) {
237
+ const parts = [];
238
+ if (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) {
239
+ parts.push(createJSDoc({ comments: JSDoc.comments }));
240
+ parts.push("\n");
241
+ }
242
+ if (canExport) parts.push("export ");
243
+ if (isDefault) parts.push("default ");
244
+ if (async) parts.push("async ");
245
+ parts.push(`function ${name}`);
246
+ if (generics) {
247
+ parts.push("<");
248
+ parts.push(Array.isArray(generics) ? generics.join(", ").trim() : generics);
249
+ parts.push(">");
250
+ }
251
+ parts.push(`(${params || ""})`);
252
+ if (returnType && !async) parts.push(`: ${returnType}`);
253
+ if (returnType && async) parts.push(`: Promise<${returnType}>`);
254
+ parts.push(" {");
255
+ if (children) return `${parts.join("")}
256
+ ${children}
257
+ }`;
258
+ return `${parts.join("")}}`;
259
+ }
260
+ Function.displayName = "KubbFunction";
261
+ /**
262
+ * ArrowFunction
263
+ *
264
+ * Builds an arrow function declaration string for the fsx renderer. Supports
265
+ * the same options as `Function`. Use `singleLine` to produce a one-line
266
+ * arrow expression.
267
+ */
268
+ function ArrowFunction({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine, children }) {
269
+ const parts = [];
270
+ if (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) {
271
+ parts.push(createJSDoc({ comments: JSDoc.comments }));
272
+ parts.push("\n");
273
+ }
274
+ if (canExport) parts.push("export ");
275
+ if (isDefault) parts.push("default ");
276
+ parts.push(`const ${name} = `);
277
+ if (async) parts.push("async ");
278
+ if (generics) {
279
+ parts.push("<");
280
+ parts.push(Array.isArray(generics) ? generics.join(", ").trim() : generics);
281
+ parts.push(">");
282
+ }
283
+ parts.push(`(${params || ""})`);
284
+ if (returnType && !async) parts.push(`: ${returnType}`);
285
+ if (returnType && async) parts.push(`: Promise<${returnType}>`);
286
+ if (singleLine) {
287
+ parts.push(` => ${children || ""}\n`);
288
+ return parts.join("");
289
+ }
290
+ if (children) return `${parts.join("")} => {
291
+ ${children}
292
+ }
293
+ `;
294
+ return `${parts.join("")} => {}\n`;
295
+ }
296
+ ArrowFunction.displayName = "KubbArrowFunction";
297
+ Function.Arrow = ArrowFunction;
298
+
299
+ //#endregion
300
+ //#region src/components/Root.ts
301
+ /**
302
+ * Top-level root for fsx renderers. Returns children content and ensures
303
+ * `onError` is called for runtime exceptions. Provides a RootContext with
304
+ * an `exit` hook for downstream consumers.
305
+ */
306
+ function Root({ onError, children }) {
307
+ provide(RootContext, { exit: () => {} });
308
+ try {
309
+ return children || "";
310
+ } catch (e$1) {
311
+ if (e$1 instanceof Error) onError(e$1);
312
+ return "";
313
+ }
314
+ }
315
+ Root.displayName = "KubbRoot";
316
+
317
+ //#endregion
318
+ //#region src/components/Type.ts
319
+ /**
320
+ * Renders a TypeScript type alias string for use with the fsx renderer.
321
+ * Optionally emits JSDoc comments when `JSDoc.comments` is provided.
322
+ */
323
+ function Type({ name, export: canExport, JSDoc, children }) {
324
+ if (name.charAt(0).toUpperCase() !== name.charAt(0)) throw new Error("Name should start with a capital letter (see TypeScript types)");
325
+ let result = "";
326
+ if (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) {
327
+ result += createJSDoc({ comments: JSDoc.comments });
328
+ result += "\n";
329
+ }
330
+ if (canExport) result += "export ";
331
+ result += `type ${name} = ${children || ""}`;
332
+ return result;
333
+ }
334
+ Type.displayName = "KubbType";
335
+
336
+ //#endregion
337
+ //#region src/contexts/AppContext.ts
338
+ /**
339
+ * Provides app-level metadata and lifecycle hooks (like `exit`) to
340
+ * components and composables within a Fabric runtime.
341
+ */
342
+ const AppContext = createContext(void 0);
343
+
344
+ //#endregion
345
+ //#region src/composables/useApp.ts
346
+ /**
347
+ * `useApp` will return the current App with meta and exit function.
348
+ *
349
+ * Throws an error when there is no AppContext available.
350
+ */
351
+ function useApp() {
352
+ const app = useContext(AppContext, void 0);
353
+ if (!app) throw new Error("App context should be provided");
354
+ return app;
355
+ }
356
+
357
+ //#endregion
358
+ //#region src/composables/useFile.ts
359
+ /**
360
+ * `useFile` will return the current FileCollector for registering files.
361
+ *
362
+ * Throws when no FileCollector is present in context — ensure a Fabric that
363
+ * provides a FileCollector is mounted before calling this hook.
364
+ */
365
+ function useFile() {
366
+ const collector = useContext(FileCollectorContext, null);
367
+ if (!collector) throw new Error("No FileCollector found in context. Make sure you are using a Fabric that provides a FileCollector.");
368
+ return collector;
369
+ }
370
+
371
+ //#endregion
372
+ //#region src/composables/useLifecycle.ts
373
+ /**
374
+ * `useLifecycle` will return some helpers to exit/restart the generation.
375
+ *
376
+ * This hook reads the RootContext and exposes lifecycle helpers (like `exit`)
377
+ * for consumers to programmatically stop generation or perform teardown.
378
+ */
379
+ function useLifecycle() {
380
+ const { exit } = useContext(RootContext, { exit: () => {} });
381
+ return { exit };
382
+ }
383
+
384
+ //#endregion
385
+ //#region ../../node_modules/.pnpm/remeda@2.33.2/node_modules/remeda/dist/isFunction.js
10
386
  const e = (e$1) => typeof e$1 == `function`;
11
387
 
12
388
  //#endregion
@@ -332,8 +708,27 @@ function createFabric(config = { mode: "sequential" }) {
332
708
  }
333
709
 
334
710
  //#endregion
711
+ exports.App = App;
712
+ exports.AppContext = AppContext;
713
+ exports.Const = Const;
714
+ exports.File = File;
715
+ exports.FileCollector = FileCollector;
716
+ exports.FileCollectorContext = FileCollectorContext;
335
717
  exports.FileManager = FileManager;
336
718
  exports.FileProcessor = FileProcessor;
719
+ exports.Function = Function;
720
+ exports.Root = Root;
721
+ exports.RootContext = RootContext;
722
+ exports.Type = Type;
723
+ exports.createContext = createContext;
337
724
  exports.createFabric = createFabric;
338
725
  exports.createFile = require_defineProperty.createFile;
726
+ exports.createJSDoc = createJSDoc;
727
+ exports.inject = inject;
728
+ exports.provide = provide;
729
+ exports.unprovide = unprovide;
730
+ exports.useApp = useApp;
731
+ exports.useContext = useContext;
732
+ exports.useFile = useFile;
733
+ exports.useLifecycle = useLifecycle;
339
734
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["e","NodeEventEmitter","errors: Error[]","defaultParser","resolvedFiles: Array<KubbFile.ResolvedFile>","createFile","trimExtName","files: Array<KubbFile.ResolvedFile>","context: FabricContext<T>","fabric: Fabric<T>","isFunction"],"sources":["../../../node_modules/.pnpm/remeda@2.33.1/node_modules/remeda/dist/isFunction.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/utils/Cache.ts","../src/FileManager.ts","../src/createFabric.ts"],"sourcesContent":["const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction.js.map","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport type { FabricMode } from '../Fabric.ts'\n\ntype Options = {\n mode?: FabricMode\n maxListener?: number\n}\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor({ maxListener = 100, mode = 'sequential' }: Options = {}) {\n this.#emitter.setMaxListeners(maxListener)\n this.#mode = mode\n }\n\n #emitter = new NodeEventEmitter()\n #mode: FabricMode\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return\n }\n\n const errors: Error[] = []\n\n if (this.#mode === 'sequential') {\n // Run listeners one by one, in order\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n errors.push(error)\n }\n }\n } else {\n // Run all listeners concurrently\n const promises = listeners.map(async (listener) => {\n try {\n await listener(...eventArgs)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n errors.push(error)\n }\n })\n await Promise.all(promises)\n }\n\n if (errors.length === 1) {\n throw errors[0]\n }\n\n if (errors.length > 1) {\n throw new AggregateError(errors, `Errors in async listeners for \"${eventName}\"`)\n }\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import pLimit from 'p-limit'\nimport type { FabricEvents, FabricMode } from './Fabric.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Map<KubbFile.Extname, Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Map<KubbFile.Extname, Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n const parser = parsers.get(file.extname)\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('files:processing:start', files)\n\n const total = files.length\n let processed = 0\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n await this.events.emit('file:processing:start', resolvedFile, index, total)\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n const currentProcessed = ++processed\n const percentage = (currentProcessed / total) * 100\n\n await this.events.emit('file:processing:update', {\n file: resolvedFile,\n source,\n processed: currentProcessed,\n percentage,\n total,\n })\n\n await this.events.emit('file:processing:end', resolvedFile, index, total)\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\n\n await this.events.emit('files:processing:end', files)\n\n return files\n }\n}\n","export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport type { FabricEvents } from './Fabric.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n #filesCache: Array<KubbFile.ResolvedFile> | null = null\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = events\n return this\n }\n\n #resolvePath(file: KubbFile.File): KubbFile.File {\n this.events.emit('file:resolve:path', file)\n\n return file\n }\n\n #resolveName(file: KubbFile.File): KubbFile.File {\n this.events.emit('file:resolve:name', file)\n\n return file\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (let file of mergedFiles.values()) {\n file = this.#resolveName(file)\n file = this.#resolvePath(file)\n\n const resolvedFile = createFile(file)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n await this.events.emit('files:added', resolvedFiles)\n\n return resolvedFiles\n }\n\n async upsert(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (let file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n file = this.#resolveName(file)\n file = this.#resolvePath(file)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n await this.events.emit('files:added', resolvedFiles)\n\n return resolvedFiles\n }\n\n flush() {\n this.#filesCache = null\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files: Array<KubbFile.ResolvedFile> = []\n\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n\n return files\n }\n\n //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('files:writing:start', this.files)\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('files:writing:end', resolvedFiles)\n\n return resolvedFiles\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\n/**\n * Creates a new Fabric instance\n *\n * @example\n * const fabric = createFabric()\n * fabric.use(myPlugin())\n */\nexport function createFabric<T extends FabricOptions>(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Map<KubbFile.Extname, Parser<any>>()\n const installedParserNames = new Set<string>()\n const fileManager = new FileManager({ events })\n\n const context: FabricContext<T> = {\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<T>\n\n const fabric: Fabric<T> = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n async upsertFile(...files) {\n await fileManager.upsert(...files)\n },\n async use(pluginOrParser, ...options) {\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn(`Plugin \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const injected = (injecter as any)(context, ...options)\n Object.assign(fabric, injected)\n }\n }\n\n if (pluginOrParser.type === 'parser') {\n if (installedParserNames.has(pluginOrParser.name)) {\n console.warn(`Parser \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedParserNames.add(pluginOrParser.name)\n }\n\n if (pluginOrParser.extNames) {\n for (const extName of pluginOrParser.extNames) {\n const existing = installedParsers.get(extName)\n if (existing && existing.name !== pluginOrParser.name) {\n console.warn(`Parser \"${pluginOrParser.name}\" is overriding parser \"${existing.name}\" for extension \"${extName}\".`)\n }\n installedParsers.set(extName, pluginOrParser)\n }\n }\n }\n\n if (isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(context, ...options)\n }\n\n return fabric\n },\n } as Fabric<T>\n\n return fabric\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;AAAA,MAAM,KAAE,QAAG,OAAOA,OAAG;;;;;;ACQrB,IAAa,oBAAb,MAAoE;CAClE,YAAY,EAAE,cAAc,KAAK,OAAO,iBAA0B,EAAE,EAAE;oEAK3D,IAAIC,0BAAkB;;AAJ/B,+DAAa,CAAC,gBAAgB,YAAY;AAC1C,6DAAa,KAAI;;CAMnB,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,oEAAY,KAAa,CAAC,UAAU,UAAU;AAEpD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,KAAK,OAAO;EACxC,MAAM,OAAO,KAAK,KAAK,OAAO;EAC/B;CAED,MAAMC,SAAoB;EACxB;EACA,IAAI,QAAQ;AACV,UAAO,YAAY;;EAErB,MAAM,QAAQ,GAAG,OAAO;AACtB,SAAM,YAAY,IAAI,GAAG,MAAM;;EAEjC,MAAM,WAAW,GAAG,OAAO;AACzB,SAAM,YAAY,OAAO,GAAG,MAAM;;EAEpC,MAAM,IAAI,gBAAgB,GAAG,SAAS;AACpC,OAAI,eAAe,SAAS,UAAU;AACpC,QAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,WAAW,eAAe,KAAK,oBAAoB;QAEhE,kBAAiB,IAAI,eAAe;AAGtC,QAAIC,EAAW,eAAe,OAAO,EAAE;KACrC,MAAM,WAAW,eAAe;KAEhC,MAAM,WAAY,SAAiB,SAAS,GAAG,QAAQ;AACvD,YAAO,OAAO,QAAQ,SAAS;;;AAInC,OAAI,eAAe,SAAS,UAAU;AACpC,QAAI,qBAAqB,IAAI,eAAe,KAAK,CAC/C,SAAQ,KAAK,WAAW,eAAe,KAAK,oBAAoB;QAEhE,sBAAqB,IAAI,eAAe,KAAK;AAG/C,QAAI,eAAe,SACjB,MAAK,MAAM,WAAW,eAAe,UAAU;KAC7C,MAAM,WAAW,iBAAiB,IAAI,QAAQ;AAC9C,SAAI,YAAY,SAAS,SAAS,eAAe,KAC/C,SAAQ,KAAK,WAAW,eAAe,KAAK,0BAA0B,SAAS,KAAK,mBAAmB,QAAQ,IAAI;AAErH,sBAAiB,IAAI,SAAS,eAAe;;;AAKnD,OAAIA,EAAW,eAAe,QAAQ,EAAE;IACtC,MAAM,YAAY,eAAe;AAEjC,UAAO,UAAkB,SAAS,GAAG,QAAQ;;AAG/C,UAAO;;EAEV;AAED,QAAO"}
1
+ {"version":3,"file":"index.cjs","names":["AppContext","parts: string[]","e","e","NodeEventEmitter","errors: Error[]","defaultParser","resolvedFiles: Array<KubbFile.ResolvedFile>","createFile","trimExtName","files: Array<KubbFile.ResolvedFile>","context: FabricContext<T>","fabric: Fabric<T>","isFunction"],"sources":["../src/context.ts","../src/composables/useContext.ts","../src/contexts/RootContext.ts","../src/components/App.ts","../src/utils/createJSDoc.ts","../src/components/Const.ts","../src/contexts/FileCollectorContext.ts","../src/utils/FileCollector.ts","../src/components/File.ts","../src/components/Function.ts","../src/components/Root.ts","../src/components/Type.ts","../src/contexts/AppContext.ts","../src/composables/useApp.ts","../src/composables/useFile.ts","../src/composables/useLifecycle.ts","../../../node_modules/.pnpm/remeda@2.33.2/node_modules/remeda/dist/isFunction.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/utils/Cache.ts","../src/FileManager.ts","../src/createFabric.ts"],"sourcesContent":["/**\n * Context type that carries type information about its value\n * This is a branded symbol type that enables type-safe context usage\n */\nexport type Context<T> = symbol & { readonly __type: T }\n\n/**\n * Context stack for tracking the current context values\n *\n * Note: This uses a global Map for simplicity in code generation scenarios.\n * For concurrent runtime execution, consider using AsyncLocalStorage or\n * instance-based context management.\n */\nconst contextStack = new Map<symbol, unknown[]>()\nconst contextDefaults = new Map<symbol, unknown>()\n\n/**\n * Provides a value to descendant components (Vue 3 style)\n *\n * @example\n * ```ts\n * const ThemeKey = Symbol('theme')\n * provide(ThemeKey, { color: 'blue' })\n * ```\n */\nexport function provide<T>(key: symbol | Context<T>, value: T): void {\n if (!contextStack.has(key)) {\n contextStack.set(key, [])\n }\n contextStack.get(key)!.push(value)\n}\n\n/**\n * Injects a value provided by an ancestor component (Vue 3 style)\n *\n * @example\n * ```ts\n * const theme = inject(ThemeKey, { color: 'default' })\n * ```\n */\nexport function inject<T>(key: symbol | Context<T>, defaultValue?: T): T {\n const stack = contextStack.get(key)\n if (!stack || stack.length === 0) {\n if (defaultValue !== undefined) {\n return defaultValue\n }\n const storedDefault = contextDefaults.get(key)\n if (storedDefault !== undefined) {\n return storedDefault as T\n }\n throw new Error(`No value provided for key: ${key.toString()}`)\n }\n return stack[stack.length - 1] as T\n}\n\n/**\n * Unprovides a value (for cleanup)\n * @internal\n */\nexport function unprovide<T>(key: symbol | Context<T>): void {\n const stack = contextStack.get(key)\n if (stack && stack.length > 0) {\n stack.pop()\n }\n}\n\n/**\n * Creates a context key with a default value (React-style compatibility)\n *\n * @example\n * ```ts\n * const ThemeContext = createContext({ color: 'blue' })\n * // ThemeContext is now typed as Context<{ color: string }>\n * const theme = useContext(ThemeContext) // theme is { color: string }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const key = Symbol('context') as Context<T>\n contextDefaults.set(key, defaultValue)\n\n return key\n}\n","import type { Context } from '../context.ts'\nimport { inject } from '../context.ts'\n\n/**\n * React-style alias for inject\n *\n * @example\n * ```ts\n * const theme = useContext(ThemeContext) // type is inferred from ThemeContext\n * ```\n */\nexport function useContext<T>(key: Context<T>): T\nexport function useContext<T, TValue = T>(key: Context<T>, defaultValue: TValue): NonNullable<T> | TValue\nexport function useContext<T>(key: Context<T>, defaultValue?: T): T {\n return inject(key, defaultValue)\n}\n","import { createContext } from '../context.ts'\n\nexport type RootContextProps = {\n /**\n * Exit (unmount) the whole app.\n */\n readonly exit: (error?: Error) => void\n}\n\n/**\n * Provides a top-level lifecycle hook (`exit`) for terminating the Fabric\n * runtime. This context is available at the root of a Fabric app.\n */\nexport const RootContext = createContext<RootContextProps>({\n exit: () => {},\n})\n","import { useContext } from '../composables/useContext.ts'\nimport { createContext, provide } from '../context.ts'\nimport { RootContext } from '../contexts/RootContext.ts'\n\nexport type AppContextProps<TMeta = unknown> = {\n /**\n * Exit (unmount)\n */\n readonly exit: (error?: Error) => void\n readonly meta: TMeta\n}\n\nconst AppContext = createContext<AppContextProps | undefined>(undefined)\n\ntype Props<TMeta = unknown> = {\n readonly meta: TMeta\n readonly children?: string\n}\n\n/**\n * Minimal fsx app container — provides an AppContext carrying `meta` and an\n * `exit` hook. In fsx mode this just returns children content.\n */\nexport function App<TMeta = unknown>({ children, meta }: Props<TMeta>): string {\n const { exit } = useContext(RootContext)\n provide(AppContext, { exit, meta })\n\n // In fsx, we just return children since we don't have a component tree\n // Context is provided via provide() calls before components run\n\n return children || ''\n}\n\nApp.Context = AppContext\nApp.displayName = 'KubbApp'\n\n// Export for use with provide/inject\nexport { AppContext }\n","/**\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 { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype JSDoc = { comments: Array<string> }\n\ntype Props = {\n /**\n * Name of the const\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Type to make the const being typed\n */\n type?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n /**\n * Use of `const` assertions\n */\n asConst?: boolean\n children?: string\n}\n\nexport function Const({ name, export: canExport, type, JSDoc, asConst, children }: Props): string {\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `const ${name}`\n\n if (type) {\n result += `: ${type}`\n }\n\n result += ` = ${children || ''}`\n\n if (asConst) {\n result += ' as const'\n }\n\n return result\n}\n\nConst.displayName = 'KubbConst'\n","import { createContext } from '../context.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport type { FileCollector } from '../utils/FileCollector.ts'\n\n/**\n * Context for collecting files - provided by createFsxFabric\n */\nexport const FileCollectorContext = createContext<FileCollector | null>(null)\n\n/**\n * Context for the current file being processed\n */\ntype CurrentFileContext = {\n sources: KubbFile.Source[]\n imports: KubbFile.Import[]\n exports: KubbFile.Export[]\n}\nexport const CurrentFileContext = createContext<CurrentFileContext | null>(null)\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","import { useContext } from '../composables/useContext.ts'\nimport { provide } from '../context.ts'\nimport { FileCollectorContext } from '../contexts/FileCollectorContext.ts'\nimport type { KubbFile } from '../types.ts'\nimport { FileCollector } from '../utils/FileCollector.ts'\n\nexport type FileProps<TMeta extends object = object> = {\n /**\n * Name to be used to dynamically create the baseName(based on input.path).\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: KubbFile.BaseName\n /**\n * Path will be full qualified path to a specified file.\n */\n path: KubbFile.Path\n meta?: TMeta\n banner?: string\n footer?: string\n children?: string\n}\n\n/**\n * File component for fsx - registers files via context\n *\n * When executed this will create or reuse a FileCollector from context and\n * register the file (baseName/path) so it can be emitted later. Returns the\n * children string content for fsx renderers.\n */\nexport function File<TMeta extends object = object>({ children, ...rest }: FileProps<TMeta>): string {\n const collector = useContext(FileCollectorContext, new FileCollector())\n provide(FileCollectorContext, collector)\n\n // Register this file with the collector\n collector.add({\n baseName: rest.baseName,\n path: rest.path,\n meta: rest.meta || ({} as TMeta),\n banner: rest.banner,\n footer: rest.footer,\n sources: [],\n imports: [],\n exports: [],\n })\n\n return children || ''\n}\n\n/**\n * FileSource - for adding source code to a file\n *\n * Returns the provided children string so the fsx renderer can collect it.\n */\nexport function FileSource(props: Omit<KubbFile.Source, 'value'> & { children?: string }): string {\n return props.children || ''\n}\n\n/**\n * FileExport - for adding exports to a file\n *\n * No-op function used by renderers to record exports.\n */\nexport function FileExport(_props: KubbFile.Export): string {\n return ''\n}\n\n/**\n * FileImport - for adding imports to a file\n *\n * No-op function used by renderers to record imports.\n */\nexport function FileImport(_props: KubbFile.Import): string {\n return ''\n}\n\nFile.Source = FileSource\nFile.Import = FileImport\nFile.Export = FileExport\n","import type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n /**\n * Name of the function.\n */\n name: string\n /**\n * Add default when export is being used\n */\n default?: boolean\n /**\n * Parameters/options/props that need to be used.\n */\n params?: string\n /**\n * Does this function need to be exported.\n */\n export?: boolean\n /**\n * Does the function has async/promise behaviour.\n * This will also add `Promise<returnType>` as the returnType.\n */\n async?: boolean\n /**\n * Generics that needs to be added for TypeScript.\n */\n generics?: string | string[]\n\n /**\n * ReturnType(see async for adding Promise type).\n */\n returnType?: string\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n children?: string\n}\n\n/**\n * Builds a function declaration string for the fsx renderer. Supports optional\n * export/default/async flags, generics, params and JSDoc rendering.\n */\nexport function Function({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, children }: Props): string {\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n if (async) {\n parts.push('async ')\n }\n\n parts.push(`function ${name}`)\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n parts.push(' {')\n\n if (children) {\n return `${parts.join('')}${' '}${'\\n'}${children}${' '}${'\\n'}}`\n }\n\n return `${parts.join('')}}`\n}\n\nFunction.displayName = 'KubbFunction'\n\ntype ArrowFunctionProps = Props & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Builds an arrow function declaration string for the fsx renderer. Supports\n * the same options as `Function`. Use `singleLine` to produce a one-line\n * arrow expression.\n */\nfunction ArrowFunction({\n name,\n default: isDefault,\n export: canExport,\n async,\n generics,\n params,\n returnType,\n JSDoc,\n singleLine,\n children,\n}: ArrowFunctionProps): string {\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n parts.push(`const ${name} = `)\n\n if (async) {\n parts.push('async ')\n }\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n if (singleLine) {\n parts.push(` => ${children || ''}\\n`)\n return parts.join('')\n }\n\n if (children) {\n return `${parts.join('')} => {${' '}${'\\n'}${children}${' '}${'\\n'}}${'\\n'}`\n }\n\n return `${parts.join('')} => {}\\n`\n}\n\nArrowFunction.displayName = 'KubbArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { provide } from '../context.ts'\nimport { RootContext } from '../contexts/RootContext.ts'\n\ntype RootProps = {\n /**\n * Exit (unmount) hook\n */\n readonly onExit: (error?: Error) => void\n /**\n * Error hook\n */\n readonly onError: (error: Error) => void\n readonly children?: string\n}\n\n/**\n * Top-level root for fsx renderers. Returns children content and ensures\n * `onError` is called for runtime exceptions. Provides a RootContext with\n * an `exit` hook for downstream consumers.\n */\nexport function Root({ onError, children }: Omit<RootProps, 'onExit'>): string {\n provide(RootContext, { exit: () => {} })\n\n try {\n // In fsx, we don't have component trees like React\n // We just return the children and let context handle the rest\n return children || ''\n } catch (e) {\n if (e instanceof Error) {\n onError(e)\n }\n return ''\n }\n}\n\nRoot.displayName = 'KubbRoot'\n","import type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\ntype Props = {\n /**\n * Name of the type, this needs to start with a capital letter.\n */\n name: string\n /**\n * Does this type need to be exported.\n */\n export?: boolean\n /**\n * Options for JSdocs.\n */\n JSDoc?: JSDoc\n children?: string\n}\n\n/**\n * Renders a TypeScript type alias string for use with the fsx renderer.\n * Optionally emits JSDoc comments when `JSDoc.comments` is provided.\n */\nexport function Type({ name, export: canExport, JSDoc, children }: Props): string {\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter (see TypeScript types)')\n }\n\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `type ${name} = ${children || ''}`\n\n return result\n}\n\nType.displayName = 'KubbType'\n","import { createContext } from '../context.ts'\n\nexport type AppContextProps<TMeta = unknown> = {\n /**\n * Exit (unmount)\n */\n readonly exit: (error?: Error) => void\n readonly meta: TMeta\n}\n\n/**\n * Provides app-level metadata and lifecycle hooks (like `exit`) to\n * components and composables within a Fabric runtime.\n */\nexport const AppContext = createContext<AppContextProps | undefined>(undefined)\n","import { AppContext, type AppContextProps } from '../contexts/AppContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * `useApp` will return the current App with meta and exit function.\n *\n * Throws an error when there is no AppContext available.\n */\nexport function useApp<TMeta = unknown>(): AppContextProps<TMeta> {\n const app = useContext(AppContext, undefined)\n\n if (!app) {\n throw new Error('App context should be provided')\n }\n\n return app as AppContextProps<TMeta>\n}\n","import { FileCollectorContext } from '../contexts/FileCollectorContext.ts'\nimport type { FileCollector } from '../utils/FileCollector.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * `useFile` will return the current FileCollector for registering files.\n *\n * Throws when no FileCollector is present in context — ensure a Fabric that\n * provides a FileCollector is mounted before calling this hook.\n */\nexport function useFile(): FileCollector {\n const collector = useContext(FileCollectorContext, null)\n\n if (!collector) {\n throw new Error('No FileCollector found in context. Make sure you are using a Fabric that provides a FileCollector.')\n }\n\n return collector\n}\n","import { RootContext } from '../contexts/RootContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * `useLifecycle` will return some helpers to exit/restart the generation.\n *\n * This hook reads the RootContext and exposes lifecycle helpers (like `exit`)\n * for consumers to programmatically stop generation or perform teardown.\n */\nexport function useLifecycle() {\n const { exit } = useContext(RootContext, { exit: () => {} })\n\n return {\n exit,\n }\n}\n","const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction.js.map","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport type { FabricMode } from '../Fabric.ts'\n\ntype Options = {\n mode?: FabricMode\n maxListener?: number\n}\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor({ maxListener = 100, mode = 'sequential' }: Options = {}) {\n this.#emitter.setMaxListeners(maxListener)\n this.#mode = mode\n }\n\n #emitter = new NodeEventEmitter()\n #mode: FabricMode\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return\n }\n\n const errors: Error[] = []\n\n if (this.#mode === 'sequential') {\n // Run listeners one by one, in order\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n errors.push(error)\n }\n }\n } else {\n // Run all listeners concurrently\n const promises = listeners.map(async (listener) => {\n try {\n await listener(...eventArgs)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n errors.push(error)\n }\n })\n await Promise.all(promises)\n }\n\n if (errors.length === 1) {\n throw errors[0]\n }\n\n if (errors.length > 1) {\n throw new AggregateError(errors, `Errors in async listeners for \"${eventName}\"`)\n }\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import pLimit from 'p-limit'\nimport type { FabricEvents, FabricMode } from './Fabric.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Map<KubbFile.Extname, Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Map<KubbFile.Extname, Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n const parser = parsers.get(file.extname)\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('files:processing:start', files)\n\n const total = files.length\n let processed = 0\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n await this.events.emit('file:processing:start', resolvedFile, index, total)\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n const currentProcessed = ++processed\n const percentage = (currentProcessed / total) * 100\n\n await this.events.emit('file:processing:update', {\n file: resolvedFile,\n source,\n processed: currentProcessed,\n percentage,\n total,\n })\n\n await this.events.emit('file:processing:end', resolvedFile, index, total)\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\n\n await this.events.emit('files:processing:end', files)\n\n return files\n }\n}\n","export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport type { FabricEvents } from './Fabric.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n #filesCache: Array<KubbFile.ResolvedFile> | null = null\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = events\n return this\n }\n\n #resolvePath(file: KubbFile.File): KubbFile.File {\n this.events.emit('file:resolve:path', file)\n\n return file\n }\n\n #resolveName(file: KubbFile.File): KubbFile.File {\n this.events.emit('file:resolve:name', file)\n\n return file\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (let file of mergedFiles.values()) {\n file = this.#resolveName(file)\n file = this.#resolvePath(file)\n\n const resolvedFile = createFile(file)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n await this.events.emit('files:added', resolvedFiles)\n\n return resolvedFiles\n }\n\n async upsert(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (let file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n file = this.#resolveName(file)\n file = this.#resolvePath(file)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n await this.events.emit('files:added', resolvedFiles)\n\n return resolvedFiles\n }\n\n flush() {\n this.#filesCache = null\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files: Array<KubbFile.ResolvedFile> = []\n\n for (const key of keys) {\n const file = this.#cache.get(key)\n if (file) {\n files.push(file)\n }\n }\n\n this.#filesCache = files\n\n return files\n }\n\n //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('files:writing:start', this.files)\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('files:writing:end', resolvedFiles)\n\n return resolvedFiles\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\n/**\n * Creates a new Fabric instance\n *\n * @example\n * const fabric = createFabric()\n * fabric.use(myPlugin())\n */\nexport function createFabric<T extends FabricOptions>(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Map<KubbFile.Extname, Parser<any>>()\n const installedParserNames = new Set<string>()\n const fileManager = new FileManager({ events })\n\n const context: FabricContext<T> = {\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<T>\n\n const fabric: Fabric<T> = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n async upsertFile(...files) {\n await fileManager.upsert(...files)\n },\n async use(pluginOrParser, ...options) {\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn(`Plugin \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const injected = (injecter as any)(context, ...options)\n Object.assign(fabric, injected)\n }\n }\n\n if (pluginOrParser.type === 'parser') {\n if (installedParserNames.has(pluginOrParser.name)) {\n console.warn(`Parser \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedParserNames.add(pluginOrParser.name)\n }\n\n if (pluginOrParser.extNames) {\n for (const extName of pluginOrParser.extNames) {\n const existing = installedParsers.get(extName)\n if (existing && existing.name !== pluginOrParser.name) {\n console.warn(`Parser \"${pluginOrParser.name}\" is overriding parser \"${existing.name}\" for extension \"${extName}\".`)\n }\n installedParsers.set(extName, pluginOrParser)\n }\n }\n }\n\n if (isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(context, ...options)\n }\n\n return fabric\n },\n } as Fabric<T>\n\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