@kubb/fabric-core 0.0.0-canary-20260112115803 → 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
package/dist/index.cjs CHANGED
@@ -1,12 +1,133 @@
1
1
  const require_trimExtName = require('./trimExtName-DaBSwMN-.cjs');
2
- const require_defineProperty = require('./defineProperty-hUmuXj5B.cjs');
2
+ const require_defineProperty = require('./defineProperty-BAD-J6vV.cjs');
3
3
  const require_defaultParser = require('./defaultParser-CIF-0xIK.cjs');
4
+ const require_classPrivateFieldSet2 = require('./classPrivateFieldSet2-DrVq6yr-.cjs');
4
5
  let natural_orderby = require("natural-orderby");
5
6
  let p_limit = require("p-limit");
6
7
  p_limit = require_trimExtName.__toESM(p_limit);
7
8
  let node_events = require("node:events");
8
9
 
9
- //#region ../../node_modules/.pnpm/remeda@2.33.1/node_modules/remeda/dist/isFunction.js
10
+ //#region src/context.ts
11
+ /**
12
+ * Context stack for tracking the current context values
13
+ *
14
+ * Note: This uses a global Map for simplicity in code generation scenarios.
15
+ * For concurrent runtime execution, consider using AsyncLocalStorage or
16
+ * instance-based context management.
17
+ */
18
+ const contextStack = /* @__PURE__ */ new Map();
19
+ const contextDefaults = /* @__PURE__ */ new Map();
20
+ /**
21
+ * Provides a value to descendant components (Vue 3 style)
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const ThemeKey = Symbol('theme')
26
+ * provide(ThemeKey, { color: 'blue' })
27
+ * ```
28
+ */
29
+ function provide(key, value) {
30
+ if (!contextStack.has(key)) contextStack.set(key, []);
31
+ contextStack.get(key).push(value);
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
+ function inject(key, defaultValue) {
42
+ const stack = contextStack.get(key);
43
+ if (!stack || stack.length === 0) {
44
+ if (defaultValue !== void 0) return defaultValue;
45
+ const storedDefault = contextDefaults.get(key);
46
+ if (storedDefault !== void 0) return storedDefault;
47
+ throw new Error(`No value provided for key: ${key.toString()}`);
48
+ }
49
+ return stack[stack.length - 1];
50
+ }
51
+ /**
52
+ * Unprovides a value (for cleanup)
53
+ * @internal
54
+ */
55
+ function unprovide(key) {
56
+ const stack = contextStack.get(key);
57
+ if (stack && stack.length > 0) stack.pop();
58
+ }
59
+ /**
60
+ * Creates a context key with a default value (React-style compatibility)
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const ThemeContext = createContext({ color: 'blue' })
65
+ * // ThemeContext is now typed as Context<{ color: string }>
66
+ * const theme = useContext(ThemeContext) // theme is { color: string }
67
+ * ```
68
+ */
69
+ function createContext(defaultValue) {
70
+ const key = Symbol("context");
71
+ contextDefaults.set(key, defaultValue);
72
+ return key;
73
+ }
74
+
75
+ //#endregion
76
+ //#region src/contexts/AppContext.ts
77
+ const AppContext = createContext(void 0);
78
+
79
+ //#endregion
80
+ //#region src/composables/useApp.ts
81
+ /**
82
+ * `useApp` will return the current App with meta and exit function.
83
+ */
84
+ function useApp() {
85
+ const app = inject(AppContext, void 0);
86
+ if (!app) throw new Error("App context should be provided");
87
+ return app;
88
+ }
89
+
90
+ //#endregion
91
+ //#region src/composables/useContext.ts
92
+ function useContext(key, defaultValue) {
93
+ return inject(key, defaultValue);
94
+ }
95
+
96
+ //#endregion
97
+ //#region src/contexts/FileCollectorContext.ts
98
+ /**
99
+ * Context for collecting files - provided by createFsxFabric
100
+ */
101
+ const FileCollectorContext = createContext(null);
102
+ const CurrentFileContext = createContext(null);
103
+
104
+ //#endregion
105
+ //#region src/composables/useFile.ts
106
+ /**
107
+ * `useFile` will return the current FileCollector for registering files.
108
+ */
109
+ function useFile() {
110
+ const collector = inject(FileCollectorContext, null);
111
+ if (!collector) throw new Error("No FileCollector found in context. Make sure you are using a Fabric that provides a FileCollector.");
112
+ return collector;
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/contexts/RootContext.ts
117
+ const RootContext = createContext({ exit: () => {} });
118
+
119
+ //#endregion
120
+ //#region src/composables/useLifecycle.ts
121
+ /**
122
+ * `useLifecycle` will return some helpers to exit/restart the generation.
123
+ */
124
+ function useLifecycle() {
125
+ const { exit } = inject(RootContext, { exit: () => {} });
126
+ return { exit };
127
+ }
128
+
129
+ //#endregion
130
+ //#region ../../node_modules/.pnpm/remeda@2.33.2/node_modules/remeda/dist/isFunction.js
10
131
  const e = (e$1) => typeof e$1 == `function`;
11
132
 
12
133
  //#endregion
@@ -15,16 +136,16 @@ var _emitter = /* @__PURE__ */ new WeakMap();
15
136
  var _mode = /* @__PURE__ */ new WeakMap();
16
137
  var AsyncEventEmitter = class {
17
138
  constructor({ maxListener = 100, mode = "sequential" } = {}) {
18
- require_defineProperty._classPrivateFieldInitSpec(this, _emitter, new node_events.EventEmitter());
19
- require_defineProperty._classPrivateFieldInitSpec(this, _mode, void 0);
20
- require_defineProperty._classPrivateFieldGet2(_emitter, this).setMaxListeners(maxListener);
21
- require_defineProperty._classPrivateFieldSet2(_mode, this, mode);
139
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _emitter, new node_events.EventEmitter());
140
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _mode, void 0);
141
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_emitter, this).setMaxListeners(maxListener);
142
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_mode, this, mode);
22
143
  }
23
144
  async emit(eventName, ...eventArgs) {
24
- const listeners = require_defineProperty._classPrivateFieldGet2(_emitter, this).listeners(eventName);
145
+ const listeners = require_classPrivateFieldSet2._classPrivateFieldGet2(_emitter, this).listeners(eventName);
25
146
  if (listeners.length === 0) return;
26
147
  const errors = [];
27
- if (require_defineProperty._classPrivateFieldGet2(_mode, this) === "sequential") for (const listener of listeners) try {
148
+ if (require_classPrivateFieldSet2._classPrivateFieldGet2(_mode, this) === "sequential") for (const listener of listeners) try {
28
149
  await listener(...eventArgs);
29
150
  } catch (err) {
30
151
  const error = err instanceof Error ? err : new Error(String(err));
@@ -45,7 +166,7 @@ var AsyncEventEmitter = class {
45
166
  if (errors.length > 1) throw new AggregateError(errors, `Errors in async listeners for "${eventName}"`);
46
167
  }
47
168
  on(eventName, handler) {
48
- require_defineProperty._classPrivateFieldGet2(_emitter, this).on(eventName, handler);
169
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_emitter, this).on(eventName, handler);
49
170
  }
50
171
  onOnce(eventName, handler) {
51
172
  const wrapper = (...args) => {
@@ -55,10 +176,10 @@ var AsyncEventEmitter = class {
55
176
  this.on(eventName, wrapper);
56
177
  }
57
178
  off(eventName, handler) {
58
- require_defineProperty._classPrivateFieldGet2(_emitter, this).off(eventName, handler);
179
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_emitter, this).off(eventName, handler);
59
180
  }
60
181
  removeAll() {
61
- require_defineProperty._classPrivateFieldGet2(_emitter, this).removeAllListeners();
182
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_emitter, this).removeAllListeners();
62
183
  }
63
184
  };
64
185
 
@@ -67,7 +188,7 @@ var AsyncEventEmitter = class {
67
188
  var _limit = /* @__PURE__ */ new WeakMap();
68
189
  var FileProcessor = class {
69
190
  constructor({ events = new AsyncEventEmitter() } = {}) {
70
- require_defineProperty._classPrivateFieldInitSpec(this, _limit, (0, p_limit.default)(100));
191
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _limit, (0, p_limit.default)(100));
71
192
  require_defineProperty._defineProperty(this, "events", void 0);
72
193
  this.events = events;
73
194
  return this;
@@ -110,7 +231,7 @@ var FileProcessor = class {
110
231
  }
111
232
  for await (const [file, index] of asyncFiles()) if (file) await processOne(file, index);
112
233
  } else {
113
- const promises = files.map((resolvedFile, index) => require_defineProperty._classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
234
+ const promises = files.map((resolvedFile, index) => require_classPrivateFieldSet2._classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
114
235
  await Promise.all(promises);
115
236
  }
116
237
  await this.events.emit("files:processing:end", files);
@@ -123,26 +244,26 @@ var FileProcessor = class {
123
244
  var _buffer = /* @__PURE__ */ new WeakMap();
124
245
  var Cache = class {
125
246
  constructor() {
126
- require_defineProperty._classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
247
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
127
248
  }
128
249
  get(key) {
129
250
  var _this$buffer$get;
130
- return (_this$buffer$get = require_defineProperty._classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
251
+ return (_this$buffer$get = require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
131
252
  }
132
253
  set(key, value) {
133
- require_defineProperty._classPrivateFieldGet2(_buffer, this).set(key, value);
254
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).set(key, value);
134
255
  }
135
256
  delete(key) {
136
- require_defineProperty._classPrivateFieldGet2(_buffer, this).delete(key);
257
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).delete(key);
137
258
  }
138
259
  clear() {
139
- require_defineProperty._classPrivateFieldGet2(_buffer, this).clear();
260
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).clear();
140
261
  }
141
262
  keys() {
142
- return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).keys()];
263
+ return [...require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).keys()];
143
264
  }
144
265
  values() {
145
- return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).values()];
266
+ return [...require_classPrivateFieldSet2._classPrivateFieldGet2(_buffer, this).values()];
146
267
  }
147
268
  flush() {}
148
269
  };
@@ -150,7 +271,7 @@ var Cache = class {
150
271
  //#endregion
151
272
  //#region \0@oxc-project+runtime@0.103.0/helpers/classPrivateMethodInitSpec.js
152
273
  function _classPrivateMethodInitSpec(e$1, a) {
153
- require_defineProperty._checkPrivateRedeclaration(e$1, a), a.add(e$1);
274
+ require_classPrivateFieldSet2._checkPrivateRedeclaration(e$1, a), a.add(e$1);
154
275
  }
155
276
 
156
277
  //#endregion
@@ -169,8 +290,8 @@ var _FileManager_brand = /* @__PURE__ */ new WeakSet();
169
290
  var FileManager = class {
170
291
  constructor({ events = new AsyncEventEmitter() } = {}) {
171
292
  _classPrivateMethodInitSpec(this, _FileManager_brand);
172
- require_defineProperty._classPrivateFieldInitSpec(this, _cache, new Cache());
173
- require_defineProperty._classPrivateFieldInitSpec(this, _filesCache, null);
293
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _cache, new Cache());
294
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _filesCache, null);
174
295
  require_defineProperty._defineProperty(this, "events", void 0);
175
296
  require_defineProperty._defineProperty(this, "processor", void 0);
176
297
  this.processor = new FileProcessor({ events });
@@ -186,10 +307,10 @@ var FileManager = class {
186
307
  else mergedFiles.set(file.path, file);
187
308
  });
188
309
  for (let file of mergedFiles.values()) {
189
- file = require_defineProperty._assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
190
- file = require_defineProperty._assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
310
+ file = require_classPrivateFieldSet2._assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
311
+ file = require_classPrivateFieldSet2._assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
191
312
  const resolvedFile = require_defineProperty.createFile(file);
192
- require_defineProperty._classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
313
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
193
314
  this.flush();
194
315
  resolvedFiles.push(resolvedFile);
195
316
  }
@@ -205,11 +326,11 @@ var FileManager = class {
205
326
  else mergedFiles.set(file.path, file);
206
327
  });
207
328
  for (let file of mergedFiles.values()) {
208
- const existing = require_defineProperty._classPrivateFieldGet2(_cache, this).get(file.path);
209
- file = require_defineProperty._assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
210
- file = require_defineProperty._assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
329
+ const existing = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).get(file.path);
330
+ file = require_classPrivateFieldSet2._assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
331
+ file = require_classPrivateFieldSet2._assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
211
332
  const resolvedFile = require_defineProperty.createFile(existing ? mergeFile(existing, file) : file);
212
- require_defineProperty._classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
333
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
213
334
  this.flush();
214
335
  resolvedFiles.push(resolvedFile);
215
336
  }
@@ -217,29 +338,29 @@ var FileManager = class {
217
338
  return resolvedFiles;
218
339
  }
219
340
  flush() {
220
- require_defineProperty._classPrivateFieldSet2(_filesCache, this, null);
221
- require_defineProperty._classPrivateFieldGet2(_cache, this).flush();
341
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_filesCache, this, null);
342
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).flush();
222
343
  }
223
344
  getByPath(path) {
224
- return require_defineProperty._classPrivateFieldGet2(_cache, this).get(path);
345
+ return require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).get(path);
225
346
  }
226
347
  deleteByPath(path) {
227
- require_defineProperty._classPrivateFieldGet2(_cache, this).delete(path);
228
- require_defineProperty._classPrivateFieldSet2(_filesCache, this, null);
348
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).delete(path);
349
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_filesCache, this, null);
229
350
  }
230
351
  clear() {
231
- require_defineProperty._classPrivateFieldGet2(_cache, this).clear();
232
- require_defineProperty._classPrivateFieldSet2(_filesCache, this, null);
352
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).clear();
353
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_filesCache, this, null);
233
354
  }
234
355
  get files() {
235
- if (require_defineProperty._classPrivateFieldGet2(_filesCache, this)) return require_defineProperty._classPrivateFieldGet2(_filesCache, this);
236
- const keys = (0, natural_orderby.orderBy)(require_defineProperty._classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => require_trimExtName.trimExtName(v).endsWith("index")]);
356
+ if (require_classPrivateFieldSet2._classPrivateFieldGet2(_filesCache, this)) return require_classPrivateFieldSet2._classPrivateFieldGet2(_filesCache, this);
357
+ const keys = (0, natural_orderby.orderBy)(require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => require_trimExtName.trimExtName(v).endsWith("index")]);
237
358
  const files = [];
238
359
  for (const key of keys) {
239
- const file = require_defineProperty._classPrivateFieldGet2(_cache, this).get(key);
360
+ const file = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).get(key);
240
361
  if (file) files.push(file);
241
362
  }
242
- require_defineProperty._classPrivateFieldSet2(_filesCache, this, files);
363
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_filesCache, this, files);
243
364
  return files;
244
365
  }
245
366
  async write(options) {
@@ -332,8 +453,19 @@ function createFabric(config = { mode: "sequential" }) {
332
453
  }
333
454
 
334
455
  //#endregion
456
+ exports.AppContext = AppContext;
457
+ exports.FileCollectorContext = FileCollectorContext;
335
458
  exports.FileManager = FileManager;
336
459
  exports.FileProcessor = FileProcessor;
460
+ exports.RootContext = RootContext;
461
+ exports.createContext = createContext;
337
462
  exports.createFabric = createFabric;
338
463
  exports.createFile = require_defineProperty.createFile;
464
+ exports.inject = inject;
465
+ exports.provide = provide;
466
+ exports.unprovide = unprovide;
467
+ exports.useApp = useApp;
468
+ exports.useContext = useContext;
469
+ exports.useFile = useFile;
470
+ exports.useLifecycle = useLifecycle;
339
471
  //# 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,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O,UAAkB,SAAS,GAAG,QAAQ;;AAG/C,UAAO;;EAEV;AAED,QAAO"}
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":["../src/context.ts","../src/contexts/AppContext.ts","../src/composables/useApp.ts","../src/composables/useContext.ts","../src/contexts/FileCollectorContext.ts","../src/composables/useFile.ts","../src/contexts/RootContext.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 { 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\nexport const AppContext = createContext<AppContextProps | undefined>(undefined)\n","import { inject } from '../context.ts'\nimport { AppContext, type AppContextProps } from '../contexts/AppContext.ts'\n\n/**\n * `useApp` will return the current App with meta and exit function.\n */\nexport function useApp<TMeta = unknown>(): AppContextProps<TMeta> {\n const app = inject(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 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>(key: Context<T>, defaultValue: T): T\nexport function useContext<T>(key: Context<T>, defaultValue?: T): T {\n return inject(key, defaultValue)\n}\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 { inject } from '../context.ts'\nimport { FileCollectorContext } from '../contexts/FileCollectorContext.ts'\nimport type { FileCollector } from '../utils/FileCollector.ts'\n\n/**\n * `useFile` will return the current FileCollector for registering files.\n */\nexport function useFile(): FileCollector {\n const collector = inject(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 { createContext } from '../context.ts'\n\nexport type RootContextProps = {\n /**\n * Exit (unmount) the whole app.\n */\n readonly exit: (error?: Error) => void\n}\n\nexport const RootContext = createContext<RootContextProps>({\n exit: () => {},\n})\n","import { inject } from '../context.ts'\nimport { RootContext } from '../contexts/RootContext.ts'\n\n/**\n * `useLifecycle` will return some helpers to exit/restart the generation.\n */\nexport function useLifecycle() {\n const { exit } = inject(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\n return fabric\n}\n"],"x_google_ignoreList":[8],"mappings":";;;;;;;;;;;;;;;;;AAaA,MAAM,+BAAe,IAAI,KAAwB;AACjD,MAAM,kCAAkB,IAAI,KAAsB;;;;;;;;;;AAWlD,SAAgB,QAAW,KAA0B,OAAgB;AACnE,KAAI,CAAC,aAAa,IAAI,IAAI,CACxB,cAAa,IAAI,KAAK,EAAE,CAAC;AAE3B,cAAa,IAAI,IAAI,CAAE,KAAK,MAAM;;;;;;;;;;AAWpC,SAAgB,OAAU,KAA0B,cAAqB;CACvE,MAAM,QAAQ,aAAa,IAAI,IAAI;AACnC,KAAI,CAAC,SAAS,MAAM,WAAW,GAAG;AAChC,MAAI,iBAAiB,OACnB,QAAO;EAET,MAAM,gBAAgB,gBAAgB,IAAI,IAAI;AAC9C,MAAI,kBAAkB,OACpB,QAAO;AAET,QAAM,IAAI,MAAM,8BAA8B,IAAI,UAAU,GAAG;;AAEjE,QAAO,MAAM,MAAM,SAAS;;;;;;AAO9B,SAAgB,UAAa,KAAgC;CAC3D,MAAM,QAAQ,aAAa,IAAI,IAAI;AACnC,KAAI,SAAS,MAAM,SAAS,EAC1B,OAAM,KAAK;;;;;;;;;;;;AAcf,SAAgB,cAAiB,cAA6B;CAC5D,MAAM,MAAM,OAAO,UAAU;AAC7B,iBAAgB,IAAI,KAAK,aAAa;AAEtC,QAAO;;;;;ACtET,MAAa,aAAa,cAA2C,OAAU;;;;;;;ACJ/E,SAAgB,SAAkD;CAChE,MAAM,MAAM,OAAO,YAAY,O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B,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"}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,109 @@
1
- import { a as FabricOptions, c as FileManager, h as ResolvedFile, l as FileProcessor, n as FabricConfig, p as File, t as Fabric } from "./Fabric-BXYWK9V4.cjs";
1
+ import { a as ResolvedFile, n as File } from "./KubbFile-BqiYGIzl.cjs";
2
+ import { t as FileCollector } from "./FileCollector-lJGpddxr.cjs";
3
+ import { a as FabricOptions, c as FileManager, l as FileProcessor, n as FabricConfig, t as Fabric } from "./Fabric-4XbXcu8_.cjs";
2
4
 
5
+ //#region src/context.d.ts
6
+ /**
7
+ * Context type that carries type information about its value
8
+ * This is a branded symbol type that enables type-safe context usage
9
+ */
10
+ type Context<T> = symbol & {
11
+ readonly __type: T;
12
+ };
13
+ /**
14
+ * Provides a value to descendant components (Vue 3 style)
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const ThemeKey = Symbol('theme')
19
+ * provide(ThemeKey, { color: 'blue' })
20
+ * ```
21
+ */
22
+ declare function provide<T>(key: symbol | Context<T>, value: T): void;
23
+ /**
24
+ * Injects a value provided by an ancestor component (Vue 3 style)
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const theme = inject(ThemeKey, { color: 'default' })
29
+ * ```
30
+ */
31
+ declare function inject<T>(key: symbol | Context<T>, defaultValue?: T): T;
32
+ /**
33
+ * Unprovides a value (for cleanup)
34
+ * @internal
35
+ */
36
+ declare function unprovide<T>(key: symbol | Context<T>): void;
37
+ /**
38
+ * Creates a context key with a default value (React-style compatibility)
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const ThemeContext = createContext({ color: 'blue' })
43
+ * // ThemeContext is now typed as Context<{ color: string }>
44
+ * const theme = useContext(ThemeContext) // theme is { color: string }
45
+ * ```
46
+ */
47
+ declare function createContext<T>(defaultValue: T): Context<T>;
48
+ //#endregion
49
+ //#region src/contexts/AppContext.d.ts
50
+ type AppContextProps<TMeta = unknown> = {
51
+ /**
52
+ * Exit (unmount)
53
+ */
54
+ readonly exit: (error?: Error) => void;
55
+ readonly meta: TMeta;
56
+ };
57
+ declare const AppContext: Context<AppContextProps<unknown> | undefined>;
58
+ //#endregion
59
+ //#region src/composables/useApp.d.ts
60
+ /**
61
+ * `useApp` will return the current App with meta and exit function.
62
+ */
63
+ declare function useApp<TMeta = unknown>(): AppContextProps<TMeta>;
64
+ //#endregion
65
+ //#region src/composables/useContext.d.ts
66
+ /**
67
+ * React-style alias for inject
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const theme = useContext(ThemeContext) // type is inferred from ThemeContext
72
+ * ```
73
+ */
74
+ declare function useContext<T>(key: Context<T>): T;
75
+ declare function useContext<T>(key: Context<T>, defaultValue: T): T;
76
+ //#endregion
77
+ //#region src/composables/useFile.d.ts
78
+ /**
79
+ * `useFile` will return the current FileCollector for registering files.
80
+ */
81
+ declare function useFile(): FileCollector;
82
+ //#endregion
83
+ //#region src/composables/useLifecycle.d.ts
84
+ /**
85
+ * `useLifecycle` will return some helpers to exit/restart the generation.
86
+ */
87
+ declare function useLifecycle(): {
88
+ exit: (error?: Error) => void;
89
+ };
90
+ //#endregion
91
+ //#region src/contexts/FileCollectorContext.d.ts
92
+ /**
93
+ * Context for collecting files - provided by createFsxFabric
94
+ */
95
+ declare const FileCollectorContext: Context<FileCollector | null>;
96
+ //#endregion
97
+ //#region src/contexts/RootContext.d.ts
98
+ type RootContextProps = {
99
+ /**
100
+ * Exit (unmount) the whole app.
101
+ */
102
+ readonly exit: (error?: Error) => void;
103
+ };
104
+ declare const RootContext: Context<RootContextProps>;
105
+ //#endregion
3
106
  //#region src/createFabric.d.ts
4
-
5
107
  /**
6
108
  * Creates a new Fabric instance
7
109
  *
@@ -17,5 +119,5 @@ declare function createFabric<T extends FabricOptions>(config?: FabricConfig<T>)
17
119
  */
18
120
  declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
19
121
  //#endregion
20
- export { type Fabric, FileManager, FileProcessor, createFabric, createFile };
122
+ export { AppContext, type Context, type Fabric, FileCollectorContext, FileManager, FileProcessor, RootContext, createContext, createFabric, createFile, inject, provide, unprovide, useApp, useContext, useFile, useLifecycle };
21
123
  //# sourceMappingURL=index.d.cts.map