@cldmv/slothlet 3.2.3 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -9
- package/REFERENCE.md +23 -0
- package/dist/lib/builders/api-assignment.mjs +1 -589
- package/dist/lib/builders/api_builder.mjs +1 -1155
- package/dist/lib/builders/builder.mjs +1 -78
- package/dist/lib/builders/modes-processor.mjs +1 -1800
- package/dist/lib/errors.mjs +9 -211
- package/dist/lib/factories/component-base.mjs +1 -80
- package/dist/lib/factories/context.mjs +1 -22
- package/dist/lib/handlers/api-cache-manager.mjs +1 -200
- package/dist/lib/handlers/api-manager.mjs +1 -2513
- package/dist/lib/handlers/context-async.mjs +1 -168
- package/dist/lib/handlers/context-live.mjs +1 -168
- package/dist/lib/handlers/hook-manager.mjs +1 -773
- package/dist/lib/handlers/lifecycle-token.mjs +1 -28
- package/dist/lib/handlers/lifecycle.mjs +1 -115
- package/dist/lib/handlers/materialize-manager.mjs +1 -48
- package/dist/lib/handlers/metadata.mjs +1 -501
- package/dist/lib/handlers/ownership.mjs +1 -322
- package/dist/lib/handlers/permission-manager.mjs +17 -0
- package/dist/lib/handlers/unified-wrapper.mjs +1 -3042
- package/dist/lib/handlers/version-manager.mjs +1 -885
- package/dist/lib/helpers/class-instance-wrapper.mjs +1 -109
- package/dist/lib/helpers/config.mjs +1 -355
- package/dist/lib/helpers/eventemitter-context.mjs +1 -349
- package/dist/lib/helpers/hint-detector.mjs +1 -47
- package/dist/lib/helpers/modes-utils.mjs +1 -37
- package/dist/lib/helpers/pattern-matcher.mjs +17 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +1 -169
- package/dist/lib/helpers/sanitize.mjs +1 -340
- package/dist/lib/helpers/utilities.mjs +1 -70
- package/dist/lib/i18n/languages/de-de.json +21 -1
- package/dist/lib/i18n/languages/en-gb.json +21 -1
- package/dist/lib/i18n/languages/en-us.json +21 -1
- package/dist/lib/i18n/languages/es-mx.json +21 -1
- package/dist/lib/i18n/languages/fr-fr.json +21 -1
- package/dist/lib/i18n/languages/hi-in.json +21 -1
- package/dist/lib/i18n/languages/ja-jp.json +21 -1
- package/dist/lib/i18n/languages/ko-kr.json +21 -1
- package/dist/lib/i18n/languages/pt-br.json +21 -1
- package/dist/lib/i18n/languages/ru-ru.json +21 -1
- package/dist/lib/i18n/languages/zh-cn.json +21 -1
- package/dist/lib/i18n/translations.mjs +1 -126
- package/dist/lib/modes/eager.mjs +1 -59
- package/dist/lib/modes/lazy.mjs +1 -81
- package/dist/lib/processors/flatten.mjs +1 -437
- package/dist/lib/processors/loader.mjs +1 -339
- package/dist/lib/processors/type-generator.mjs +1 -275
- package/dist/lib/processors/typescript.mjs +1 -172
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +1 -113
- package/dist/lib/runtime/runtime-livebindings.mjs +1 -78
- package/dist/lib/runtime/runtime.mjs +1 -102
- package/dist/slothlet.mjs +1 -808
- package/package.json +37 -31
- package/types/dist/lib/builders/api-assignment.d.mts +3 -92
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -1
- package/types/dist/lib/builders/api_builder.d.mts +102 -91
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
- package/types/dist/lib/builders/builder.d.mts +1 -55
- package/types/dist/lib/builders/builder.d.mts.map +1 -1
- package/types/dist/lib/builders/modes-processor.d.mts +3 -27
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -1
- package/types/dist/lib/errors.d.mts +19 -109
- package/types/dist/lib/errors.d.mts.map +1 -1
- package/types/dist/lib/factories/component-base.d.mts +7 -177
- package/types/dist/lib/factories/component-base.d.mts.map +1 -1
- package/types/dist/lib/factories/context.d.mts +4 -22
- package/types/dist/lib/factories/context.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-cache-manager.d.mts +20 -203
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-manager.d.mts +33 -408
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-async.d.mts +23 -61
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-live.d.mts +22 -59
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -1
- package/types/dist/lib/handlers/hook-manager.d.mts +46 -185
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle-token.d.mts +3 -48
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle.d.mts +5 -82
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -1
- package/types/dist/lib/handlers/materialize-manager.d.mts +8 -70
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/metadata.d.mts +17 -221
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -1
- package/types/dist/lib/handlers/ownership.d.mts +44 -160
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -1
- package/types/dist/lib/handlers/permission-manager.d.mts +47 -0
- package/types/dist/lib/handlers/permission-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +26 -239
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -1
- package/types/dist/lib/handlers/version-manager.d.mts +28 -225
- package/types/dist/lib/handlers/version-manager.d.mts.map +1 -1
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +2 -52
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -1
- package/types/dist/lib/helpers/config.d.mts +125 -123
- package/types/dist/lib/helpers/config.d.mts.map +1 -1
- package/types/dist/lib/helpers/eventemitter-context.d.mts +3 -29
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -1
- package/types/dist/lib/helpers/hint-detector.d.mts +2 -15
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -1
- package/types/dist/lib/helpers/modes-utils.d.mts +3 -30
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -1
- package/types/dist/lib/helpers/pattern-matcher.d.mts +4 -0
- package/types/dist/lib/helpers/pattern-matcher.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +3 -27
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +4 -92
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +4 -52
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +4 -37
- package/types/dist/lib/i18n/translations.d.mts.map +1 -1
- package/types/dist/lib/modes/eager.d.mts +8 -30
- package/types/dist/lib/modes/eager.d.mts.map +1 -1
- package/types/dist/lib/modes/lazy.d.mts +10 -43
- package/types/dist/lib/modes/lazy.d.mts.map +1 -1
- package/types/dist/lib/processors/flatten.d.mts +56 -107
- package/types/dist/lib/processors/flatten.d.mts.map +1 -1
- package/types/dist/lib/processors/loader.d.mts +6 -41
- package/types/dist/lib/processors/loader.d.mts.map +1 -1
- package/types/dist/lib/processors/type-generator.d.mts +2 -16
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -1
- package/types/dist/lib/processors/typescript.d.mts +6 -53
- package/types/dist/lib/processors/typescript.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +3 -71
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -37
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +3 -39
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +3 -249
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +36 -16
- package/types/index.d.mts.map +1 -0
- package/AGENT-USAGE.md +0 -736
- package/docs/API-RULES.md +0 -712
|
@@ -14,440 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export class Flatten extends ComponentBase {
|
|
24
|
-
static slothletProperty = "flatten";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
constructor(slothlet) {
|
|
28
|
-
super(slothlet);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
#checkSelfReferential(mod, moduleName) {
|
|
33
|
-
if (!mod || typeof mod !== "object") return false;
|
|
34
|
-
return mod[moduleName] === mod;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
async #checkMultiDefault(analysis, hasMultipleDefaults, t) {
|
|
39
|
-
if (!hasMultipleDefaults) return null;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (analysis.hasDefault) {
|
|
43
|
-
return {
|
|
44
|
-
preserveAsNamespace: true,
|
|
45
|
-
reason: await t("FLATTEN_REASON_MULTI_DEFAULT_WITH_DEFAULT")
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
flattenToRoot: true,
|
|
52
|
-
reason: await t("FLATTEN_REASON_MULTI_DEFAULT_WITHOUT_DEFAULT")
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#checkAutoFlatten(mod, moduleName, moduleKeys) {
|
|
58
|
-
if (moduleKeys.length !== 1) return false;
|
|
59
|
-
return moduleKeys[0] === moduleName;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
async getFlatteningDecision(options) {
|
|
64
|
-
const { mod, moduleName, categoryName, analysis, hasMultipleDefaults, moduleKeys, t } = options;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const isAddapiFile = moduleName === "addapi";
|
|
69
|
-
if (isAddapiFile) {
|
|
70
|
-
|
|
71
|
-
if (analysis.hasDefault && analysis.defaultExportType === "object" && moduleKeys.length > 0) {
|
|
72
|
-
return {
|
|
73
|
-
flattenToCategory: true,
|
|
74
|
-
flattenType: "addapi-metadata-default",
|
|
75
|
-
reason: await t("FLATTEN_REASON_ADDAPI_METADATA_DEFAULT")
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
flattenToCategory: true,
|
|
81
|
-
flattenType: "addapi-special-file",
|
|
82
|
-
reason: await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE")
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (this.#checkSelfReferential(mod, moduleName)) {
|
|
88
|
-
return {
|
|
89
|
-
preserveAsNamespace: true,
|
|
90
|
-
reason: await t("FLATTEN_REASON_SELF_REFERENTIAL")
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const multiDefaultDecision = await this.#checkMultiDefault(analysis, hasMultipleDefaults, t);
|
|
96
|
-
if (multiDefaultDecision) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (multiDefaultDecision.preserveAsNamespace) {
|
|
100
|
-
const exportToCheck = typeof mod === "function" ? mod : mod?.default && typeof mod.default === "function" ? mod.default : null;
|
|
101
|
-
if (exportToCheck && exportToCheck.name && exportToCheck.name !== "default") {
|
|
102
|
-
const normalizedFunctionName = exportToCheck.name.toLowerCase().replace(/[-_]/g, "");
|
|
103
|
-
const normalizedModuleName = moduleName.toLowerCase().replace(/[-_]/g, "");
|
|
104
|
-
if (normalizedFunctionName === normalizedModuleName) {
|
|
105
|
-
multiDefaultDecision.preferredName = exportToCheck.name;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return multiDefaultDecision;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (this.#checkAutoFlatten(mod, moduleName, moduleKeys)) {
|
|
114
|
-
return {
|
|
115
|
-
useAutoFlattening: true,
|
|
116
|
-
reason: await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_FILENAME")
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (moduleName === categoryName) {
|
|
122
|
-
return {
|
|
123
|
-
flattenToCategory: true,
|
|
124
|
-
reason: await t("FLATTEN_REASON_FILENAME_MATCHES_CATEGORY")
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const exportToCheck = typeof mod === "function" ? mod : mod?.default && typeof mod.default === "function" ? mod.default : null;
|
|
131
|
-
|
|
132
|
-
if (exportToCheck && exportToCheck.name && exportToCheck.name !== "default") {
|
|
133
|
-
|
|
134
|
-
const normalizedFunctionName = exportToCheck.name.toLowerCase().replace(/[-_]/g, "");
|
|
135
|
-
const normalizedModuleName = moduleName.toLowerCase().replace(/[-_]/g, "");
|
|
136
|
-
const functionNameMatchesFilename = normalizedFunctionName === normalizedModuleName;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (functionNameMatchesFilename) {
|
|
140
|
-
return {
|
|
141
|
-
preserveAsNamespace: true,
|
|
142
|
-
preferredName: exportToCheck.name,
|
|
143
|
-
reason: await t("FLATTEN_REASON_PRESERVING_FUNCTION_NAME")
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
preserveAsNamespace: true,
|
|
155
|
-
reason: await t("FLATTEN_REASON_DEFAULT_PRESERVE_NAMESPACE")
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
processModuleForAPI(options) {
|
|
161
|
-
const {
|
|
162
|
-
mod,
|
|
163
|
-
decision,
|
|
164
|
-
moduleName,
|
|
165
|
-
propertyName,
|
|
166
|
-
moduleKeys,
|
|
167
|
-
analysis,
|
|
168
|
-
file = null,
|
|
169
|
-
collisionContext = "initial",
|
|
170
|
-
apiPathPrefix = "",
|
|
171
|
-
isSelfReferential = false
|
|
172
|
-
} = options;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const isAddapiFile =
|
|
178
|
-
moduleName === "addapi" ||
|
|
179
|
-
(file && file.name === "addapi") ||
|
|
180
|
-
(file && file.fullName && ["addapi.mjs", "addapi.cjs", "addapi.js", "addapi.ts"].includes(file.fullName.toLowerCase()));
|
|
181
|
-
if (isAddapiFile && analysis.hasDefault && moduleKeys.length > 0) {
|
|
182
|
-
const moduleContent = mod.default;
|
|
183
|
-
for (const key of moduleKeys) {
|
|
184
|
-
moduleContent[key] = mod[key];
|
|
185
|
-
}
|
|
186
|
-
return { moduleContent };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (decision.useAutoFlattening) {
|
|
191
|
-
return { moduleContent: mod[moduleName] };
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (decision.flattenToRoot || decision.flattenToCategory) {
|
|
196
|
-
if (mod.default && moduleKeys.length === 0) {
|
|
197
|
-
return { moduleContent: mod.default };
|
|
198
|
-
}
|
|
199
|
-
if (mod.default && moduleKeys.length > 0) {
|
|
200
|
-
const moduleContent = typeof mod.default === "function" ? mod.default : { ...mod.default };
|
|
201
|
-
for (const key of moduleKeys) {
|
|
202
|
-
moduleContent[key] = mod[key];
|
|
203
|
-
}
|
|
204
|
-
return { moduleContent };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const moduleContent = {};
|
|
208
|
-
for (const key of moduleKeys) {
|
|
209
|
-
moduleContent[key] = mod[key];
|
|
210
|
-
}
|
|
211
|
-
return { moduleContent };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (isSelfReferential) {
|
|
216
|
-
return { moduleContent: mod[moduleName] || mod };
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (mod.default && moduleKeys.length > 0) {
|
|
221
|
-
if (typeof mod.default === "function") {
|
|
222
|
-
|
|
223
|
-
const moduleContent = this.slothlet.helpers.modesUtils.ensureNamedExportFunction(mod.default, propertyName);
|
|
224
|
-
const collisionConfig = this.slothlet.config.api?.collision || this.slothlet.config.collision;
|
|
225
|
-
const collisionMode = collisionContext === "initial" ? collisionConfig.initial : collisionConfig.api;
|
|
226
|
-
for (const key of moduleKeys) {
|
|
227
|
-
if (!this.shouldAttachNamedExport(key, mod[key], moduleContent, mod.default)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const hasExisting = Object.prototype.hasOwnProperty.call(moduleContent, key);
|
|
231
|
-
if (hasExisting) {
|
|
232
|
-
if (collisionMode === "merge" || collisionMode === "skip") {
|
|
233
|
-
|
|
234
|
-
continue;
|
|
235
|
-
} else if (collisionMode === "error") {
|
|
236
|
-
throw new this.slothlet.SlothletError(
|
|
237
|
-
"COLLISION_DEFAULT_EXPORT_ERROR",
|
|
238
|
-
{
|
|
239
|
-
key,
|
|
240
|
-
apiPath: `${apiPathPrefix}.${propertyName}`
|
|
241
|
-
},
|
|
242
|
-
null,
|
|
243
|
-
{ validationError: true }
|
|
244
|
-
);
|
|
245
|
-
} else if (collisionMode === "warn") {
|
|
246
|
-
new this.slothlet.SlothletWarning("WARNING_COLLISION_DEFAULT_EXPORT_OVERWRITE", {
|
|
247
|
-
key,
|
|
248
|
-
apiPath: `${apiPathPrefix}.${propertyName}`
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
moduleContent[key] = mod[key];
|
|
254
|
-
}
|
|
255
|
-
return { moduleContent };
|
|
256
|
-
}
|
|
257
|
-
if (typeof mod.default === "object" && mod.default !== null) {
|
|
258
|
-
|
|
259
|
-
const moduleContent = mod.default;
|
|
260
|
-
for (const key of moduleKeys) {
|
|
261
|
-
if (key in mod.default) {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (!this.shouldAttachNamedExport(key, mod[key], moduleContent, mod.default)) {
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
moduleContent[key] = mod[key];
|
|
268
|
-
}
|
|
269
|
-
return { moduleContent };
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const moduleContent = { default: mod.default };
|
|
273
|
-
for (const key of moduleKeys) {
|
|
274
|
-
moduleContent[key] = mod[key];
|
|
275
|
-
}
|
|
276
|
-
return { moduleContent };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (mod.default && moduleKeys.length === 0) {
|
|
281
|
-
return { moduleContent: this.slothlet.helpers.modesUtils.ensureNamedExportFunction(mod.default, propertyName) };
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const moduleContent = {};
|
|
286
|
-
for (const key of moduleKeys) {
|
|
287
|
-
moduleContent[key] = mod[key];
|
|
288
|
-
}
|
|
289
|
-
return { moduleContent };
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
async buildCategoryDecisions(options) {
|
|
294
|
-
const { categoryName, mod, moduleName, fileBaseName, analysis, moduleKeys, currentDepth, moduleFiles = [], t } = options;
|
|
295
|
-
|
|
296
|
-
const decision = {
|
|
297
|
-
shouldFlatten: false,
|
|
298
|
-
flattenType: "preserve",
|
|
299
|
-
preferredName: null,
|
|
300
|
-
reason: await t("FLATTEN_REASON_NO_CONDITIONS_MET")
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const isAddapiFile =
|
|
306
|
-
moduleName === "addapi" ||
|
|
307
|
-
fileBaseName === "addapi" ||
|
|
308
|
-
(fileBaseName && ["addapi.mjs", "addapi.cjs", "addapi.js", "addapi.ts"].includes(fileBaseName.toLowerCase()));
|
|
309
|
-
if (isAddapiFile) {
|
|
310
|
-
|
|
311
|
-
if (analysis.hasDefault && analysis.defaultExportType === "object" && moduleKeys.length > 0) {
|
|
312
|
-
return {
|
|
313
|
-
shouldFlatten: true,
|
|
314
|
-
flattenType: "addapi-metadata-default",
|
|
315
|
-
reason: await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE_PARENT")
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return {
|
|
320
|
-
shouldFlatten: true,
|
|
321
|
-
flattenType: "addapi-special-file",
|
|
322
|
-
reason: await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE")
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (moduleName === categoryName && typeof mod === "function" && currentDepth > 0) {
|
|
328
|
-
return {
|
|
329
|
-
shouldFlatten: true,
|
|
330
|
-
flattenType: "function-folder-match",
|
|
331
|
-
reason: await t("FLATTEN_REASON_FUNCTION_FOLDER_MATCH")
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (analysis.hasDefault && analysis.defaultExportType === "object" && moduleName === categoryName && currentDepth > 0) {
|
|
337
|
-
return {
|
|
338
|
-
shouldFlatten: true,
|
|
339
|
-
flattenType: "default-export-flatten",
|
|
340
|
-
reason: await t("FLATTEN_REASON_DEFAULT_OBJECT_EXPORT_FLATTEN")
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (moduleName === categoryName && mod && typeof mod === "object" && !Array.isArray(mod) && currentDepth > 0) {
|
|
346
|
-
if (moduleKeys.length === 1 && moduleKeys[0] === moduleName) {
|
|
347
|
-
return {
|
|
348
|
-
shouldFlatten: true,
|
|
349
|
-
flattenType: "object-auto-flatten",
|
|
350
|
-
reason: await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_FILENAME")
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (fileBaseName === categoryName && moduleKeys.length > 0) {
|
|
357
|
-
return {
|
|
358
|
-
shouldFlatten: true,
|
|
359
|
-
flattenType: "filename-folder-match-flatten",
|
|
360
|
-
reason: await t("FLATTEN_REASON_BASENAME_MATCHES_CATEGORY")
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (moduleFiles.length === 1 && currentDepth > 0 && mod && typeof mod === "object" && !Array.isArray(mod)) {
|
|
366
|
-
const genericFilenames = ["singlefile", "index", "main", "default"];
|
|
367
|
-
const isGenericFilename = genericFilenames.includes(moduleName.toLowerCase());
|
|
368
|
-
|
|
369
|
-
if (moduleKeys.length === 1 && isGenericFilename) {
|
|
370
|
-
return {
|
|
371
|
-
shouldFlatten: true,
|
|
372
|
-
flattenType: "parent-level-flatten",
|
|
373
|
-
reason: await t("FLATTEN_REASON_GENERIC_FILENAME_SINGLE_EXPORT")
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (typeof mod === "function" && mod.name && currentDepth > 0) {
|
|
380
|
-
const functionNameMatchesFolder =
|
|
381
|
-
mod.name.toLowerCase() === categoryName.toLowerCase() ||
|
|
382
|
-
mod.name.toLowerCase().replace(/[-_]/g, "") === categoryName.toLowerCase().replace(/[-_]/g, "");
|
|
383
|
-
|
|
384
|
-
if (functionNameMatchesFolder) {
|
|
385
|
-
return {
|
|
386
|
-
shouldFlatten: true,
|
|
387
|
-
flattenType: "function-folder-match",
|
|
388
|
-
preferredName: mod.name,
|
|
389
|
-
reason: await t("FLATTEN_REASON_FUNCTION_FOLDER_MATCH")
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const exportToCheck = typeof mod === "function" ? mod : mod?.default && typeof mod.default === "function" ? mod.default : null;
|
|
397
|
-
|
|
398
|
-
if (exportToCheck && exportToCheck.name && exportToCheck.name !== "default") {
|
|
399
|
-
|
|
400
|
-
const normalizedFunctionName = exportToCheck.name.toLowerCase().replace(/[-_]/g, "");
|
|
401
|
-
const normalizedModuleName = moduleName.toLowerCase().replace(/[-_]/g, "");
|
|
402
|
-
const functionNameMatchesFilename = normalizedFunctionName === normalizedModuleName;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (functionNameMatchesFilename) {
|
|
406
|
-
return {
|
|
407
|
-
shouldFlatten: false,
|
|
408
|
-
preferredName: exportToCheck.name,
|
|
409
|
-
reason: await t("FLATTEN_REASON_PRESERVING_FUNCTION_NAME")
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (typeof mod === "function" && (!mod.name || mod.name === "default" || mod.__slothletDefault === true) && currentDepth > 0) {
|
|
416
|
-
return {
|
|
417
|
-
shouldFlatten: true,
|
|
418
|
-
flattenType: "default-function",
|
|
419
|
-
preferredName: categoryName,
|
|
420
|
-
reason: await t("FLATTEN_REASON_DEFAULT_FUNCTION_EXPORT")
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (moduleKeys.length === 1 && moduleKeys[0] === moduleName) {
|
|
426
|
-
return {
|
|
427
|
-
shouldFlatten: true,
|
|
428
|
-
flattenType: "object-auto-flatten",
|
|
429
|
-
preferredName: moduleName,
|
|
430
|
-
reason: await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_MODULE")
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return decision;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
shouldAttachNamedExport(key, value, defaultFunc, originalDefault) {
|
|
439
|
-
if (!key || key === "default") {
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
if (value === defaultFunc || value === originalDefault) {
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
if (typeof defaultFunc === "function" && key === defaultFunc.name) {
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
if (typeof originalDefault === "function" && key === originalDefault.name) {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
return true;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
17
|
+
import{ComponentBase}from"@cldmv/slothlet/factories/component-base";class Flatten extends ComponentBase{static slothletProperty="flatten";constructor(slothlet){super(slothlet)}#checkSelfReferential(mod,moduleName){if(!mod||typeof mod!=="object")return false;return mod[moduleName]===mod}async#checkMultiDefault(analysis,hasMultipleDefaults,t){if(!hasMultipleDefaults)return null;if(analysis.hasDefault){return{preserveAsNamespace:true,reason:await t("FLATTEN_REASON_MULTI_DEFAULT_WITH_DEFAULT")}}return{flattenToRoot:true,reason:await t("FLATTEN_REASON_MULTI_DEFAULT_WITHOUT_DEFAULT")}}#checkAutoFlatten(mod,moduleName,moduleKeys){if(moduleKeys.length!==1)return false;return moduleKeys[0]===moduleName}async getFlatteningDecision(options){const{mod,moduleName,categoryName,analysis,hasMultipleDefaults,moduleKeys,t}=options;const isAddapiFile=moduleName==="addapi";if(isAddapiFile){if(analysis.hasDefault&&analysis.defaultExportType==="object"&&moduleKeys.length>0){return{flattenToCategory:true,flattenType:"addapi-metadata-default",reason:await t("FLATTEN_REASON_ADDAPI_METADATA_DEFAULT")}}return{flattenToCategory:true,flattenType:"addapi-special-file",reason:await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE")}}if(this.#checkSelfReferential(mod,moduleName)){return{preserveAsNamespace:true,reason:await t("FLATTEN_REASON_SELF_REFERENTIAL")}}const multiDefaultDecision=await this.#checkMultiDefault(analysis,hasMultipleDefaults,t);if(multiDefaultDecision){if(multiDefaultDecision.preserveAsNamespace){const exportToCheck2=typeof mod==="function"?mod:mod?.default&&typeof mod.default==="function"?mod.default:null;if(exportToCheck2&&exportToCheck2.name&&exportToCheck2.name!=="default"){const normalizedFunctionName=exportToCheck2.name.toLowerCase().replace(/[-_]/g,"");const normalizedModuleName=moduleName.toLowerCase().replace(/[-_]/g,"");if(normalizedFunctionName===normalizedModuleName){multiDefaultDecision.preferredName=exportToCheck2.name}}}return multiDefaultDecision}if(this.#checkAutoFlatten(mod,moduleName,moduleKeys)){return{useAutoFlattening:true,reason:await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_FILENAME")}}if(moduleName===categoryName){return{flattenToCategory:true,reason:await t("FLATTEN_REASON_FILENAME_MATCHES_CATEGORY")}}const exportToCheck=typeof mod==="function"?mod:mod?.default&&typeof mod.default==="function"?mod.default:null;if(exportToCheck&&exportToCheck.name&&exportToCheck.name!=="default"){const normalizedFunctionName=exportToCheck.name.toLowerCase().replace(/[-_]/g,"");const normalizedModuleName=moduleName.toLowerCase().replace(/[-_]/g,"");const functionNameMatchesFilename=normalizedFunctionName===normalizedModuleName;if(functionNameMatchesFilename){return{preserveAsNamespace:true,preferredName:exportToCheck.name,reason:await t("FLATTEN_REASON_PRESERVING_FUNCTION_NAME")}}}return{preserveAsNamespace:true,reason:await t("FLATTEN_REASON_DEFAULT_PRESERVE_NAMESPACE")}}processModuleForAPI(options){const{mod,decision,moduleName,propertyName,moduleKeys,analysis,file=null,collisionContext="initial",apiPathPrefix="",isSelfReferential=false}=options;const isAddapiFile=moduleName==="addapi"||file&&file.name==="addapi"||file&&file.fullName&&["addapi.mjs","addapi.cjs","addapi.js","addapi.ts"].includes(file.fullName.toLowerCase());if(isAddapiFile&&analysis.hasDefault&&moduleKeys.length>0){const moduleContent2=mod.default;for(const key of moduleKeys){moduleContent2[key]=mod[key]}return{moduleContent:moduleContent2}}if(decision.useAutoFlattening){return{moduleContent:mod[moduleName]}}if(decision.flattenToRoot||decision.flattenToCategory){if(mod.default&&moduleKeys.length===0){return{moduleContent:mod.default}}if(mod.default&&moduleKeys.length>0){const moduleContent3=typeof mod.default==="function"?mod.default:{...mod.default};for(const key of moduleKeys){moduleContent3[key]=mod[key]}return{moduleContent:moduleContent3}}const moduleContent2={};for(const key of moduleKeys){moduleContent2[key]=mod[key]}return{moduleContent:moduleContent2}}if(isSelfReferential){return{moduleContent:mod[moduleName]||mod}}if(mod.default&&moduleKeys.length>0){if(typeof mod.default==="function"){const moduleContent3=this.slothlet.helpers.modesUtils.ensureNamedExportFunction(mod.default,propertyName);const collisionConfig=this.slothlet.config.api?.collision||this.slothlet.config.collision;const collisionMode=collisionContext==="initial"?collisionConfig.initial:collisionConfig.api;for(const key of moduleKeys){if(!this.shouldAttachNamedExport(key,mod[key],moduleContent3,mod.default)){continue}const hasExisting=Object.prototype.hasOwnProperty.call(moduleContent3,key);if(hasExisting){if(collisionMode==="merge"||collisionMode==="skip"){continue}else if(collisionMode==="error"){throw new this.slothlet.SlothletError("COLLISION_DEFAULT_EXPORT_ERROR",{key,apiPath:`${apiPathPrefix}.${propertyName}`},null,{validationError:true})}else if(collisionMode==="warn"){new this.slothlet.SlothletWarning("WARNING_COLLISION_DEFAULT_EXPORT_OVERWRITE",{key,apiPath:`${apiPathPrefix}.${propertyName}`})}}moduleContent3[key]=mod[key]}return{moduleContent:moduleContent3}}if(typeof mod.default==="object"&&mod.default!==null){const moduleContent3=mod.default;for(const key of moduleKeys){if(key in mod.default){continue}if(!this.shouldAttachNamedExport(key,mod[key],moduleContent3,mod.default)){continue}moduleContent3[key]=mod[key]}return{moduleContent:moduleContent3}}const moduleContent2={default:mod.default};for(const key of moduleKeys){moduleContent2[key]=mod[key]}return{moduleContent:moduleContent2}}if(mod.default&&moduleKeys.length===0){return{moduleContent:this.slothlet.helpers.modesUtils.ensureNamedExportFunction(mod.default,propertyName)}}const moduleContent={};for(const key of moduleKeys){moduleContent[key]=mod[key]}return{moduleContent}}async buildCategoryDecisions(options){const{categoryName,mod,moduleName,fileBaseName,analysis,moduleKeys,currentDepth,moduleFiles=[],t}=options;const decision={shouldFlatten:false,flattenType:"preserve",preferredName:null,reason:await t("FLATTEN_REASON_NO_CONDITIONS_MET")};const isAddapiFile=moduleName==="addapi"||fileBaseName==="addapi"||fileBaseName&&["addapi.mjs","addapi.cjs","addapi.js","addapi.ts"].includes(fileBaseName.toLowerCase());if(isAddapiFile){if(analysis.hasDefault&&analysis.defaultExportType==="object"&&moduleKeys.length>0){return{shouldFlatten:true,flattenType:"addapi-metadata-default",reason:await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE_PARENT")}}return{shouldFlatten:true,flattenType:"addapi-special-file",reason:await t("FLATTEN_REASON_ADDAPI_SPECIAL_FILE")}}if(moduleName===categoryName&&typeof mod==="function"&¤tDepth>0){return{shouldFlatten:true,flattenType:"function-folder-match",reason:await t("FLATTEN_REASON_FUNCTION_FOLDER_MATCH")}}if(analysis.hasDefault&&analysis.defaultExportType==="object"&&moduleName===categoryName&¤tDepth>0){return{shouldFlatten:true,flattenType:"default-export-flatten",reason:await t("FLATTEN_REASON_DEFAULT_OBJECT_EXPORT_FLATTEN")}}if(moduleName===categoryName&&mod&&typeof mod==="object"&&!Array.isArray(mod)&¤tDepth>0){if(moduleKeys.length===1&&moduleKeys[0]===moduleName){return{shouldFlatten:true,flattenType:"object-auto-flatten",reason:await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_FILENAME")}}}if(fileBaseName===categoryName&&moduleKeys.length>0){return{shouldFlatten:true,flattenType:"filename-folder-match-flatten",reason:await t("FLATTEN_REASON_BASENAME_MATCHES_CATEGORY")}}if(moduleFiles.length===1&¤tDepth>0&&mod&&typeof mod==="object"&&!Array.isArray(mod)){const genericFilenames=["singlefile","index","main","default"];const isGenericFilename=genericFilenames.includes(moduleName.toLowerCase());if(moduleKeys.length===1&&isGenericFilename){return{shouldFlatten:true,flattenType:"parent-level-flatten",reason:await t("FLATTEN_REASON_GENERIC_FILENAME_SINGLE_EXPORT")}}}if(typeof mod==="function"&&mod.name&¤tDepth>0){const functionNameMatchesFolder=mod.name.toLowerCase()===categoryName.toLowerCase()||mod.name.toLowerCase().replace(/[-_]/g,"")===categoryName.toLowerCase().replace(/[-_]/g,"");if(functionNameMatchesFolder){return{shouldFlatten:true,flattenType:"function-folder-match",preferredName:mod.name,reason:await t("FLATTEN_REASON_FUNCTION_FOLDER_MATCH")}}}const exportToCheck=typeof mod==="function"?mod:mod?.default&&typeof mod.default==="function"?mod.default:null;if(exportToCheck&&exportToCheck.name&&exportToCheck.name!=="default"){const normalizedFunctionName=exportToCheck.name.toLowerCase().replace(/[-_]/g,"");const normalizedModuleName=moduleName.toLowerCase().replace(/[-_]/g,"");const functionNameMatchesFilename=normalizedFunctionName===normalizedModuleName;if(functionNameMatchesFilename){return{shouldFlatten:false,preferredName:exportToCheck.name,reason:await t("FLATTEN_REASON_PRESERVING_FUNCTION_NAME")}}}if(typeof mod==="function"&&(!mod.name||mod.name==="default"||mod.__slothletDefault===true)&¤tDepth>0){return{shouldFlatten:true,flattenType:"default-function",preferredName:categoryName,reason:await t("FLATTEN_REASON_DEFAULT_FUNCTION_EXPORT")}}if(moduleKeys.length===1&&moduleKeys[0]===moduleName){return{shouldFlatten:true,flattenType:"object-auto-flatten",preferredName:moduleName,reason:await t("FLATTEN_REASON_SINGLE_EXPORT_MATCHES_MODULE")}}return decision}shouldAttachNamedExport(key,value,defaultFunc,originalDefault){if(!key||key==="default"){return false}if(value===defaultFunc||value===originalDefault){return false}if(typeof defaultFunc==="function"&&key===defaultFunc.name){return false}if(typeof originalDefault==="function"&&key===originalDefault.name){return false}return true}}export{Flatten};
|