@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
@@ -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
+ }