@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.
- package/AGENT-USAGE.md +355 -325
- package/README.md +554 -238
- package/dist/lib/builders/api-assignment.mjs +605 -0
- package/dist/lib/builders/api_builder.mjs +1073 -0
- package/dist/lib/builders/builder.mjs +94 -0
- package/dist/lib/builders/modes-processor.mjs +1816 -0
- package/dist/lib/errors.mjs +227 -0
- package/dist/lib/factories/component-base.mjs +96 -0
- package/dist/lib/factories/context.mjs +38 -0
- package/dist/lib/handlers/api-cache-manager.mjs +216 -0
- package/dist/lib/handlers/api-manager.mjs +2364 -0
- package/dist/lib/handlers/context-async.mjs +184 -0
- package/dist/lib/handlers/context-live.mjs +184 -0
- package/dist/lib/handlers/hook-manager.mjs +789 -0
- package/dist/lib/handlers/lifecycle-token.mjs +44 -0
- package/dist/lib/handlers/lifecycle.mjs +131 -0
- package/dist/lib/handlers/materialize-manager.mjs +64 -0
- package/dist/lib/handlers/metadata.mjs +500 -0
- package/dist/lib/handlers/ownership.mjs +338 -0
- package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
- package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
- package/dist/lib/helpers/config.mjs +343 -0
- package/dist/lib/helpers/eventemitter-context.mjs +365 -0
- package/dist/lib/helpers/hint-detector.mjs +63 -0
- package/dist/lib/helpers/modes-utils.mjs +53 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +123 -117
- package/dist/lib/helpers/sanitize.mjs +247 -168
- package/dist/lib/helpers/utilities.mjs +46 -81
- package/dist/lib/i18n/languages/de-de.json +377 -0
- package/dist/lib/i18n/languages/en-gb.json +377 -0
- package/dist/lib/i18n/languages/en-us.json +377 -0
- package/dist/lib/i18n/languages/es-mx.json +377 -0
- package/dist/lib/i18n/languages/fr-fr.json +377 -0
- package/dist/lib/i18n/languages/hi-in.json +377 -0
- package/dist/lib/i18n/languages/ja-jp.json +377 -0
- package/dist/lib/i18n/languages/ko-kr.json +377 -0
- package/dist/lib/i18n/languages/pt-br.json +377 -0
- package/dist/lib/i18n/languages/ru-ru.json +377 -0
- package/dist/lib/i18n/languages/zh-cn.json +377 -0
- package/dist/lib/i18n/translations.mjs +140 -0
- package/dist/lib/modes/eager.mjs +75 -0
- package/dist/lib/modes/lazy.mjs +97 -0
- package/dist/lib/processors/flatten.mjs +453 -0
- package/dist/lib/processors/loader.mjs +355 -0
- package/dist/lib/processors/type-generator.mjs +291 -0
- package/dist/lib/processors/typescript.mjs +188 -0
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
- package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
- package/dist/lib/runtime/runtime.mjs +39 -159
- package/dist/slothlet.mjs +525 -744
- package/docs/API-RULES.md +338 -486
- package/index.cjs +4 -4
- package/index.mjs +82 -45
- package/package.json +143 -30
- package/types/dist/lib/builders/api-assignment.d.mts +97 -0
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
- package/types/dist/lib/builders/api_builder.d.mts +96 -0
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
- package/types/dist/lib/builders/builder.d.mts +60 -0
- package/types/dist/lib/builders/builder.d.mts.map +1 -0
- package/types/dist/lib/builders/modes-processor.d.mts +32 -0
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
- package/types/dist/lib/errors.d.mts +118 -0
- package/types/dist/lib/errors.d.mts.map +1 -0
- package/types/dist/lib/factories/component-base.d.mts +182 -0
- package/types/dist/lib/factories/component-base.d.mts.map +1 -0
- package/types/dist/lib/factories/context.d.mts +26 -0
- package/types/dist/lib/factories/context.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-manager.d.mts +392 -0
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-async.d.mts +66 -0
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-live.d.mts +65 -0
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
- package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/metadata.d.mts +215 -0
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
- package/types/dist/lib/handlers/ownership.d.mts +170 -0
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/config.d.mts +96 -0
- package/types/dist/lib/helpers/config.d.mts.map +1 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
- package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
- package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +95 -94
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +53 -116
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +39 -0
- package/types/dist/lib/i18n/translations.d.mts.map +1 -0
- package/types/dist/lib/modes/eager.d.mts +36 -0
- package/types/dist/lib/modes/eager.d.mts.map +1 -0
- package/types/dist/lib/modes/lazy.d.mts +49 -0
- package/types/dist/lib/modes/lazy.d.mts.map +1 -0
- package/types/dist/lib/processors/flatten.d.mts +114 -0
- package/types/dist/lib/processors/flatten.d.mts.map +1 -0
- package/types/dist/lib/processors/loader.d.mts +47 -0
- package/types/dist/lib/processors/loader.d.mts.map +1 -0
- package/types/dist/lib/processors/type-generator.d.mts +19 -0
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
- package/types/dist/lib/processors/typescript.d.mts +55 -0
- package/types/dist/lib/processors/typescript.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +39 -9
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +184 -111
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +1 -3
- package/dist/lib/engine/README.md +0 -21
- package/dist/lib/engine/slothlet_child.mjs +0 -59
- package/dist/lib/engine/slothlet_engine.mjs +0 -372
- package/dist/lib/engine/slothlet_esm.mjs +0 -230
- package/dist/lib/engine/slothlet_helpers.mjs +0 -455
- package/dist/lib/engine/slothlet_worker.mjs +0 -149
- package/dist/lib/helpers/als-eventemitter.mjs +0 -256
- package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
- package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
- package/dist/lib/helpers/api_builder/construction.mjs +0 -495
- package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
- package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
- package/dist/lib/helpers/api_builder.mjs +0 -41
- package/dist/lib/helpers/auto-wrap.mjs +0 -62
- package/dist/lib/helpers/hooks.mjs +0 -389
- package/dist/lib/helpers/instance-manager.mjs +0 -111
- package/dist/lib/helpers/metadata-api.mjs +0 -201
- package/dist/lib/helpers/multidefault.mjs +0 -216
- package/dist/lib/modes/slothlet_eager.mjs +0 -154
- package/dist/lib/modes/slothlet_lazy.mjs +0 -594
- package/docs/API-RULES-CONDITIONS.md +0 -712
- package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
- package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
- package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
- package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
- package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
- package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
- package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
- package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
- package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder.d.mts +0 -6
- package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
- package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
- package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
- package/types/dist/lib/helpers/hooks.d.mts +0 -342
- package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
- package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
- package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
- package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
- package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
- package/types/dist/lib/helpers/multidefault.d.mts +0 -90
- package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
- package/types/index.d.mts.map +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
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 { EventEmitter } from "node:events";
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const EXCLUDED_CONSTRUCTORS = new Set([Object, Array, Promise, Date, RegExp, Error]);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const EXCLUDED_INSTANCEOF_CLASSES = [ArrayBuffer, Map, Set, WeakMap, WeakSet, EventEmitter];
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export function runtime_shouldWrapMethod(value, prop) {
|
|
31
|
+
return (
|
|
32
|
+
typeof value === "function" &&
|
|
33
|
+
typeof prop === "string" &&
|
|
34
|
+
prop !== "constructor" &&
|
|
35
|
+
!(prop in Object.prototype) &&
|
|
36
|
+
!prop.startsWith("__")
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export function runtime_isClassInstance(val) {
|
|
42
|
+
if (
|
|
43
|
+
val == null ||
|
|
44
|
+
typeof val !== "object" ||
|
|
45
|
+
!val.constructor ||
|
|
46
|
+
typeof val.constructor !== "function" ||
|
|
47
|
+
EXCLUDED_CONSTRUCTORS.has(val.constructor)
|
|
48
|
+
) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const cls of EXCLUDED_INSTANCEOF_CLASSES) {
|
|
53
|
+
if (typeof cls === "function" && val instanceof cls) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export function runtime_wrapClassInstance(instance, contextManager, instanceID, instanceCache) {
|
|
63
|
+
if (instanceCache.has(instance)) {
|
|
64
|
+
return instanceCache.get(instance);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const methodCache = new Map();
|
|
75
|
+
|
|
76
|
+
const wrappedInstance = new Proxy(instance, {
|
|
77
|
+
get(target, prop, receiver) {
|
|
78
|
+
|
|
79
|
+
if (methodCache.has(prop)) {
|
|
80
|
+
return methodCache.get(prop);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const value = Reflect.get(target, prop, receiver);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if (runtime_shouldWrapMethod(value, prop)) {
|
|
88
|
+
const runtime_contextPreservingMethod = function (...args) {
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const result = contextManager.runInContext(instanceID, value, target, args);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if (result != null && runtime_isClassInstance(result)) {
|
|
95
|
+
return runtime_wrapClassInstance(result, contextManager, instanceID, instanceCache);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return result;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
methodCache.set(prop, runtime_contextPreservingMethod);
|
|
103
|
+
return runtime_contextPreservingMethod;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if (value != null && runtime_isClassInstance(value)) {
|
|
108
|
+
return runtime_wrapClassInstance(value, contextManager, instanceID, instanceCache);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return value;
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
set(target, prop, value, receiver) {
|
|
115
|
+
|
|
116
|
+
if (methodCache.has(prop)) {
|
|
117
|
+
methodCache.delete(prop);
|
|
118
|
+
}
|
|
119
|
+
return Reflect.set(target, prop, value, receiver);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
instanceCache.set(instance, wrappedInstance);
|
|
124
|
+
return wrappedInstance;
|
|
125
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
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
|
+
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export class Config extends ComponentBase {
|
|
24
|
+
static slothletProperty = "config";
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
normalizeCollision(collision) {
|
|
28
|
+
const validModes = ["skip", "warn", "replace", "merge", "merge-replace", "error"];
|
|
29
|
+
const defaultMode = "merge";
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if (typeof collision === "string") {
|
|
33
|
+
const normalized = collision.toLowerCase();
|
|
34
|
+
const mode = validModes.includes(normalized) ? normalized : defaultMode;
|
|
35
|
+
return { initial: mode, api: mode };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if (collision && typeof collision === "object") {
|
|
40
|
+
const validateMode = (m) => {
|
|
41
|
+
if (!m) return defaultMode;
|
|
42
|
+
const normalized = String(m).toLowerCase();
|
|
43
|
+
return validModes.includes(normalized) ? normalized : defaultMode;
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
initial: validateMode(collision.initial),
|
|
47
|
+
api: validateMode(collision.api)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
return { initial: defaultMode, api: defaultMode };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
normalizeRuntime(runtime) {
|
|
57
|
+
if (!runtime || typeof runtime !== "string") {
|
|
58
|
+
return "async";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const normalized = runtime.toLowerCase().trim();
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (normalized === "async" || normalized === "asynclocal" || normalized === "asynclocalstorage") {
|
|
65
|
+
return "async";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if (normalized === "live" || normalized === "livebindings" || normalized === "experimental") {
|
|
70
|
+
return "live";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
return "async";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
normalizeMode(mode) {
|
|
79
|
+
if (!mode || typeof mode !== "string") {
|
|
80
|
+
return "eager";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const normalized = mode.toLowerCase().trim();
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (normalized === "lazy" || normalized === "deferred" || normalized === "proxy") {
|
|
87
|
+
return "lazy";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (normalized === "eager" || normalized === "immediate" || normalized === "preload") {
|
|
92
|
+
return "eager";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
return "eager";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
normalizeMutations(mutations) {
|
|
101
|
+
const defaults = { add: true, remove: true, reload: true };
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (!mutations || typeof mutations !== "object") {
|
|
105
|
+
return defaults;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
add: mutations.add === false ? false : true,
|
|
111
|
+
remove: mutations.remove === false ? false : true,
|
|
112
|
+
reload: mutations.reload === false ? false : true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
normalizeDebug(debug) {
|
|
118
|
+
if (!debug) {
|
|
119
|
+
return {
|
|
120
|
+
builder: false,
|
|
121
|
+
api: false,
|
|
122
|
+
index: false,
|
|
123
|
+
modes: false,
|
|
124
|
+
wrapper: false,
|
|
125
|
+
ownership: false,
|
|
126
|
+
context: false,
|
|
127
|
+
initialization: false,
|
|
128
|
+
materialize: false
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if (debug === true) {
|
|
134
|
+
return {
|
|
135
|
+
builder: true,
|
|
136
|
+
api: true,
|
|
137
|
+
index: true,
|
|
138
|
+
modes: true,
|
|
139
|
+
wrapper: true,
|
|
140
|
+
ownership: true,
|
|
141
|
+
context: true,
|
|
142
|
+
initialization: true,
|
|
143
|
+
materialize: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if (typeof debug === "object") {
|
|
149
|
+
return {
|
|
150
|
+
builder: debug.builder || false,
|
|
151
|
+
api: debug.api || false,
|
|
152
|
+
index: debug.index || false,
|
|
153
|
+
modes: debug.modes || false,
|
|
154
|
+
wrapper: debug.wrapper || false,
|
|
155
|
+
ownership: debug.ownership || false,
|
|
156
|
+
context: debug.context || false,
|
|
157
|
+
initialization: debug.initialization || false,
|
|
158
|
+
materialize: debug.materialize || false
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
builder: false,
|
|
165
|
+
api: false,
|
|
166
|
+
index: false,
|
|
167
|
+
modes: false,
|
|
168
|
+
wrapper: false,
|
|
169
|
+
ownership: false,
|
|
170
|
+
context: false,
|
|
171
|
+
initialization: false,
|
|
172
|
+
materialize: false
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
transformConfig(config = {}) {
|
|
178
|
+
|
|
179
|
+
if (!config.dir) {
|
|
180
|
+
throw new this.SlothletError("INVALID_CONFIG_DIR_MISSING", {}, null, { validationError: true });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const resolvedDir = this.slothlet.helpers.resolver.resolvePathFromCaller(config.dir);
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
let mutations = null;
|
|
189
|
+
if (config.allowMutation === false) {
|
|
190
|
+
|
|
191
|
+
mutations = { add: false, remove: false, reload: false };
|
|
192
|
+
if (!config.silent) {
|
|
193
|
+
new this.SlothletWarning("V2_CONFIG_UNSUPPORTED", {
|
|
194
|
+
option: "allowMutation",
|
|
195
|
+
replacement: "api.mutations: { add: false, remove: false, reload: false }",
|
|
196
|
+
hint: "The allowMutation config option was part of v2. Use api.mutations for granular control in v3."
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
let collision = null;
|
|
204
|
+
if (config.collision && !config.api?.collision) {
|
|
205
|
+
collision = this.normalizeCollision(config.collision);
|
|
206
|
+
if (!config.silent) {
|
|
207
|
+
new this.SlothletWarning("V2_CONFIG_UNSUPPORTED", {
|
|
208
|
+
option: "collision",
|
|
209
|
+
replacement: "api.collision",
|
|
210
|
+
hint: "Root-level collision config was part of v2. Use api.collision in v3."
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
const apiConfig = config.api || {};
|
|
217
|
+
const finalCollision = apiConfig.collision ? this.normalizeCollision(apiConfig.collision) : collision || this.normalizeCollision(null);
|
|
218
|
+
const finalMutations = apiConfig.mutations ? this.normalizeMutations(apiConfig.mutations) : mutations || this.normalizeMutations(null);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
let scopeConfig = config.scope;
|
|
222
|
+
if (scopeConfig && typeof scopeConfig === "object" && scopeConfig.merge) {
|
|
223
|
+
const validMergeStrategies = ["shallow", "deep"];
|
|
224
|
+
if (!validMergeStrategies.includes(scopeConfig.merge)) {
|
|
225
|
+
throw new this.SlothletError(
|
|
226
|
+
"INVALID_CONFIG",
|
|
227
|
+
{
|
|
228
|
+
option: "scope.merge",
|
|
229
|
+
value: scopeConfig.merge,
|
|
230
|
+
expected: validMergeStrategies.join(" or "),
|
|
231
|
+
hint: `Invalid merge strategy: "${scopeConfig.merge}". Must be "shallow" or "deep".`,
|
|
232
|
+
validationError: true
|
|
233
|
+
},
|
|
234
|
+
null,
|
|
235
|
+
{ validationError: true }
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
let hookConfig = { enabled: false, pattern: "**", suppressErrors: false };
|
|
242
|
+
if (config.hook === true || config.hook === false) {
|
|
243
|
+
|
|
244
|
+
hookConfig.enabled = config.hook;
|
|
245
|
+
hookConfig.pattern = config.hook ? "**" : null;
|
|
246
|
+
} else if (typeof config.hook === "string") {
|
|
247
|
+
|
|
248
|
+
hookConfig.enabled = true;
|
|
249
|
+
hookConfig.pattern = config.hook;
|
|
250
|
+
} else if (config.hook && typeof config.hook === "object") {
|
|
251
|
+
|
|
252
|
+
hookConfig.enabled = config.hook.enabled !== false;
|
|
253
|
+
hookConfig.pattern = config.hook.pattern || "**";
|
|
254
|
+
hookConfig.suppressErrors = config.hook.suppressErrors || false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
let trackingConfig = { materialization: false };
|
|
259
|
+
if (config.tracking === true || config.tracking === false) {
|
|
260
|
+
|
|
261
|
+
trackingConfig.materialization = config.tracking;
|
|
262
|
+
} else if (config.tracking && typeof config.tracking === "object") {
|
|
263
|
+
|
|
264
|
+
trackingConfig.materialization = config.tracking.materialization === true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
if (config.backgroundMaterialize === true) {
|
|
269
|
+
trackingConfig.materialization = true;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
let i18nConfig = null;
|
|
274
|
+
if (config.i18n && typeof config.i18n === "object") {
|
|
275
|
+
i18nConfig = {
|
|
276
|
+
language: typeof config.i18n.language === "string" ? config.i18n.language : undefined
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
...config,
|
|
283
|
+
dir: resolvedDir,
|
|
284
|
+
mode: this.normalizeMode(config.mode),
|
|
285
|
+
runtime: this.normalizeRuntime(config.runtime),
|
|
286
|
+
apiDepth: config.apiDepth !== undefined ? config.apiDepth : Infinity,
|
|
287
|
+
reference: config.reference || null,
|
|
288
|
+
context: config.context || null,
|
|
289
|
+
i18n: i18nConfig,
|
|
290
|
+
debug: this.normalizeDebug(config.debug),
|
|
291
|
+
diagnostics: config.diagnostics === true,
|
|
292
|
+
hook: hookConfig,
|
|
293
|
+
collision: finalCollision,
|
|
294
|
+
api: {
|
|
295
|
+
collision: finalCollision,
|
|
296
|
+
mutations: finalMutations
|
|
297
|
+
},
|
|
298
|
+
scope: scopeConfig,
|
|
299
|
+
tracking: trackingConfig,
|
|
300
|
+
backgroundMaterialize: config.backgroundMaterialize === true,
|
|
301
|
+
silent: config.silent === true,
|
|
302
|
+
typescript: this.normalizeTypeScript(config.typescript)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
normalizeTypeScript(typescript) {
|
|
308
|
+
|
|
309
|
+
if (!typescript) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
if (typescript === true) {
|
|
315
|
+
return { enabled: true, mode: "fast" };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
if (typeof typescript === "string") {
|
|
320
|
+
const mode = typescript.toLowerCase();
|
|
321
|
+
if (mode === "fast" || mode === "strict") {
|
|
322
|
+
return { enabled: true, mode };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return { enabled: true, mode: "fast" };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
if (typeof typescript === "object") {
|
|
330
|
+
const mode = typescript.mode === "strict" ? "strict" : "fast";
|
|
331
|
+
return {
|
|
332
|
+
enabled: true,
|
|
333
|
+
mode,
|
|
334
|
+
types: typescript.types || null,
|
|
335
|
+
target: typescript.target || "es2020",
|
|
336
|
+
sourcemap: typescript.sourcemap || false
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
}
|