@cldmv/slothlet 2.11.0 → 3.0.1

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 (189) hide show
  1. package/AGENT-USAGE.md +355 -325
  2. package/README.md +554 -238
  3. package/dist/lib/builders/api-assignment.mjs +605 -0
  4. package/dist/lib/builders/api_builder.mjs +1073 -0
  5. package/dist/lib/builders/builder.mjs +94 -0
  6. package/dist/lib/builders/modes-processor.mjs +1816 -0
  7. package/dist/lib/errors.mjs +227 -0
  8. package/dist/lib/factories/component-base.mjs +96 -0
  9. package/dist/lib/factories/context.mjs +38 -0
  10. package/dist/lib/handlers/api-cache-manager.mjs +216 -0
  11. package/dist/lib/handlers/api-manager.mjs +2364 -0
  12. package/dist/lib/handlers/context-async.mjs +184 -0
  13. package/dist/lib/handlers/context-live.mjs +184 -0
  14. package/dist/lib/handlers/hook-manager.mjs +789 -0
  15. package/dist/lib/handlers/lifecycle-token.mjs +44 -0
  16. package/dist/lib/handlers/lifecycle.mjs +131 -0
  17. package/dist/lib/handlers/materialize-manager.mjs +64 -0
  18. package/dist/lib/handlers/metadata.mjs +500 -0
  19. package/dist/lib/handlers/ownership.mjs +338 -0
  20. package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
  21. package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
  22. package/dist/lib/helpers/config.mjs +343 -0
  23. package/dist/lib/helpers/eventemitter-context.mjs +365 -0
  24. package/dist/lib/helpers/hint-detector.mjs +63 -0
  25. package/dist/lib/helpers/modes-utils.mjs +53 -0
  26. package/dist/lib/helpers/resolve-from-caller.mjs +123 -117
  27. package/dist/lib/helpers/sanitize.mjs +247 -168
  28. package/dist/lib/helpers/utilities.mjs +46 -81
  29. package/dist/lib/i18n/languages/de-de.json +377 -0
  30. package/dist/lib/i18n/languages/en-gb.json +377 -0
  31. package/dist/lib/i18n/languages/en-us.json +377 -0
  32. package/dist/lib/i18n/languages/es-mx.json +377 -0
  33. package/dist/lib/i18n/languages/fr-fr.json +377 -0
  34. package/dist/lib/i18n/languages/hi-in.json +377 -0
  35. package/dist/lib/i18n/languages/ja-jp.json +377 -0
  36. package/dist/lib/i18n/languages/ko-kr.json +377 -0
  37. package/dist/lib/i18n/languages/pt-br.json +377 -0
  38. package/dist/lib/i18n/languages/ru-ru.json +377 -0
  39. package/dist/lib/i18n/languages/zh-cn.json +377 -0
  40. package/dist/lib/i18n/translations.mjs +140 -0
  41. package/dist/lib/modes/eager.mjs +75 -0
  42. package/dist/lib/modes/lazy.mjs +97 -0
  43. package/dist/lib/processors/flatten.mjs +453 -0
  44. package/dist/lib/processors/loader.mjs +355 -0
  45. package/dist/lib/processors/type-generator.mjs +291 -0
  46. package/dist/lib/processors/typescript.mjs +188 -0
  47. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
  48. package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
  49. package/dist/lib/runtime/runtime.mjs +39 -159
  50. package/dist/slothlet.mjs +525 -744
  51. package/docs/API-RULES.md +338 -486
  52. package/index.cjs +4 -4
  53. package/index.mjs +82 -45
  54. package/package.json +143 -30
  55. package/types/dist/lib/builders/api-assignment.d.mts +97 -0
  56. package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
  57. package/types/dist/lib/builders/api_builder.d.mts +96 -0
  58. package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
  59. package/types/dist/lib/builders/builder.d.mts +60 -0
  60. package/types/dist/lib/builders/builder.d.mts.map +1 -0
  61. package/types/dist/lib/builders/modes-processor.d.mts +32 -0
  62. package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
  63. package/types/dist/lib/errors.d.mts +118 -0
  64. package/types/dist/lib/errors.d.mts.map +1 -0
  65. package/types/dist/lib/factories/component-base.d.mts +182 -0
  66. package/types/dist/lib/factories/component-base.d.mts.map +1 -0
  67. package/types/dist/lib/factories/context.d.mts +26 -0
  68. package/types/dist/lib/factories/context.d.mts.map +1 -0
  69. package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
  70. package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
  71. package/types/dist/lib/handlers/api-manager.d.mts +392 -0
  72. package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
  73. package/types/dist/lib/handlers/context-async.d.mts +66 -0
  74. package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
  75. package/types/dist/lib/handlers/context-live.d.mts +65 -0
  76. package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
  77. package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
  78. package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
  79. package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
  80. package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
  81. package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
  82. package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
  83. package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
  84. package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
  85. package/types/dist/lib/handlers/metadata.d.mts +215 -0
  86. package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
  87. package/types/dist/lib/handlers/ownership.d.mts +170 -0
  88. package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
  89. package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
  90. package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
  91. package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
  92. package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
  93. package/types/dist/lib/helpers/config.d.mts +96 -0
  94. package/types/dist/lib/helpers/config.d.mts.map +1 -0
  95. package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
  96. package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
  97. package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
  98. package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
  99. package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
  100. package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
  101. package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
  102. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
  103. package/types/dist/lib/helpers/sanitize.d.mts +95 -94
  104. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
  105. package/types/dist/lib/helpers/utilities.d.mts +53 -116
  106. package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
  107. package/types/dist/lib/i18n/translations.d.mts +39 -0
  108. package/types/dist/lib/i18n/translations.d.mts.map +1 -0
  109. package/types/dist/lib/modes/eager.d.mts +36 -0
  110. package/types/dist/lib/modes/eager.d.mts.map +1 -0
  111. package/types/dist/lib/modes/lazy.d.mts +49 -0
  112. package/types/dist/lib/modes/lazy.d.mts.map +1 -0
  113. package/types/dist/lib/processors/flatten.d.mts +114 -0
  114. package/types/dist/lib/processors/flatten.d.mts.map +1 -0
  115. package/types/dist/lib/processors/loader.d.mts +47 -0
  116. package/types/dist/lib/processors/loader.d.mts.map +1 -0
  117. package/types/dist/lib/processors/type-generator.d.mts +19 -0
  118. package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
  119. package/types/dist/lib/processors/typescript.d.mts +55 -0
  120. package/types/dist/lib/processors/typescript.d.mts.map +1 -0
  121. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
  122. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  123. package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
  124. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  125. package/types/dist/lib/runtime/runtime.d.mts +39 -9
  126. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  127. package/types/dist/slothlet.d.mts +184 -111
  128. package/types/dist/slothlet.d.mts.map +1 -1
  129. package/types/index.d.mts +1 -3
  130. package/dist/lib/engine/README.md +0 -21
  131. package/dist/lib/engine/slothlet_child.mjs +0 -59
  132. package/dist/lib/engine/slothlet_engine.mjs +0 -372
  133. package/dist/lib/engine/slothlet_esm.mjs +0 -230
  134. package/dist/lib/engine/slothlet_helpers.mjs +0 -455
  135. package/dist/lib/engine/slothlet_worker.mjs +0 -149
  136. package/dist/lib/helpers/als-eventemitter.mjs +0 -256
  137. package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
  138. package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
  139. package/dist/lib/helpers/api_builder/construction.mjs +0 -495
  140. package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
  141. package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
  142. package/dist/lib/helpers/api_builder.mjs +0 -41
  143. package/dist/lib/helpers/auto-wrap.mjs +0 -62
  144. package/dist/lib/helpers/hooks.mjs +0 -389
  145. package/dist/lib/helpers/instance-manager.mjs +0 -111
  146. package/dist/lib/helpers/metadata-api.mjs +0 -201
  147. package/dist/lib/helpers/multidefault.mjs +0 -216
  148. package/dist/lib/modes/slothlet_eager.mjs +0 -154
  149. package/dist/lib/modes/slothlet_lazy.mjs +0 -594
  150. package/docs/API-RULES-CONDITIONS.md +0 -712
  151. package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
  152. package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
  153. package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
  154. package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
  155. package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
  156. package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
  157. package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
  158. package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
  159. package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
  160. package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
  161. package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
  162. package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
  163. package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
  164. package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
  165. package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
  166. package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
  167. package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
  168. package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
  169. package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
  170. package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
  171. package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
  172. package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
  173. package/types/dist/lib/helpers/api_builder.d.mts +0 -6
  174. package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
  175. package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
  176. package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
  177. package/types/dist/lib/helpers/hooks.d.mts +0 -342
  178. package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
  179. package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
  180. package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
  181. package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
  182. package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
  183. package/types/dist/lib/helpers/multidefault.d.mts +0 -90
  184. package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
  185. package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
  186. package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
  187. package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
  188. package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
  189. package/types/index.d.mts.map +0 -1
@@ -1,216 +0,0 @@
1
- /*
2
- Copyright 2026 CLDMV/Shinrai
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
-
18
-
19
-
20
-
21
- import path from "path";
22
-
23
-
24
- async function multidefault_analyzeModules(moduleFiles, baseDir, options = {}) {
25
- const { debug = false, instance = null } = options;
26
- const selfReferentialFiles = new Set();
27
- const rawModuleCache = new Map();
28
- const defaultExportFiles = [];
29
- let totalDefaultExports = 0;
30
-
31
- if (debug) {
32
- console.log(`[DEBUG] multidefault_analyzeModules: Processing ${moduleFiles.length} files in ${baseDir}`);
33
- }
34
-
35
-
36
- for (const file of moduleFiles) {
37
- const moduleExt = path.extname(file.name);
38
- const fileName = path.basename(file.name, moduleExt);
39
- const moduleFilePath = path.resolve(baseDir, file.name);
40
-
41
-
42
-
43
- let importUrl = `file://${moduleFilePath.replace(/\\/g, "/")}`;
44
- const separator = importUrl.includes("?") ? "&" : "?";
45
-
46
-
47
- importUrl = `${importUrl}${separator}_t=${Date.now()}_${Math.random().toString(36).slice(2)}`;
48
-
49
-
50
- if (instance && instance.instanceId) {
51
- const runtimeType = instance.config?.runtime || "async";
52
- if (runtimeType === "live") {
53
- importUrl = `${importUrl}&slothlet_instance=${instance.instanceId}`;
54
- }
55
- }
56
-
57
-
58
- const rawImport = await import(importUrl);
59
-
60
-
61
- const isCjsFile = moduleExt === ".cjs";
62
- const rawMod = isCjsFile ? rawImport.default : rawImport;
63
- rawModuleCache.set(file.name, rawMod);
64
-
65
-
66
- const hasRealDefault = rawMod && "default" in rawMod;
67
- if (hasRealDefault) {
68
- totalDefaultExports++;
69
-
70
-
71
- const isSelfReferential = multidefault_isSelfReferential(rawMod);
72
-
73
- if (debug) {
74
- console.log(`[DEBUG] multidefault_analyzeModules: Checking ${file.name}`);
75
- console.log(`[DEBUG] - fileName: ${fileName}`);
76
- console.log(`[DEBUG] - has default: ${hasRealDefault}`);
77
- console.log(`[DEBUG] - isSelfReferential: ${isSelfReferential}`);
78
- }
79
-
80
- if (!isSelfReferential) {
81
-
82
- defaultExportFiles.push({ fileName, rawModule: rawMod });
83
- if (debug) {
84
- console.log(`[DEBUG] Found default export in ${file.name} (non-self-referential)`);
85
- }
86
- } else {
87
- selfReferentialFiles.add(fileName);
88
- if (debug) {
89
- console.log(`[DEBUG] Skipped ${file.name} - self-referential default export`);
90
- }
91
- }
92
- } else if (debug) {
93
- console.log(`[DEBUG] multidefault_analyzeModules: Checking ${file.name}`);
94
- console.log(`[DEBUG] - fileName: ${fileName}`);
95
- console.log(`[DEBUG] - has default: ${hasRealDefault}`);
96
- if (isCjsFile) {
97
- console.log(`[DEBUG] - CJS file unwrapped from Node.js wrapper`);
98
- }
99
- }
100
- }
101
-
102
-
103
- const hasMultipleDefaultExports = totalDefaultExports > 1;
104
-
105
- if (debug) {
106
- console.log(`[DEBUG] multidefault_analyzeModules results:`);
107
- console.log(`[DEBUG] - selfReferentialFiles:`, Array.from(selfReferentialFiles));
108
- console.log(`[DEBUG] - totalDefaultExports:`, totalDefaultExports);
109
- console.log(`[DEBUG] - hasMultipleDefaultExports:`, hasMultipleDefaultExports);
110
- console.log(`[DEBUG] - defaultExportFiles count:`, defaultExportFiles.length);
111
- }
112
-
113
- return {
114
- totalDefaultExports,
115
- hasMultipleDefaultExports,
116
- selfReferentialFiles,
117
- rawModuleCache,
118
- defaultExportFiles
119
- };
120
- }
121
-
122
-
123
- function multidefault_isSelfReferential(rawModule) {
124
- if (!rawModule || !("default" in rawModule)) {
125
- return false;
126
- }
127
-
128
-
129
- return Object.entries(rawModule).some(([key, value]) => key !== "default" && value === rawModule.default);
130
- }
131
-
132
-
133
- function multidefault_getFlatteningDecision(options) {
134
- const {
135
- hasMultipleDefaultExports,
136
- moduleHasDefault,
137
- isSelfReferential,
138
- moduleKeys,
139
- apiPathKey,
140
- totalModuleCount,
141
- debug = false
142
- } = options;
143
-
144
- if (debug) {
145
- console.log(`[DEBUG] multidefault_getFlatteningDecision: Analyzing flattening for ${apiPathKey}`);
146
- console.log(`[DEBUG] - hasMultipleDefaultExports: ${hasMultipleDefaultExports}`);
147
- console.log(`[DEBUG] - moduleHasDefault: ${moduleHasDefault}`);
148
- console.log(`[DEBUG] - isSelfReferential: ${isSelfReferential}`);
149
- console.log(`[DEBUG] - moduleKeys: [${moduleKeys.join(", ")}]`);
150
- console.log(`[DEBUG] - totalModuleCount: ${totalModuleCount}`);
151
- }
152
-
153
-
154
- if (isSelfReferential) {
155
- return {
156
- shouldFlatten: false,
157
- flattenToRoot: false,
158
- preserveAsNamespace: true,
159
- reason: "self-referential default export"
160
- };
161
- }
162
-
163
-
164
- if (hasMultipleDefaultExports) {
165
- if (moduleHasDefault) {
166
-
167
- return {
168
- shouldFlatten: false,
169
- flattenToRoot: false,
170
- preserveAsNamespace: true,
171
- reason: "multi-default context with default export"
172
- };
173
- } else {
174
-
175
- return {
176
- shouldFlatten: true,
177
- flattenToRoot: true,
178
- preserveAsNamespace: false,
179
- reason: "multi-default context without default export"
180
- };
181
- }
182
- }
183
-
184
-
185
-
186
- if (moduleKeys.length === 1 && moduleKeys[0] === apiPathKey) {
187
- return {
188
- shouldFlatten: true,
189
- flattenToRoot: false,
190
- preserveAsNamespace: false,
191
- reason: "single named export matching filename"
192
- };
193
- }
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
- return {
209
- shouldFlatten: false,
210
- flattenToRoot: false,
211
- preserveAsNamespace: true,
212
- reason: "default namespace preservation"
213
- };
214
- }
215
-
216
- export { multidefault_analyzeModules, multidefault_isSelfReferential, multidefault_getFlatteningDecision };
@@ -1,154 +0,0 @@
1
- /*
2
- Copyright 2026 CLDMV/Shinrai
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- import fs from "node:fs/promises";
24
- import path from "node:path";
25
- import { processModuleForAPI } from "@cldmv/slothlet/helpers/api_builder";
26
- import { multidefault_analyzeModules } from "@cldmv/slothlet/helpers/multidefault";
27
-
28
-
29
-
30
-
31
-
32
- export async function create(dir, maxDepth = Infinity, currentDepth = 0) {
33
- const entries = await fs.readdir(dir, { withFileTypes: true });
34
- const api = {};
35
- let rootDefaultFunction = null;
36
-
37
-
38
- const moduleFiles = entries.filter((e) => this._shouldIncludeFile(e));
39
- const defaultExportFiles = [];
40
-
41
- const analysis = await multidefault_analyzeModules(moduleFiles, dir, { debug: this.config.debug, instance: this });
42
-
43
- const { totalDefaultExports, hasMultipleDefaultExports, selfReferentialFiles, defaultExportFiles: analysisDefaults } = analysis;
44
-
45
-
46
- defaultExportFiles.length = 0;
47
- for (const { fileName } of analysisDefaults) {
48
- const entry = moduleFiles.find((f) => path.basename(f.name, path.extname(f.name)) === fileName);
49
- if (entry) {
50
- const mod = await this._loadSingleModule(path.join(dir, entry.name));
51
- defaultExportFiles.push({ entry, fileName, mod });
52
- }
53
- }
54
-
55
- if (this.config.debug) {
56
- console.log(`[DEBUG] Eager mode: Using shared multidefault utility results`);
57
- console.log(
58
- `[DEBUG] Detection result: ${totalDefaultExports} total defaults (${defaultExportFiles.length} non-self-referential + ${selfReferentialFiles.size} self-referential), hasMultipleDefaultExports=${hasMultipleDefaultExports}`
59
- );
60
- console.log(
61
- `[DEBUG] Default export files:`,
62
- defaultExportFiles.map((f) => f.fileName)
63
- );
64
- }
65
-
66
-
67
- for (const entry of moduleFiles) {
68
- const ext = path.extname(entry.name);
69
- const fileName = path.basename(entry.name, ext);
70
- const apiPathKey = this._toapiPathKey(fileName);
71
-
72
-
73
- const moduleResult = await this._loadSingleModule(path.join(dir, entry.name), true);
74
- const mod = moduleResult.mod;
75
- const analysis = moduleResult.analysis;
76
-
77
-
78
- const isSelfReferential = selfReferentialFiles.has(fileName);
79
-
80
- processModuleForAPI({
81
- mod,
82
- fileName,
83
- apiPathKey,
84
- hasMultipleDefaultExports,
85
- isSelfReferential,
86
- api,
87
- getRootDefault: () => rootDefaultFunction,
88
- setRootDefault: (fn) => {
89
- rootDefaultFunction = fn;
90
- },
91
- context: {
92
- debug: this.config.debug,
93
- mode: "root",
94
- totalModules: moduleFiles.length
95
- },
96
- originalAnalysis: analysis
97
- });
98
- }
99
-
100
- for (const entry of entries) {
101
- if (entry.isDirectory() && !entry.name.startsWith(".") && currentDepth < maxDepth) {
102
- const categoryPath = path.join(dir, entry.name);
103
- const categoryKey = this._toapiPathKey(entry.name);
104
- const categoryResult = await this._buildCategory(categoryPath, {
105
- currentDepth: currentDepth + 1,
106
- maxDepth,
107
- mode: "eager",
108
- existingApi: api
109
- });
110
-
111
-
112
- if (
113
- api[categoryKey] &&
114
- typeof api[categoryKey] === "object" &&
115
- typeof categoryResult === "object" &&
116
- !Array.isArray(api[categoryKey]) &&
117
- !Array.isArray(categoryResult)
118
- ) {
119
- if (this.config.debug) {
120
- console.log(
121
- `[DEBUG] eager: Merging subdirectory '${categoryKey}' - existing:`,
122
- Object.keys(api[categoryKey]),
123
- "new:",
124
- Object.keys(categoryResult)
125
- );
126
- }
127
-
128
- Object.assign(api[categoryKey], categoryResult);
129
- } else {
130
- api[categoryKey] = categoryResult;
131
- }
132
- }
133
- }
134
-
135
- let finalApi;
136
- if (this.config.debug) {
137
- console.log(`[DEBUG] Final assembly: rootDefaultFunction=${!!rootDefaultFunction}`);
138
- console.log(`[DEBUG] API object keys before final assembly:`, Object.keys(api));
139
- }
140
- if (rootDefaultFunction) {
141
- Object.assign(rootDefaultFunction, api);
142
- finalApi = rootDefaultFunction;
143
- if (this.config.debug) {
144
- console.log(`[DEBUG] Applied root contributor pattern - final API is function`);
145
- }
146
- } else {
147
- finalApi = api;
148
- if (this.config.debug) {
149
- console.log(`[DEBUG] No root function - final API is object`);
150
- }
151
- }
152
-
153
- return finalApi;
154
- }