@cldmv/slothlet 2.7.1 → 2.9.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.
- package/AGENT-USAGE.md +1 -1
- package/README.md +253 -1475
- package/dist/lib/helpers/als-eventemitter.mjs +4 -5
- package/dist/lib/helpers/api_builder/add_api.mjs +237 -0
- package/dist/lib/helpers/api_builder/analysis.mjs +522 -0
- package/dist/lib/helpers/api_builder/construction.mjs +457 -0
- package/dist/lib/helpers/api_builder/decisions.mjs +737 -0
- package/dist/lib/helpers/api_builder.mjs +16 -1567
- package/dist/lib/helpers/utilities.mjs +121 -0
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +44 -17
- package/dist/lib/runtime/runtime-livebindings.mjs +18 -3
- package/dist/lib/runtime/runtime.mjs +3 -3
- package/dist/slothlet.mjs +197 -547
- package/docs/API-RULES-CONDITIONS.md +508 -0
- package/{API-RULES.md → docs/API-RULES.md} +127 -72
- package/index.cjs +2 -1
- package/index.mjs +2 -1
- package/package.json +11 -9
- package/types/dist/lib/helpers/als-eventemitter.d.mts.map +1 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +60 -0
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +1 -0
- package/types/dist/lib/helpers/api_builder/analysis.d.mts +189 -0
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +1 -0
- package/types/dist/lib/helpers/api_builder/construction.d.mts +107 -0
- package/types/dist/lib/helpers/api_builder/construction.d.mts.map +1 -0
- package/types/dist/lib/helpers/api_builder/decisions.d.mts +213 -0
- package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +1 -0
- package/types/dist/lib/helpers/api_builder.d.mts +5 -448
- package/types/dist/lib/helpers/api_builder.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +120 -0
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +7 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +8 -0
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +23 -13
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +0 -1
- package/API-RULES-CONDITIONS.md +0 -367
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 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 fs from "node:fs/promises";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { types as utilTypes } from "node:util";
|
|
24
|
+
import { pathToFileURL } from "node:url";
|
|
25
|
+
import { multidefault_analyzeModules } from "@cldmv/slothlet/helpers/multidefault";
|
|
26
|
+
import { setActiveInstance } from "@cldmv/slothlet/helpers/instance-manager";
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export function isLikelySerializable(val) {
|
|
34
|
+
const type = typeof val;
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (type !== "object" || val === null) {
|
|
38
|
+
return type === "string" || type === "number" || type === "boolean" || type === "undefined";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
Array.isArray(val) || val instanceof Date || val instanceof RegExp || val?.constructor === Object || typeof val.toJSON === "function"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export async function analyzeModule(modulePath, options = {}) {
|
|
53
|
+
const { debug = false, instance = null } = options;
|
|
54
|
+
|
|
55
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
let importUrl = moduleUrl;
|
|
59
|
+
if (instance && instance.instanceId) {
|
|
60
|
+
const runtimeType = instance.config?.runtime || "async";
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (runtimeType === "live") {
|
|
64
|
+
const separator = moduleUrl.includes("?") ? "&" : "?";
|
|
65
|
+
importUrl = `${moduleUrl}${separator}slothlet_instance=${instance.instanceId}`;
|
|
66
|
+
importUrl = `${importUrl}&slothlet_runtime=${runtimeType}`;
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
setActiveInstance(instance.instanceId);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const rawModule = await import(importUrl);
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
let processedModule = rawModule;
|
|
79
|
+
const isCjs = modulePath.endsWith(".cjs") && "default" in rawModule;
|
|
80
|
+
|
|
81
|
+
if (isCjs) {
|
|
82
|
+
processedModule = rawModule.default;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const hasDefault = !!processedModule.default;
|
|
86
|
+
const isFunction = typeof processedModule.default === "function";
|
|
87
|
+
const exports = Object.entries(processedModule);
|
|
88
|
+
const namedExports = Object.entries(processedModule).filter(([k]) => k !== "default");
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
let defaultExportType = null;
|
|
92
|
+
if (hasDefault) {
|
|
93
|
+
defaultExportType = typeof processedModule.default === "function" ? "function" : "object";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
let shouldWrapAsCallable = false;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
hasDefault &&
|
|
102
|
+
typeof processedModule.default === "object" &&
|
|
103
|
+
processedModule.default !== null &&
|
|
104
|
+
typeof processedModule.default.default === "function"
|
|
105
|
+
) {
|
|
106
|
+
shouldWrapAsCallable = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (!shouldWrapAsCallable) {
|
|
111
|
+
for (const [_, exportValue] of namedExports) {
|
|
112
|
+
if (typeof exportValue === "object" && exportValue !== null && typeof exportValue.default === "function") {
|
|
113
|
+
shouldWrapAsCallable = true;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (debug) {
|
|
120
|
+
console.log(`[DEBUG] analyzeModule(${path.basename(modulePath)}):`, {
|
|
121
|
+
isCjs,
|
|
122
|
+
hasDefault,
|
|
123
|
+
isFunction,
|
|
124
|
+
defaultExportType,
|
|
125
|
+
shouldWrapAsCallable,
|
|
126
|
+
namedExportsCount: namedExports.length
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
rawModule,
|
|
132
|
+
processedModule,
|
|
133
|
+
isFunction,
|
|
134
|
+
hasDefault,
|
|
135
|
+
isCjs,
|
|
136
|
+
exports,
|
|
137
|
+
defaultExportType,
|
|
138
|
+
shouldWrapAsCallable,
|
|
139
|
+
namedExports,
|
|
140
|
+
metadata: { modulePath }
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
export function processModuleFromAnalysis(analysis, options = {}) {
|
|
146
|
+
const { instance, debug = false } = options;
|
|
147
|
+
const { processedModule, isFunction, hasDefault, shouldWrapAsCallable, namedExports } = analysis;
|
|
148
|
+
|
|
149
|
+
if (!instance) {
|
|
150
|
+
throw new Error("processModuleFromAnalysis requires instance parameter for _toapiPathKey access");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
if (isFunction) {
|
|
155
|
+
let fn = processedModule.default;
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if (hasDefault) {
|
|
159
|
+
try {
|
|
160
|
+
Object.defineProperty(fn, "__slothletDefault", {
|
|
161
|
+
value: true,
|
|
162
|
+
writable: false,
|
|
163
|
+
enumerable: false,
|
|
164
|
+
configurable: true
|
|
165
|
+
});
|
|
166
|
+
} catch {
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
for (const [exportName, exportValue] of Object.entries(processedModule)) {
|
|
173
|
+
if (exportName !== "default") {
|
|
174
|
+
fn[instance._toapiPathKey(exportName)] = exportValue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return fn;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
if (shouldWrapAsCallable) {
|
|
182
|
+
let callableObject = null;
|
|
183
|
+
let objectName = "callable";
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if (
|
|
187
|
+
hasDefault &&
|
|
188
|
+
typeof processedModule.default === "object" &&
|
|
189
|
+
processedModule.default !== null &&
|
|
190
|
+
typeof processedModule.default.default === "function"
|
|
191
|
+
) {
|
|
192
|
+
callableObject = processedModule.default;
|
|
193
|
+
objectName = processedModule.default.name || (namedExports[0] && namedExports[0][0] !== "default" ? namedExports[0][0] : "callable");
|
|
194
|
+
} else {
|
|
195
|
+
|
|
196
|
+
for (const [exportName, exportValue] of namedExports) {
|
|
197
|
+
if (typeof exportValue === "object" && exportValue !== null && typeof exportValue.default === "function") {
|
|
198
|
+
callableObject = exportValue;
|
|
199
|
+
objectName = exportName;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (callableObject) {
|
|
206
|
+
const callableApi = {
|
|
207
|
+
[objectName]: function (...args) {
|
|
208
|
+
return callableObject.default.apply(callableObject, args);
|
|
209
|
+
}
|
|
210
|
+
}[objectName];
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
for (const [methodName, method] of Object.entries(callableObject)) {
|
|
214
|
+
if (methodName === "default") continue;
|
|
215
|
+
callableApi[methodName] = method;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (debug) {
|
|
219
|
+
console.log(`[DEBUG] Created callable wrapper for ${objectName}`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return callableApi;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if (hasDefault && typeof processedModule.default === "object") {
|
|
228
|
+
const obj = processedModule.default;
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
const namedExportsToAdd = Object.entries(processedModule).filter(
|
|
232
|
+
([exportName, exportValue]) => exportName !== "default" && exportValue !== obj
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
if (namedExportsToAdd.length > 0) {
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
const isCustomProxy = utilTypes?.isProxy?.(obj) ?? false;
|
|
239
|
+
|
|
240
|
+
if (isCustomProxy) {
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
for (const [exportName, exportValue] of namedExportsToAdd) {
|
|
244
|
+
const apiKey = instance._toapiPathKey(exportName);
|
|
245
|
+
obj[apiKey] = exportValue;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
const proxyWithStructure = obj;
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
proxyWithStructure.default = obj;
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
if (!proxyWithStructure.toJSON) {
|
|
275
|
+
Object.defineProperty(proxyWithStructure, "toJSON", {
|
|
276
|
+
value: function () {
|
|
277
|
+
|
|
278
|
+
const serializable = {};
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
for (const key of Reflect.ownKeys(this)) {
|
|
282
|
+
|
|
283
|
+
if (typeof key !== "string") continue;
|
|
284
|
+
|
|
285
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(this, key);
|
|
286
|
+
if (!descriptor || !descriptor.enumerable) continue;
|
|
287
|
+
|
|
288
|
+
if (key === "default") {
|
|
289
|
+
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const value = this[key];
|
|
294
|
+
if (typeof value === "function") {
|
|
295
|
+
serializable[key] = "[Function]";
|
|
296
|
+
} else if (isLikelySerializable(value)) {
|
|
297
|
+
|
|
298
|
+
serializable[key] = value;
|
|
299
|
+
} else {
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
JSON.stringify(value);
|
|
303
|
+
serializable[key] = value;
|
|
304
|
+
} catch {
|
|
305
|
+
serializable[key] = "[Non-serializable value]";
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
serializable._slothlet_proxy_info = {
|
|
312
|
+
type: "proxy",
|
|
313
|
+
circular_reference: "Property .default points to this object (excluded from serialization)",
|
|
314
|
+
warning: "This is a slothlet API proxy with circular .default reference"
|
|
315
|
+
};
|
|
316
|
+
return serializable;
|
|
317
|
+
},
|
|
318
|
+
writable: false,
|
|
319
|
+
enumerable: false,
|
|
320
|
+
configurable: true
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
for (const [exportName, exportValue] of namedExportsToAdd) {
|
|
326
|
+
const apiKey = instance._toapiPathKey(exportName);
|
|
327
|
+
if (!(apiKey in proxyWithStructure)) {
|
|
328
|
+
proxyWithStructure[apiKey] = exportValue;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return proxyWithStructure;
|
|
333
|
+
} else {
|
|
334
|
+
|
|
335
|
+
for (const [exportName, exportValue] of namedExportsToAdd) {
|
|
336
|
+
obj[instance._toapiPathKey(exportName)] = exportValue;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return obj;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return obj;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
if (namedExports.length > 0) {
|
|
348
|
+
const apiExport = {};
|
|
349
|
+
for (const [exportName, exportValue] of namedExports) {
|
|
350
|
+
apiExport[instance._toapiPathKey(exportName)] = exportValue;
|
|
351
|
+
}
|
|
352
|
+
return apiExport;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
throw new Error(`No valid exports found in processed module`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
export async function analyzeDirectoryStructure(categoryPath, options = {}) {
|
|
361
|
+
const { instance, currentDepth = 0, debug = false } = options;
|
|
362
|
+
|
|
363
|
+
if (!instance || typeof instance._toapiPathKey !== "function") {
|
|
364
|
+
throw new Error("analyzeDirectoryStructure requires a valid slothlet instance");
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const files = await fs.readdir(categoryPath, { withFileTypes: true });
|
|
368
|
+
const moduleFiles = files.filter((f) => instance._shouldIncludeFile(f));
|
|
369
|
+
const categoryName = instance._toapiPathKey(path.basename(categoryPath));
|
|
370
|
+
const subDirs = files.filter((e) => e.isDirectory() && !e.name.startsWith("."));
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
let processingStrategy;
|
|
374
|
+
if (moduleFiles.length === 0) {
|
|
375
|
+
processingStrategy = "empty";
|
|
376
|
+
} else if (moduleFiles.length === 1 && subDirs.length === 0) {
|
|
377
|
+
processingStrategy = "single-file";
|
|
378
|
+
} else {
|
|
379
|
+
processingStrategy = "multi-file";
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
let multiDefaultAnalysis = null;
|
|
384
|
+
if (processingStrategy === "multi-file") {
|
|
385
|
+
multiDefaultAnalysis = await multidefault_analyzeModules(moduleFiles, categoryPath, { debug, instance });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
const flatteningHints = {
|
|
390
|
+
shouldFlattenSingleFile: processingStrategy === "single-file",
|
|
391
|
+
shouldFlattenToParent: currentDepth > 0 && processingStrategy === "single-file",
|
|
392
|
+
hasMultipleDefaults: multiDefaultAnalysis?.hasMultipleDefaultExports || false,
|
|
393
|
+
selfReferentialFiles: multiDefaultAnalysis?.selfReferentialFiles || new Set()
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
if (debug) {
|
|
397
|
+
console.log(`[DEBUG] analyzeDirectoryStructure(${categoryName}):`, {
|
|
398
|
+
processingStrategy,
|
|
399
|
+
moduleCount: moduleFiles.length,
|
|
400
|
+
subDirCount: subDirs.length,
|
|
401
|
+
hasMultipleDefaults: flatteningHints.hasMultipleDefaults
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
isSingleFile: processingStrategy === "single-file",
|
|
407
|
+
shouldAutoFlatten: flatteningHints.shouldFlattenSingleFile,
|
|
408
|
+
categoryName,
|
|
409
|
+
moduleFiles,
|
|
410
|
+
subDirs,
|
|
411
|
+
multiDefaultAnalysis,
|
|
412
|
+
processingStrategy,
|
|
413
|
+
flatteningHints
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
export async function getCategoryBuildingDecisions(categoryPath, options = {}) {
|
|
419
|
+
const { instance, currentDepth = 0, maxDepth = Infinity, debug = false } = options;
|
|
420
|
+
|
|
421
|
+
if (!instance) {
|
|
422
|
+
throw new Error("getCategoryBuildingDecisions requires a valid slothlet instance");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const analysis = await analyzeDirectoryStructure(categoryPath, { instance, currentDepth, maxDepth, debug });
|
|
426
|
+
const { processingStrategy, categoryName, moduleFiles, subDirs, multiDefaultAnalysis } = analysis;
|
|
427
|
+
|
|
428
|
+
const processedModules = [];
|
|
429
|
+
const subDirectories = [];
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
if (processingStrategy !== "empty") {
|
|
433
|
+
for (const file of moduleFiles) {
|
|
434
|
+
const moduleExt = path.extname(file.name);
|
|
435
|
+
const moduleName = instance._toapiPathKey(path.basename(file.name, moduleExt));
|
|
436
|
+
const modulePath = path.join(categoryPath, file.name);
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
const analysis = await analyzeModule(modulePath, {
|
|
440
|
+
debug,
|
|
441
|
+
instance
|
|
442
|
+
});
|
|
443
|
+
const processedModule = processModuleFromAnalysis(analysis, {
|
|
444
|
+
debug,
|
|
445
|
+
instance
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
const flatteningInfo = {
|
|
450
|
+
shouldFlatten: false,
|
|
451
|
+
apiPathKey: moduleName,
|
|
452
|
+
reason: "default"
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
if (processingStrategy === "single-file") {
|
|
457
|
+
|
|
458
|
+
const functionNameMatchesFolder =
|
|
459
|
+
typeof processedModule === "function" &&
|
|
460
|
+
processedModule.name &&
|
|
461
|
+
processedModule.name.toLowerCase() === categoryName.toLowerCase();
|
|
462
|
+
|
|
463
|
+
const moduleNameMatchesCategory = moduleName === categoryName && typeof processedModule === "function" && currentDepth > 0;
|
|
464
|
+
|
|
465
|
+
if (functionNameMatchesFolder && currentDepth > 0) {
|
|
466
|
+
flatteningInfo.shouldFlatten = true;
|
|
467
|
+
flatteningInfo.apiPathKey = processedModule.name;
|
|
468
|
+
flatteningInfo.reason = "function name matches folder";
|
|
469
|
+
} else if (moduleNameMatchesCategory) {
|
|
470
|
+
flatteningInfo.shouldFlatten = true;
|
|
471
|
+
flatteningInfo.apiPathKey = categoryName;
|
|
472
|
+
flatteningInfo.reason = "module name matches category";
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
processedModules.push({
|
|
477
|
+
file,
|
|
478
|
+
moduleName,
|
|
479
|
+
processedModule,
|
|
480
|
+
flattening: flatteningInfo
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
for (const subDirEntry of subDirs) {
|
|
487
|
+
if (currentDepth < maxDepth) {
|
|
488
|
+
const apiPathKey = instance._toapiPathKey(subDirEntry.name);
|
|
489
|
+
subDirectories.push({ dirEntry: subDirEntry, apiPathKey });
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
const upwardFlatteningCandidate = { shouldFlatten: false, apiPathKey: null };
|
|
495
|
+
if (processedModules.length === 1 && subDirectories.length === 0) {
|
|
496
|
+
const single = processedModules[0];
|
|
497
|
+
if (single.moduleName === categoryName) {
|
|
498
|
+
upwardFlatteningCandidate.shouldFlatten = true;
|
|
499
|
+
upwardFlatteningCandidate.apiPathKey = single.moduleName;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (debug) {
|
|
504
|
+
console.log(`[DEBUG] getCategoryBuildingDecisions(${categoryName}):`, {
|
|
505
|
+
processingStrategy,
|
|
506
|
+
moduleCount: processedModules.length,
|
|
507
|
+
subDirCount: subDirectories.length,
|
|
508
|
+
upwardFlattening: upwardFlatteningCandidate.shouldFlatten
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return {
|
|
513
|
+
processingStrategy,
|
|
514
|
+
categoryName,
|
|
515
|
+
shouldFlattenSingle: processingStrategy === "single-file",
|
|
516
|
+
processedModules,
|
|
517
|
+
subDirectories,
|
|
518
|
+
multiDefaultAnalysis,
|
|
519
|
+
flatteningDecisions: analysis.flatteningHints,
|
|
520
|
+
upwardFlatteningCandidate
|
|
521
|
+
};
|
|
522
|
+
}
|