@cldmv/slothlet 2.10.0 → 3.0.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.
Files changed (188) hide show
  1. package/AGENT-USAGE.md +365 -294
  2. package/README.md +556 -233
  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 +125 -85
  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 +529 -700
  51. package/docs/API-RULES.md +497 -617
  52. package/index.cjs +4 -4
  53. package/index.mjs +82 -45
  54. package/package.json +139 -26
  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 +186 -105
  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 -292
  138. package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
  139. package/dist/lib/helpers/api_builder/construction.mjs +0 -457
  140. package/dist/lib/helpers/api_builder/decisions.mjs +0 -737
  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 -126
  149. package/dist/lib/modes/slothlet_lazy.mjs +0 -513
  150. package/docs/API-RULES-CONDITIONS.md +0 -508
  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 -76
  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
@@ -0,0 +1,3031 @@
1
+ /*
2
+ Copyright 2026 CLDMV/Shinrai
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+
21
+
22
+ const ____COLLISION_MERGED_PROPERTY = Symbol("collisionMergedProperty");
23
+ import util from "node:util";
24
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
25
+
26
+
27
+ const ERROR_HOOK_PROCESSED = Symbol.for("@cldmv/slothlet/hook-error-processed");
28
+
29
+
30
+ const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
31
+
32
+
33
+ function unwrapError(error) {
34
+
35
+ if (error && error.name === "SlothletError" && error.originalError) {
36
+ return error.originalError;
37
+ }
38
+ return error;
39
+ }
40
+
41
+ const wrapperDebugEnabled =
42
+ process.env.SLOTHLET_DEBUG_WRAPPER === "1" ||
43
+ process.env.SLOTHLET_DEBUG_WRAPPER === "true" ||
44
+ process.env.SLOTHLET_DEBUG_SCRIPT_VERBOSE === "1" ||
45
+ process.env.SLOTHLET_DEBUG_SCRIPT_VERBOSE === "true";
46
+
47
+
48
+ export const TYPE_STATES = {
49
+ UNMATERIALIZED: Symbol("unmaterialized"),
50
+ IN_FLIGHT: Symbol("inFlight")
51
+ };
52
+
53
+
54
+ function getSafeFunctionName(apiPath, fallback) {
55
+ const parts = String(apiPath || "")
56
+ .split(".")
57
+ .filter((part) => part && part !== "null");
58
+ const baseName = parts.length > 0 ? parts[parts.length - 1] : "";
59
+ let safeName = String(baseName || "").replace(/[^A-Za-z0-9_$]/g, "_");
60
+ if (!safeName || !/^[A-Za-z_$]/.test(safeName[0])) {
61
+ safeName = safeName ? `_${safeName}` : "";
62
+ }
63
+ return safeName || fallback;
64
+ }
65
+
66
+
67
+ function createNamedProxyTarget(nameHint, fallback) {
68
+ const safeName = getSafeFunctionName(nameHint, fallback);
69
+ return { [safeName]: function () {} }[safeName];
70
+ }
71
+
72
+
73
+ const _proxyRegistry = new WeakMap();
74
+
75
+
76
+ export class UnifiedWrapper extends ComponentBase {
77
+
78
+ #internal = null;
79
+
80
+
81
+ get ____slothletInternal() {
82
+ if (!(#internal in this)) return undefined;
83
+ return this.#internal;
84
+ }
85
+
86
+
87
+ constructor(
88
+ slothlet,
89
+ {
90
+ mode,
91
+ apiPath,
92
+ initialImpl = null,
93
+ materializeFunc = null,
94
+ isCallable,
95
+ materializeOnCreate = false,
96
+ filePath = null,
97
+ moduleID = null,
98
+ sourceFolder = null
99
+ }
100
+ ) {
101
+ super(slothlet);
102
+
103
+
104
+
105
+
106
+ const isCallableExplicit = typeof isCallable === "boolean";
107
+ const isCallableValue = isCallableExplicit
108
+ ? isCallable
109
+ : typeof initialImpl === "function" || (initialImpl && typeof initialImpl.default === "function");
110
+
111
+
112
+
113
+ const isCallableLocked = isCallableValue || isCallableExplicit;
114
+
115
+ const internal = Object.create(null);
116
+ internal.id = Math.random().toString(36).substr(2, 9);
117
+ internal.mode = mode;
118
+ internal.apiPath = apiPath;
119
+ internal.materializeOnCreate = materializeOnCreate;
120
+ internal.isCallable = isCallableValue;
121
+ internal.isCallableLocked = isCallableLocked;
122
+ internal.moduleID = moduleID;
123
+ internal.filePath = filePath;
124
+ internal.sourceFolder = sourceFolder;
125
+ internal.invalid = false;
126
+ internal.state = {
127
+ materialized: initialImpl !== null,
128
+ inFlight: false,
129
+ collisionMode: "merge"
130
+ };
131
+ internal.displayName = apiPath ? `${String(apiPath).replace(/\./g, "__")}__UnifiedWrapper` : "UnifiedWrapper";
132
+
133
+
134
+
135
+
136
+
137
+
138
+ this.#internal = internal;
139
+
140
+
141
+ const wrapper = this;
142
+ Object.defineProperty(internal, "wrapper", {
143
+
144
+
145
+ get() {
146
+ return wrapper;
147
+ },
148
+
149
+ enumerable: false,
150
+ configurable: false
151
+ });
152
+
153
+
154
+
155
+ internal.callableImpl = null;
156
+
157
+ internal.waitingProxyCache = new Map();
158
+ internal.proxy = null;
159
+
160
+
161
+
162
+ internal.impl = UnifiedWrapper._cloneImpl(initialImpl);
163
+
164
+ internal.materializeFunc = materializeFunc;
165
+
166
+
167
+ if (filePath && slothlet.handlers?.lifecycle) {
168
+ slothlet.handlers.lifecycle.emit("impl:created", {
169
+ apiPath,
170
+ impl: this,
171
+
172
+
173
+
174
+
175
+ wrapper: Object.freeze({ __impl: this.____slothletInternal.impl }),
176
+ source: "initial",
177
+ moduleID,
178
+ filePath,
179
+
180
+
181
+ sourceFolder: sourceFolder || slothlet.config?.dir
182
+ });
183
+ }
184
+
185
+
186
+ if (initialImpl !== null && filePath && slothlet.handlers?.lifecycle) {
187
+ slothlet.handlers.lifecycle.emit("impl:created", {
188
+ apiPath,
189
+ impl: initialImpl,
190
+ wrapper: Object.freeze({ __impl: this.____slothletInternal.impl }),
191
+ source: "initial",
192
+ moduleID,
193
+ filePath,
194
+
195
+
196
+ sourceFolder: sourceFolder || slothlet.config?.dir
197
+ });
198
+ }
199
+
200
+ if (initialImpl !== null) {
201
+ const implKeys = Object.keys(initialImpl || {});
202
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && apiPath && (apiPath === "config" || apiPath.startsWith("config."))) {
203
+ this.slothlet.debug("wrapper", {
204
+ key: "DEBUG_MODE_WRAPPER_CONSTRUCTOR_IMPL_KEYS",
205
+ apiPath,
206
+ keyCount: implKeys.length,
207
+ keySample: implKeys.slice(0, 5)
208
+ });
209
+ }
210
+ this.___adoptImplChildren();
211
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && apiPath && (apiPath === "config" || apiPath.startsWith("config."))) {
212
+ const childKeys = Object.keys(this).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
213
+ this.slothlet.debug("wrapper", {
214
+ key: "DEBUG_MODE_WRAPPER_CONSTRUCTOR_AFTER_ADOPT",
215
+ apiPath,
216
+ childCount: childKeys.length,
217
+ childKeySample: childKeys.slice(0, 5)
218
+ });
219
+ }
220
+ }
221
+
222
+
223
+ if (mode === "lazy") {
224
+ slothlet._registerLazyWrapper();
225
+
226
+
227
+ if (slothlet.config.tracking?.materialization) {
228
+
229
+
230
+ setImmediate(() => {
231
+ this._materialize().catch((err) => {
232
+
233
+
234
+
235
+
236
+ if (slothlet.config?.debug?.materialize) {
237
+ slothlet.debug("materialize", {
238
+ key: "DEBUG_MODE_BACKGROUND_MATERIALIZE_ERROR",
239
+ apiPath: this.____slothletInternal?.apiPath,
240
+ error: err.message
241
+ });
242
+ }
243
+ });
244
+ });
245
+ }
246
+ }
247
+ }
248
+
249
+
250
+ [util.inspect.custom](____depth, ____options, ____inspect) {
251
+
252
+
253
+
254
+
255
+ const w = _proxyRegistry.get(this) ?? this;
256
+
257
+ const childKeys = Object.keys(w).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
258
+ if (childKeys.length > 0 && !w.____slothletInternal?.isCallable) {
259
+ const inspectObj = {};
260
+ for (const key of childKeys) {
261
+
262
+ inspectObj[key] = w[key];
263
+ }
264
+ return inspectObj;
265
+ }
266
+
267
+
268
+
269
+ if (
270
+ w.____slothletInternal?.mode === "lazy" &&
271
+ w.____slothletInternal?.state &&
272
+ !w.____slothletInternal?.state.materialized &&
273
+ w.____slothletInternal?.proxy
274
+ ) {
275
+ return w.____slothletInternal.proxy;
276
+ }
277
+ return w.____slothletInternal?.impl;
278
+ }
279
+
280
+
281
+ get __impl() {
282
+ return this.____slothletInternal.impl;
283
+ }
284
+
285
+
286
+ static _cloneImpl(value) {
287
+ if (value && typeof value === "object" && !Array.isArray(value) && typeof value !== "function") {
288
+ const isProxy = util.types.isProxy(value);
289
+ if (isProxy) {
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+ if (resolveWrapper(value)) {
299
+ const clone = {};
300
+ for (const key of Reflect.ownKeys(value)) {
301
+ try {
302
+ clone[key] = value[key];
303
+ } catch {
304
+
305
+ }
306
+ }
307
+ return clone;
308
+ }
309
+
310
+ return value;
311
+ }
312
+ const uw_cloneDescriptors = Object.getOwnPropertyDescriptors(value);
313
+ return Object.create(Object.getPrototypeOf(value), uw_cloneDescriptors);
314
+ }
315
+ return value;
316
+ }
317
+
318
+
319
+ static _extractFullImpl(wrapper) {
320
+ if (!wrapper) return null;
321
+
322
+ const impl = wrapper.____slothletInternal.impl;
323
+
324
+
325
+ if (impl === null || impl === undefined) return impl;
326
+ if (typeof impl !== "object" && typeof impl !== "function") return impl;
327
+
328
+
329
+ if (typeof impl === "function") return impl;
330
+
331
+
332
+ const extractFullImpl_result = {};
333
+
334
+
335
+ for (const key of Object.keys(impl)) {
336
+
337
+
338
+ if (key.startsWith("__")) continue;
339
+ extractFullImpl_result[key] = impl[key];
340
+ }
341
+
342
+
343
+
344
+
345
+
346
+
347
+ if (impl.__childFilePaths) {
348
+ extractFullImpl_result.__childFilePaths = impl.__childFilePaths;
349
+ }
350
+
351
+
352
+
353
+
354
+ if (impl.__childFilePathsPreMaterialize) {
355
+ extractFullImpl_result.__childFilePathsPreMaterialize = impl.__childFilePathsPreMaterialize;
356
+ }
357
+
358
+
359
+
360
+ for (const key of Object.keys(wrapper)) {
361
+
362
+
363
+ if (UnifiedWrapper.INTERNAL_KEYS.has(key)) continue;
364
+ if (key in extractFullImpl_result) continue;
365
+
366
+ const extractFullImpl_child = wrapper[key];
367
+ const _extractChildW = resolveWrapper(extractFullImpl_child);
368
+ if (_extractChildW) {
369
+
370
+ extractFullImpl_result[key] = UnifiedWrapper._extractFullImpl(_extractChildW);
371
+ } else {
372
+ extractFullImpl_result[key] = extractFullImpl_child;
373
+ }
374
+ }
375
+
376
+ return extractFullImpl_result;
377
+ }
378
+
379
+
380
+ _applyNewImpl(newImpl, forceReuseChildren = false) {
381
+
382
+
383
+ this.____slothletInternal.impl = UnifiedWrapper._cloneImpl(newImpl);
384
+ this.____slothletInternal.invalid = false;
385
+
386
+
387
+
388
+
389
+ if (
390
+ !this.____slothletInternal.isCallableLocked &&
391
+ !this.____slothletInternal.isCallable &&
392
+ (typeof newImpl === "function" || (newImpl && typeof newImpl.default === "function"))
393
+ ) {
394
+ this.____slothletInternal.isCallable = true;
395
+ this.____slothletInternal.isCallableLocked = true;
396
+ }
397
+
398
+
399
+
400
+
401
+
402
+
403
+ if (!this.____slothletInternal.filePath && this.____slothletInternal.impl && this.____slothletInternal.impl.__filePath) {
404
+ this.____slothletInternal.filePath = this.____slothletInternal.impl.__filePath;
405
+ this.slothlet.debug("wrapper", {
406
+ key: "DEBUG_MODE_APPLY_IMPL_UPDATE_PATH",
407
+ apiPath: this.____slothletInternal.apiPath,
408
+ filePath: this.____slothletInternal.filePath
409
+ });
410
+ }
411
+
412
+ this.___adoptImplChildren(forceReuseChildren);
413
+ }
414
+
415
+
416
+ ___setImpl(newImpl, moduleID = null, forceReuseChildren = false) {
417
+
418
+
419
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && this.____slothletInternal.apiPath === "string") {
420
+ this.slothlet.debug("wrapper", {
421
+ key: "DEBUG_MODE_SETIMPL_CALLED",
422
+ apiPath: this.____slothletInternal.apiPath,
423
+
424
+
425
+ newImplKeys: Object.keys(newImpl || {})
426
+ });
427
+ }
428
+
429
+
430
+ this._applyNewImpl(newImpl, forceReuseChildren);
431
+
432
+
433
+ if (newImpl && this.slothlet.handlers?.lifecycle) {
434
+ const wrapperMetadata = this.slothlet.handlers.metadata.getMetadata(this);
435
+
436
+ let extractedModuleId = moduleID || (wrapperMetadata?.moduleID ? wrapperMetadata.moduleID.split(":")[0] : null);
437
+
438
+
439
+
440
+ if (extractedModuleId && typeof extractedModuleId !== "string") {
441
+ extractedModuleId = extractedModuleId.moduleID || extractedModuleId.__moduleID || String(extractedModuleId);
442
+ }
443
+
444
+ this.slothlet.handlers.lifecycle.emit("impl:changed", {
445
+ apiPath: this.____slothletInternal.apiPath,
446
+ impl: newImpl,
447
+ wrapper: Object.freeze({ __impl: this.____slothletInternal.impl }),
448
+ source: "hot-reload",
449
+ moduleID: extractedModuleId,
450
+ filePath: wrapperMetadata?.filePath,
451
+ sourceFolder: wrapperMetadata?.sourceFolder
452
+ });
453
+ }
454
+
455
+ this.____slothletInternal.state.materialized = true;
456
+ this.____slothletInternal.state.inFlight = false;
457
+
458
+
459
+
460
+
461
+ if (this.slothlet._onWrapperMaterialized) {
462
+ this.slothlet._onWrapperMaterialized();
463
+ }
464
+ }
465
+
466
+
467
+ ___resetLazy(newMaterializeFunc) {
468
+ this.slothlet.debug("wrapper", {
469
+ key: "DEBUG_MODE_RESETLAZY_CALLED",
470
+ apiPath: this.____slothletInternal.apiPath,
471
+ hadImpl: this.____slothletInternal.impl !== null,
472
+ hadChildren: Object.keys(this).filter((k) => !k.startsWith("_") && !k.startsWith("__")).length
473
+ });
474
+
475
+
476
+ for (const key of Reflect.ownKeys(this)) {
477
+
478
+
479
+ if (typeof key === "string" && (key.startsWith("_") || key.startsWith("__"))) {
480
+ continue;
481
+ }
482
+ const child = this[key];
483
+ const childRaw = resolveWrapper(child);
484
+ if (childRaw) {
485
+ childRaw.___invalidate();
486
+ }
487
+ const descriptor = Object.getOwnPropertyDescriptor(this, key);
488
+
489
+
490
+ if (descriptor?.configurable) {
491
+ delete this[key];
492
+ }
493
+ }
494
+
495
+
496
+ this.____slothletInternal.impl = null;
497
+ this.____slothletInternal.invalid = false;
498
+ this.____slothletInternal.state.materialized = false;
499
+ this.____slothletInternal.state.inFlight = false;
500
+
501
+
502
+ this.____slothletInternal.materializationPromise = null;
503
+
504
+
505
+ this.____slothletInternal.materializeFunc = newMaterializeFunc;
506
+
507
+
508
+
509
+
510
+ if (this.____slothletInternal.waitingProxyCache) {
511
+ this.____slothletInternal.waitingProxyCache.clear();
512
+ }
513
+
514
+ this.slothlet.debug("wrapper", {
515
+ key: "DEBUG_MODE_RESETLAZY_COMPLETE",
516
+ apiPath: this.____slothletInternal.apiPath
517
+ });
518
+ }
519
+
520
+
521
+ async ___materialize() {
522
+
523
+ if (this.____slothletInternal.state.materialized) {
524
+ return;
525
+ }
526
+
527
+
528
+
529
+ if (this.____slothletInternal.invalid) {
530
+ return;
531
+ }
532
+
533
+
534
+
535
+ if (this.____slothletInternal.materializationPromise) {
536
+ this.slothlet.debug("wrapper", {
537
+ key: "DEBUG_MODE_MATERIALIZE_AWAIT",
538
+ apiPath: this.____slothletInternal.apiPath
539
+ });
540
+ return this.____slothletInternal.materializationPromise;
541
+ }
542
+
543
+
544
+
545
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && this.apiPath === "string") {
546
+ this.slothlet.debug("wrapper", {
547
+ key: "DEBUG_MODE_MATERIALIZE_START",
548
+ apiPath: this.apiPath
549
+ });
550
+ }
551
+
552
+
553
+ this.____slothletInternal.materializationPromise = (async () => {
554
+ this.____slothletInternal.state.inFlight = true;
555
+
556
+ try {
557
+ if (this.____slothletInternal.materializeFunc) {
558
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && this.____slothletInternal.apiPath === "string") {
559
+ this.slothlet.debug("wrapper", {
560
+ key: "DEBUG_MODE_MATERIALIZE_CALLING_FUNC",
561
+ apiPath: this.____slothletInternal.apiPath
562
+ });
563
+ }
564
+
565
+
566
+ const lazy_setImpl = (value) => {
567
+ this._applyNewImpl(value);
568
+ };
569
+ const result = await this.____slothletInternal.materializeFunc(lazy_setImpl);
570
+
571
+
572
+ if (!this.____slothletInternal.impl) {
573
+ this._applyNewImpl(result);
574
+ }
575
+
576
+ this.____slothletInternal.state.materialized = true;
577
+
578
+
579
+
580
+
581
+ if (this.slothlet._onWrapperMaterialized) {
582
+ this.slothlet._onWrapperMaterialized();
583
+ }
584
+
585
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && this.____slothletInternal.apiPath === "string") {
586
+ this.slothlet.debug("wrapper", {
587
+ key: "DEBUG_MODE_MATERIALIZE_COMPLETE",
588
+ apiPath: this.____slothletInternal.apiPath,
589
+ resultType: typeof result,
590
+
591
+
592
+ resultKeys: Object.keys(result || {})
593
+ });
594
+ }
595
+ }
596
+ } catch (error) {
597
+
598
+
599
+ if ((wrapperDebugEnabled || this.____config?.debug?.wrapper) && this.____slothletInternal.apiPath === "string") {
600
+ this.slothlet.debug("wrapper", {
601
+ key: "DEBUG_MODE_MATERIALIZE_ERROR",
602
+ apiPath: this.____slothletInternal.apiPath,
603
+ error: error.message
604
+ });
605
+ }
606
+ throw error;
607
+ } finally {
608
+
609
+ this.____slothletInternal.state.inFlight = false;
610
+ this.____slothletInternal.materializationPromise = null;
611
+ }
612
+ })();
613
+
614
+
615
+ return this.____slothletInternal.materializationPromise;
616
+ }
617
+
618
+
619
+ _materialize() {
620
+ return this.___materialize();
621
+ }
622
+
623
+
624
+ ___invalidate() {
625
+ this.____slothletInternal.invalid = true;
626
+ this.____slothletInternal.impl = null;
627
+
628
+ for (const key of Reflect.ownKeys(this)) {
629
+
630
+
631
+ if (typeof key === "string" && (key.startsWith("_") || key.startsWith("__"))) {
632
+ continue;
633
+ }
634
+ const descriptor = Object.getOwnPropertyDescriptor(this, key);
635
+
636
+
637
+ if (descriptor?.configurable) {
638
+ delete this[key];
639
+ }
640
+ }
641
+ }
642
+
643
+
644
+ ___adoptImplChildren(forceReuseChildren = false) {
645
+ const preExistingKeys = Object.keys(this).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
646
+ this.slothlet.debug("wrapper", {
647
+ key: "DEBUG_MODE_ADOPT_START",
648
+ apiPath: this.____slothletInternal.apiPath,
649
+
650
+
651
+ wrapperId: this.____slothletInternal.id || "no-id",
652
+ preExistingKeys: preExistingKeys.join(","),
653
+ collisionMode: this.____slothletInternal.state.collisionMode
654
+ });
655
+
656
+ if (
657
+ !this.____slothletInternal.impl ||
658
+ (typeof this.____slothletInternal.impl !== "object" && typeof this.____slothletInternal.impl !== "function")
659
+ ) {
660
+ return;
661
+ }
662
+
663
+ const ownKeys = Reflect.ownKeys(this.____slothletInternal.impl);
664
+
665
+ const internalKeys = new Set([
666
+ "__impl",
667
+ "___setImpl",
668
+ "___resetLazy",
669
+ "_materialize",
670
+ "_impl",
671
+ "_state",
672
+ "_invalid",
673
+ "____slothlet",
674
+ "____slothletInternal"
675
+ ]);
676
+ const keepImplProperties =
677
+ typeof this.____slothletInternal.impl === "function" ||
678
+ (this.____slothletInternal.impl &&
679
+ typeof this.____slothletInternal.impl === "object" &&
680
+ typeof this.____slothletInternal.impl.default === "function");
681
+ if (
682
+ keepImplProperties &&
683
+ this.____slothletInternal.impl &&
684
+ typeof this.____slothletInternal.impl === "object" &&
685
+ typeof this.____slothletInternal.impl.default === "function"
686
+ ) {
687
+ internalKeys.add("default");
688
+ }
689
+ const observedKeys = new Set();
690
+
691
+
692
+
693
+
694
+ const existingKeys = Object.keys(this).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
695
+ const storedCollisionMode = this.____slothletInternal.state.collisionMode;
696
+ const isMergeScenario = storedCollisionMode !== "replace" && existingKeys.length > 0;
697
+
698
+ this.slothlet.debug("wrapper", {
699
+ key: "DEBUG_MODE_ADOPT",
700
+ apiPath: this.____slothletInternal.apiPath,
701
+ mode: this.____slothletInternal.mode,
702
+ storedCollisionMode,
703
+ existingKeys: existingKeys.join(","),
704
+ isMergeScenario
705
+ });
706
+
707
+
708
+
709
+
710
+ const savedChildren = new Map();
711
+ if (storedCollisionMode === "replace" && existingKeys.length > 0) {
712
+ this.slothlet.debug("wrapper", {
713
+ key: "DEBUG_MODE_ADOPT_REPLACE_CLEARING",
714
+ count: existingKeys.length
715
+ });
716
+
717
+ for (const key of existingKeys) {
718
+ const child = this[key];
719
+ if (resolveWrapper(child) !== null) {
720
+ savedChildren.set(key, child);
721
+ }
722
+ const descriptor = Object.getOwnPropertyDescriptor(this, key);
723
+ if (descriptor?.configurable) {
724
+ delete this[key];
725
+ }
726
+ }
727
+
728
+ } else {
729
+
730
+ for (const key of existingKeys) {
731
+ observedKeys.add(key);
732
+ }
733
+ }
734
+
735
+
736
+ const metadataKeys = new Set(["__childFilePaths", "__filePath", "__childFilePathsPreMaterialize"]);
737
+ const skipKeys = typeof this.____slothletInternal.impl === "function" ? new Set(["length", "name", "prototype"]) : null;
738
+
739
+ const builtinKeys = new Set(["slothlet", "shutdown", "destroy"]);
740
+
741
+ for (const key of ownKeys) {
742
+ if (internalKeys.has(key)) {
743
+ continue;
744
+ }
745
+
746
+ if (typeof key === "string" && metadataKeys.has(key)) {
747
+ continue;
748
+ }
749
+
750
+ if (typeof key === "string" && builtinKeys.has(key)) {
751
+ continue;
752
+ }
753
+ if (skipKeys && typeof key === "string" && skipKeys.has(key)) {
754
+ continue;
755
+ }
756
+
757
+
758
+
759
+ if (
760
+ !this.____slothletInternal.impl ||
761
+ (typeof this.____slothletInternal.impl !== "object" && typeof this.____slothletInternal.impl !== "function")
762
+ ) {
763
+ break;
764
+ }
765
+
766
+ const descriptor = Object.getOwnPropertyDescriptor(this.____slothletInternal.impl, key);
767
+
768
+
769
+ if (!descriptor) {
770
+ continue;
771
+ }
772
+
773
+ const value = this.____slothletInternal.impl[key];
774
+
775
+
776
+ if (value === this.____slothletInternal.impl) {
777
+ continue;
778
+ }
779
+
780
+
781
+
782
+
783
+ if (typeof key !== "symbol") {
784
+ this.slothlet.debug("wrapper", {
785
+ key: "DEBUG_MODE_ADOPT_PROCESS",
786
+ apiPath: this.____slothletInternal.apiPath,
787
+ propKey: key,
788
+ typeOf: typeof value,
789
+ valueName: value?.name
790
+ });
791
+ }
792
+ observedKeys.add(key);
793
+
794
+
795
+
796
+ if (hasOwn(this, key) && !key.toString().startsWith("_")) {
797
+
798
+
799
+
800
+
801
+ if (typeof key !== "symbol") {
802
+ this.slothlet.debug("wrapper", {
803
+ key: "DEBUG_MODE_ADOPT_CHECK",
804
+ apiPath: this.____slothletInternal.apiPath,
805
+ propKey: key,
806
+ has__collisionMergedKeys: !!this.____slothletInternal.collisionMergedKeys,
807
+ inSet: this.____slothletInternal.collisionMergedKeys?.has(key)
808
+ });
809
+ }
810
+ const isCollisionMerged = this.____slothletInternal.collisionMergedKeys && this.____slothletInternal.collisionMergedKeys.has(key);
811
+
812
+ if (isCollisionMerged && !forceReuseChildren) {
813
+
814
+
815
+
816
+
817
+
818
+
819
+ if (typeof key !== "symbol") {
820
+ this.slothlet.debug("wrapper", {
821
+ key: "DEBUG_MODE_ADOPT_SKIP_COLLISION_MERGED",
822
+ apiPath: this.____slothletInternal.apiPath,
823
+ propKey: key
824
+ });
825
+ }
826
+
827
+
828
+ if (descriptor.configurable) {
829
+ delete this.____slothletInternal.impl[key];
830
+ }
831
+ continue;
832
+ }
833
+
834
+
835
+
836
+
837
+
838
+ if (typeof key !== "symbol") {
839
+ this.slothlet.debug("wrapper", {
840
+ key: "DEBUG_MODE_ADOPT_ALLOW_NOT_COLLISION_MERGED",
841
+ apiPath: this.____slothletInternal.apiPath,
842
+ propKey: key
843
+ });
844
+ }
845
+ }
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+ const existingChild = savedChildren.get(key) || this[key];
855
+ let wrapped;
856
+
857
+
858
+
859
+
860
+
861
+ const skipChildReuse = !forceReuseChildren && this.____slothletInternal.mode === "lazy" && storedCollisionMode === "replace";
862
+
863
+ if (!skipChildReuse && existingChild && resolveWrapper(existingChild) !== null) {
864
+
865
+
866
+
867
+ if (resolveWrapper(value) !== null) {
868
+
869
+ const newWrapper = resolveWrapper(value);
870
+
871
+
872
+ let rawImpl = newWrapper ? newWrapper.____slothletInternal.impl : null;
873
+
874
+
875
+
876
+
877
+
878
+ if (
879
+ rawImpl &&
880
+ typeof rawImpl === "object" &&
881
+ !Array.isArray(rawImpl) &&
882
+ typeof rawImpl !== "function" &&
883
+ Object.keys(rawImpl).filter((k) => !k.startsWith("__")).length === 0
884
+ ) {
885
+ const wrapperOwnKeys = Object.keys(newWrapper).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
886
+
887
+
888
+ if (wrapperOwnKeys.length > 0) {
889
+ rawImpl = UnifiedWrapper._extractFullImpl(newWrapper);
890
+ }
891
+ }
892
+
893
+
894
+
895
+ if (rawImpl !== null && rawImpl !== undefined) {
896
+ resolveWrapper(existingChild).___setImpl(
897
+ rawImpl,
898
+ this.slothlet,
899
+ this.____slothletInternal.moduleID,
900
+ this.____slothletInternal.filePath
901
+ );
902
+ } else if (newWrapper && newWrapper.____slothletInternal.materializeFunc) {
903
+
904
+
905
+
906
+ const existingChildWrapper = resolveWrapper(existingChild);
907
+
908
+
909
+ if (existingChildWrapper) {
910
+ existingChildWrapper.___resetLazy(newWrapper.____slothletInternal.materializeFunc);
911
+ }
912
+ }
913
+
914
+ wrapped = existingChild;
915
+ } else {
916
+ resolveWrapper(existingChild).___setImpl(
917
+ value,
918
+ this.slothlet,
919
+ this.____slothletInternal.moduleID,
920
+ this.____slothletInternal.filePath
921
+ );
922
+ wrapped = existingChild;
923
+ }
924
+
925
+
926
+ if (typeof key !== "symbol") {
927
+ this.slothlet.debug("wrapper", {
928
+ key: "DEBUG_MODE_ADOPT_REUSE_CHILD_WRAPPER",
929
+ apiPath: this.____slothletInternal.apiPath,
930
+ propKey: key
931
+ });
932
+ }
933
+ } else {
934
+
935
+ wrapped = this.___createChildWrapper(key, value);
936
+
937
+
938
+ if (typeof key !== "symbol") {
939
+ this.slothlet.debug("wrapper", {
940
+ key: "DEBUG_MODE_ADOPT_WRAP",
941
+ apiPath: this.____slothletInternal.apiPath,
942
+ propKey: key,
943
+ wrapped: wrapped ? "YES" : wrapped === null ? "NULL" : "NO"
944
+ });
945
+ }
946
+ }
947
+
948
+ if (wrapped) {
949
+
950
+
951
+ const existing = this[key];
952
+ const existingDescriptor = Object.getOwnPropertyDescriptor(this, key);
953
+
954
+
955
+
956
+
957
+ if (existing === wrapped || (existingDescriptor && !existingDescriptor.configurable)) {
958
+
959
+
960
+ if (typeof key !== "symbol") {
961
+ this.slothlet.debug("wrapper", {
962
+ key:
963
+ existingDescriptor && !existingDescriptor.configurable
964
+ ? "DEBUG_MODE_ADOPT_SKIP_NON_CONFIGURABLE"
965
+ : "DEBUG_MODE_ADOPT_SKIP_SAME_WRAPPER",
966
+ apiPath: this.____slothletInternal.apiPath,
967
+ propKey: key
968
+ });
969
+ }
970
+ } else {
971
+
972
+
973
+ if (typeof key !== "symbol") {
974
+ this.slothlet.debug("wrapper", {
975
+ key: "DEBUG_MODE_ADOPT_DEFINE",
976
+ apiPath: this.____slothletInternal.apiPath,
977
+ propKey: key
978
+ });
979
+ }
980
+ Object.defineProperty(this, key, {
981
+ value: wrapped,
982
+ writable: false,
983
+ enumerable: true,
984
+ configurable: true
985
+ });
986
+
987
+
988
+ if (typeof key !== "symbol") {
989
+ this.slothlet.debug("wrapper", {
990
+ key: "DEBUG_MODE_ADOPT_DEFINED",
991
+ apiPath: this.____slothletInternal.apiPath,
992
+ propKey: key
993
+ });
994
+ }
995
+ }
996
+
997
+
998
+ if (descriptor.configurable && !keepImplProperties && this.____slothletInternal.impl) {
999
+ delete this.____slothletInternal.impl[key];
1000
+ }
1001
+ } else if (wrapped === null) {
1002
+
1003
+ Object.defineProperty(this, key, {
1004
+ value: value,
1005
+ writable: false,
1006
+ enumerable: true,
1007
+ configurable: true
1008
+ });
1009
+
1010
+
1011
+ if (descriptor.configurable && !keepImplProperties && this.____slothletInternal.impl) {
1012
+ delete this.____slothletInternal.impl[key];
1013
+ }
1014
+ } else {
1015
+
1016
+ Object.defineProperty(this, key, {
1017
+ value: value,
1018
+ writable: false,
1019
+ enumerable: true,
1020
+ configurable: true
1021
+ });
1022
+
1023
+
1024
+ if (descriptor.configurable && !keepImplProperties && this.____slothletInternal.impl) {
1025
+ delete this.____slothletInternal.impl[key];
1026
+ }
1027
+ }
1028
+ }
1029
+
1030
+
1031
+
1032
+ if (!isMergeScenario) {
1033
+ const currentKeys = Object.keys(this).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
1034
+ for (const key of currentKeys) {
1035
+ if (!observedKeys.has(key)) {
1036
+ const existing = this[key];
1037
+ const existingRaw = resolveWrapper(existing);
1038
+
1039
+
1040
+ if (existingRaw) {
1041
+ existingRaw.___invalidate();
1042
+ }
1043
+ const descriptor = Object.getOwnPropertyDescriptor(this, key);
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+ if (descriptor?.configurable) {
1051
+ delete this[key];
1052
+ }
1053
+ }
1054
+ }
1055
+ }
1056
+
1057
+
1058
+ if (this._mergeAfterMaterialize) {
1059
+ const { existingWrapper, isMergeReplace: ____isMergeReplace } = this._mergeAfterMaterialize;
1060
+
1061
+
1062
+
1063
+ const existingKeys = Object.keys(existingWrapper).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
1064
+ for (const key of existingKeys) {
1065
+ if (!(key in this) || key.startsWith("_") || key.startsWith("__")) {
1066
+ const child = existingWrapper[key];
1067
+ Object.defineProperty(this, key, {
1068
+ value: child,
1069
+ writable: false,
1070
+ enumerable: true,
1071
+ configurable: true
1072
+ });
1073
+ }
1074
+ }
1075
+
1076
+
1077
+ delete this._mergeAfterMaterialize;
1078
+ }
1079
+ }
1080
+
1081
+
1082
+ ___createChildWrapper(key, value) {
1083
+ if (value === undefined) {
1084
+ return undefined;
1085
+ }
1086
+
1087
+ if (value && resolveWrapper(value) !== null) {
1088
+ return value;
1089
+ }
1090
+
1091
+
1092
+
1093
+
1094
+ if (
1095
+ value instanceof Map ||
1096
+ value instanceof Set ||
1097
+ value instanceof WeakMap ||
1098
+ value instanceof WeakSet ||
1099
+ value instanceof Date ||
1100
+ value instanceof RegExp ||
1101
+ value instanceof Promise ||
1102
+ value instanceof Error ||
1103
+ ArrayBuffer.isView(value) ||
1104
+ value instanceof ArrayBuffer
1105
+ ) {
1106
+ return null;
1107
+ }
1108
+
1109
+ let childImpl = value;
1110
+ if (this.____slothletInternal.mode === "eager" && childImpl && typeof childImpl === "object") {
1111
+ if (Array.isArray(childImpl)) {
1112
+ childImpl = childImpl.slice();
1113
+ } else {
1114
+ const descriptors = Object.getOwnPropertyDescriptors(childImpl);
1115
+ childImpl = Object.create(Object.getPrototypeOf(childImpl), descriptors);
1116
+ }
1117
+ }
1118
+
1119
+
1120
+ const parentMetadata = this.slothlet.handlers?.metadata?.getMetadata(this);
1121
+
1122
+
1123
+ const childExistingMetadata = this.slothlet.handlers?.metadata?.getMetadata(value);
1124
+ let childFilePath = childExistingMetadata?.filePath || null;
1125
+ let childModuleId = null;
1126
+
1127
+ if (!childFilePath) {
1128
+
1129
+
1130
+
1131
+ const keyStr = typeof key === "symbol" ? String(key) : key;
1132
+ this.slothlet.debug("wrapper", {
1133
+ key: "DEBUG_MODE_WRAP_CHILD_PATH_CHECK",
1134
+ apiPath: this.apiPath,
1135
+ propKey: keyStr,
1136
+ has_impl: !!this.____slothletInternal.impl,
1137
+ has__childFilePaths: !!(this.____slothletInternal.impl && this.____slothletInternal.impl.__childFilePaths),
1138
+ has__childFilePathsPreMaterialize: !!this.____slothletInternal.childFilePathsPreMaterialize,
1139
+ parentFilePath: parentMetadata?.filePath
1140
+ });
1141
+ if (this.____slothletInternal.impl && this.____slothletInternal.impl.__childFilePaths) {
1142
+ this.slothlet.debug("wrapper", {
1143
+ key: "DEBUG_MODE_WRAP_CHILD_PATH_AVAILABLE",
1144
+ keys: Object.keys(this.____slothletInternal.impl.__childFilePaths).join(","),
1145
+ propKey: keyStr,
1146
+ found: !!this.____slothletInternal.impl.__childFilePaths[key]
1147
+ });
1148
+ }
1149
+
1150
+
1151
+ if (
1152
+ this.____slothletInternal.impl &&
1153
+ this.____slothletInternal.impl.__childFilePaths &&
1154
+ this.____slothletInternal.impl.__childFilePaths[key]
1155
+ ) {
1156
+ childFilePath = this.____slothletInternal.impl.__childFilePaths[key];
1157
+ this.slothlet.debug("wrapper", {
1158
+ key: "DEBUG_MODE_WRAP_CHILD_PATH_USING",
1159
+ childFilePath
1160
+ });
1161
+
1162
+
1163
+ } else if (this.____slothletInternal.childFilePathsPreMaterialize && this.____slothletInternal.childFilePathsPreMaterialize[key]) {
1164
+
1165
+ childFilePath = this.____slothletInternal.childFilePathsPreMaterialize[key];
1166
+ this.slothlet.debug("wrapper", {
1167
+ key: "DEBUG_MODE_WRAP_CHILD_PATH_PRE_MAT",
1168
+ childFilePath
1169
+ });
1170
+
1171
+ } else {
1172
+
1173
+ childFilePath = parentMetadata?.filePath || null;
1174
+ this.slothlet.debug("wrapper", {
1175
+ key: "DEBUG_MODE_WRAP_CHILD_PATH_FALLBACK",
1176
+ childFilePath
1177
+ });
1178
+ }
1179
+
1180
+
1181
+ if (parentMetadata?.moduleID) {
1182
+ const colonIndex = parentMetadata.moduleID.indexOf(":");
1183
+
1184
+
1185
+ childModuleId = colonIndex > 0 ? parentMetadata.moduleID.substring(0, colonIndex) : parentMetadata.moduleID;
1186
+ }
1187
+ } else {
1188
+
1189
+
1190
+
1191
+ if (childExistingMetadata?.moduleID) {
1192
+ const colonIndex = childExistingMetadata.moduleID.indexOf(":");
1193
+
1194
+
1195
+ childModuleId = colonIndex > 0 ? childExistingMetadata.moduleID.substring(0, colonIndex) : childExistingMetadata.moduleID;
1196
+ }
1197
+ }
1198
+
1199
+ const childSourceFolder = childExistingMetadata?.sourceFolder || parentMetadata?.sourceFolder || null;
1200
+
1201
+ const nestedWrapper = new UnifiedWrapper(this.slothlet, {
1202
+ mode: "eager",
1203
+
1204
+
1205
+ apiPath: this.____slothletInternal.apiPath
1206
+ ? `${this.____slothletInternal.apiPath}.${typeof key === "symbol" ? String(key) : key}`
1207
+ : String(key),
1208
+
1209
+ initialImpl: childImpl,
1210
+ isCallable: typeof childImpl === "function",
1211
+ filePath: childFilePath,
1212
+ moduleID: childModuleId,
1213
+ sourceFolder: childSourceFolder
1214
+ });
1215
+
1216
+
1217
+ return nestedWrapper.createProxy();
1218
+ }
1219
+
1220
+
1221
+ ___createWaitingProxy(propChain = []) {
1222
+ const wrapper = this;
1223
+
1224
+
1225
+ const cacheKey = propChain.join(".");
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+ if (!wrapper.____slothletInternal.waitingProxyCache) {
1232
+ wrapper.____slothletInternal.waitingProxyCache = new Map();
1233
+ }
1234
+
1235
+
1236
+
1237
+ if (wrapper.____slothletInternal.waitingProxyCache.has(cacheKey)) {
1238
+ return wrapper.____slothletInternal.waitingProxyCache.get(cacheKey);
1239
+ }
1240
+
1241
+
1242
+
1243
+ const waitingTarget = createNamedProxyTarget(`${wrapper.____slothletInternal.apiPath}_waitingProxy`, "waitingProxyTarget");
1244
+
1245
+
1246
+
1247
+ const waitingProxy = new Proxy(waitingTarget, {
1248
+ get(___target, prop) {
1249
+ if (prop === "then") {
1250
+
1251
+
1252
+
1253
+ return (onFulfilled, onRejected) => {
1254
+ const waitingProxy_thenResolve = async () => {
1255
+
1256
+ if (!wrapper.____slothletInternal.state.materialized) {
1257
+ await wrapper._materialize();
1258
+ }
1259
+
1260
+
1261
+ let current = wrapper;
1262
+ for (const chainProp of propChain) {
1263
+
1264
+
1265
+ if (!current) return undefined;
1266
+
1267
+
1268
+ if (
1269
+ current.____slothletInternal.impl &&
1270
+ typeof current.____slothletInternal.impl === "object" &&
1271
+ util.types.isProxy(current.____slothletInternal.impl)
1272
+ ) {
1273
+ let result = current.____slothletInternal.impl;
1274
+
1275
+ const idx = propChain.indexOf(chainProp);
1276
+ for (let i = idx; i < propChain.length; i++) {
1277
+ result = result[propChain[i]];
1278
+ }
1279
+ return result;
1280
+ }
1281
+
1282
+
1283
+ const isInternal = typeof chainProp === "string" && (chainProp.startsWith("_") || chainProp.startsWith("__"));
1284
+ if (!isInternal && hasOwn(current, chainProp)) {
1285
+ const child = current[chainProp];
1286
+ const _childW = resolveWrapper(child);
1287
+ if (_childW) {
1288
+ current = _childW;
1289
+
1290
+ if (current.____slothletInternal.mode === "lazy" && !current.____slothletInternal.state.materialized) {
1291
+ await current._materialize();
1292
+ }
1293
+ continue;
1294
+ }
1295
+ return child;
1296
+ }
1297
+
1298
+
1299
+ if (current.____slothletInternal.impl && current.____slothletInternal.impl[chainProp] !== undefined) {
1300
+ return current.____slothletInternal.impl[chainProp];
1301
+ }
1302
+
1303
+ return undefined;
1304
+ }
1305
+
1306
+
1307
+ if (
1308
+ current.____slothletInternal.impl &&
1309
+ typeof current.____slothletInternal.impl === "object" &&
1310
+ util.types.isProxy(current.____slothletInternal.impl)
1311
+ ) {
1312
+ return current.____slothletInternal.impl;
1313
+ }
1314
+ return current.____slothletInternal.impl;
1315
+ };
1316
+
1317
+ waitingProxy_thenResolve().then(onFulfilled, onRejected);
1318
+ };
1319
+ }
1320
+ if (prop === "____slothletInternal") return undefined;
1321
+ if (prop === "_materialize") return wrapper._materialize.bind(wrapper);
1322
+ if (prop === "__mode") return wrapper.____slothletInternal.mode;
1323
+ if (prop === "__materialized") return wrapper.____slothletInternal.state.materialized;
1324
+ if (prop === "__inFlight") return wrapper.____slothletInternal.state.inFlight;
1325
+
1326
+
1327
+
1328
+
1329
+ if (
1330
+ wrapper.____slothletInternal.mode === "lazy" &&
1331
+ !wrapper.____slothletInternal.state.materialized &&
1332
+ !wrapper.____slothletInternal.state.inFlight
1333
+ ) {
1334
+ wrapper._materialize();
1335
+ }
1336
+
1337
+ if (prop === util.inspect.custom) {
1338
+
1339
+
1340
+ if (wrapper.____slothletInternal.state.inFlight) {
1341
+ return waitingTarget;
1342
+ }
1343
+
1344
+
1345
+
1346
+ if (!wrapper.____slothletInternal.state.materialized) {
1347
+ return waitingTarget;
1348
+ }
1349
+
1350
+
1351
+
1352
+
1353
+ if (wrapper.____slothletInternal.impl) {
1354
+ let current = wrapper.____slothletInternal.impl;
1355
+ for (const chainProp of propChain) {
1356
+ if (!current || current === null) {
1357
+ return undefined;
1358
+ }
1359
+ current = current[chainProp];
1360
+ }
1361
+
1362
+
1363
+
1364
+ return current;
1365
+ }
1366
+
1367
+
1368
+ return waitingTarget;
1369
+ }
1370
+ if (prop === "__type") {
1371
+ wrapper.slothlet.debug("wrapper", {
1372
+ key: "DEBUG_MODE_WAITING_TYPE",
1373
+ apiPath: wrapper.apiPath,
1374
+ propChain: propChain.join(","),
1375
+ materialized: wrapper.____slothletInternal.state.materialized,
1376
+ hasImpl: wrapper.____slothletInternal.impl !== null
1377
+ });
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+ if (
1384
+ wrapper.____slothletInternal.state.materialized ||
1385
+ (wrapper.____slothletInternal.impl !== null && wrapper.____slothletInternal.impl !== undefined)
1386
+ ) {
1387
+
1388
+
1389
+ let current = wrapper.createProxy();
1390
+ for (const chainProp of propChain) {
1391
+ if (!current) break;
1392
+ const currentWrapper = resolveWrapper(current);
1393
+ if (current && currentWrapper) {
1394
+
1395
+
1396
+ const isInternal = typeof chainProp === "string" && (chainProp.startsWith("_") || chainProp.startsWith("__"));
1397
+ if (!isInternal && chainProp in currentWrapper) {
1398
+ current = currentWrapper[chainProp];
1399
+ wrapper.slothlet.debug("wrapper", {
1400
+ key: "DEBUG_MODE_WAITING_TYPE_WALK_WRAPPER",
1401
+ chainProp: String(chainProp),
1402
+ typeOf: typeof current
1403
+ });
1404
+ continue;
1405
+ }
1406
+ if (
1407
+ currentWrapper.____slothletInternal.impl &&
1408
+ typeof currentWrapper.____slothletInternal.impl === "object" &&
1409
+ currentWrapper.____slothletInternal.impl !== null &&
1410
+ chainProp in currentWrapper.____slothletInternal.impl
1411
+ ) {
1412
+ current = currentWrapper.____slothletInternal.impl[chainProp];
1413
+ wrapper.slothlet.debug("wrapper", {
1414
+ key: "DEBUG_MODE_WAITING_TYPE_WALK_IMPL",
1415
+ chainProp: String(chainProp),
1416
+ typeOf: typeof current
1417
+ });
1418
+ continue;
1419
+ }
1420
+ }
1421
+ wrapper.slothlet.debug("wrapper", {
1422
+ key: "DEBUG_MODE_WAITING_TYPE_WALK_DIRECT",
1423
+ chainProp: String(chainProp),
1424
+ typeOf: typeof current
1425
+ });
1426
+ current = current[chainProp];
1427
+ }
1428
+
1429
+ const resolvedType =
1430
+ typeof current === "function" ? "function" : typeof current === "object" && current !== null ? "object" : typeof current;
1431
+ wrapper.slothlet.debug("wrapper", {
1432
+ key: "DEBUG_MODE_WAITING_TYPE_RESOLVED",
1433
+ apiPath: wrapper.apiPath,
1434
+ propChain: propChain.join(","),
1435
+ resolvedType
1436
+ });
1437
+ return resolvedType;
1438
+ }
1439
+
1440
+ wrapper.slothlet.debug("wrapper", {
1441
+ key: "DEBUG_MODE_WAITING_TYPE_INFLIGHT",
1442
+ apiPath: wrapper.apiPath,
1443
+ propChain: propChain.join(",")
1444
+ });
1445
+ return TYPE_STATES.IN_FLIGHT;
1446
+ }
1447
+ if (prop === "__metadata") {
1448
+
1449
+
1450
+
1451
+ if (wrapper.slothlet.handlers?.metadata) {
1452
+ return wrapper.slothlet.handlers.metadata.getMetadata(wrapper);
1453
+ }
1454
+
1455
+
1456
+ return {};
1457
+ }
1458
+ if (typeof prop === "symbol") return undefined;
1459
+ if (prop === "length") {
1460
+
1461
+
1462
+ return 0;
1463
+ }
1464
+
1465
+
1466
+ if (prop === "name") return waitingTarget.name || "waitingProxyTarget";
1467
+ if (prop === "toString") {
1468
+
1469
+ return Function.prototype.toString.bind(waitingTarget);
1470
+ }
1471
+ if (prop === "valueOf") {
1472
+
1473
+ return Function.prototype.valueOf.bind(waitingTarget);
1474
+ }
1475
+
1476
+
1477
+ if (prop === "toJSON") {
1478
+
1479
+
1480
+ return () => undefined;
1481
+ }
1482
+
1483
+ if (prop === "__slothletPath") return wrapper.____slothletInternal.apiPath;
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+ if (
1491
+ wrapper.____slothletInternal.impl !== null &&
1492
+ wrapper.____slothletInternal.impl !== undefined &&
1493
+ typeof wrapper.____slothletInternal.impl === "object" &&
1494
+ util.types.isProxy(wrapper.____slothletInternal.impl)
1495
+ ) {
1496
+
1497
+
1498
+ let result = wrapper.____slothletInternal.impl;
1499
+ for (const chainProp of propChain) {
1500
+ result = result[chainProp];
1501
+ }
1502
+
1503
+ return result[prop];
1504
+ }
1505
+
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+ if (wrapper.____slothletInternal.impl !== null && wrapper.____slothletInternal.impl !== undefined) {
1512
+
1513
+ let current = wrapper;
1514
+ let remainingChain = [...propChain];
1515
+
1516
+
1517
+ for (let i = 0; i < propChain.length; i++) {
1518
+ const chainProp = propChain[i];
1519
+
1520
+
1521
+ if (
1522
+ current.____slothletInternal.impl &&
1523
+ typeof current.____slothletInternal.impl === "object" &&
1524
+ util.types.isProxy(current.____slothletInternal.impl)
1525
+ ) {
1526
+
1527
+ let proxyResult = current.____slothletInternal.impl;
1528
+ for (const remainingProp of remainingChain) {
1529
+ proxyResult = proxyResult[remainingProp];
1530
+ }
1531
+
1532
+
1533
+ return proxyResult[prop];
1534
+ }
1535
+
1536
+ const isInternal = typeof chainProp === "string" && (chainProp.startsWith("_") || chainProp.startsWith("__"));
1537
+ if (!isInternal && current && chainProp in current) {
1538
+ const cached = current[chainProp];
1539
+
1540
+
1541
+ const _cachedW2 = resolveWrapper(cached);
1542
+
1543
+
1544
+ if (_cachedW2) {
1545
+ current = _cachedW2;
1546
+ remainingChain.shift();
1547
+ } else {
1548
+
1549
+ return undefined;
1550
+ }
1551
+
1552
+ } else {
1553
+
1554
+ return undefined;
1555
+ }
1556
+ }
1557
+
1558
+
1559
+
1560
+ if (
1561
+ current &&
1562
+ current.____slothletInternal.impl &&
1563
+ typeof current.____slothletInternal.impl === "object" &&
1564
+ util.types.isProxy(current.____slothletInternal.impl)
1565
+ ) {
1566
+ return current.____slothletInternal.impl[prop];
1567
+ }
1568
+
1569
+
1570
+ const isFinalInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
1571
+ if (!isFinalInternal && current && prop in current) {
1572
+ return current[prop];
1573
+ }
1574
+
1575
+
1576
+ return undefined;
1577
+ }
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
1584
+ if (!isInternal && hasOwn(wrapper, prop)) {
1585
+ wrapper.slothlet.debug("wrapper", {
1586
+ key: "DEBUG_MODE_WAITING_GET_PREMATURE",
1587
+ apiPath: wrapper.____slothletInternal.apiPath,
1588
+ prop
1589
+ });
1590
+ return wrapper[prop];
1591
+ }
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1598
+
1599
+ if (
1600
+ wrapper.____slothletInternal.needsImmediateChildAdoption &&
1601
+ wrapper.____slothletInternal.materializeFunc &&
1602
+ !wrapper.____slothletInternal.state.materialized &&
1603
+ !wrapper.____slothletInternal.state.inFlight
1604
+ ) {
1605
+ wrapper.slothlet.debug("wrapper", {
1606
+ key: "DEBUG_MODE_WAITING_GET_IMMEDIATE_MAT",
1607
+ apiPath: wrapper.____slothletInternal.apiPath,
1608
+ prop
1609
+ });
1610
+
1611
+ wrapper._materialize().catch((err) => {
1612
+ wrapper.slothlet.debug("wrapper", {
1613
+ key: "DEBUG_MODE_WAITING_GET_IMMEDIATE_MAT_ERROR",
1614
+ apiPath: wrapper.apiPath,
1615
+ error: err.message
1616
+ });
1617
+ });
1618
+
1619
+
1620
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
1621
+ if (!isInternal && hasOwn(wrapper, prop)) {
1622
+ wrapper.slothlet.debug("wrapper", {
1623
+ key: "DEBUG_MODE_WAITING_GET_IMMEDIATE_MAT_SUCCESS",
1624
+ apiPath: wrapper.____slothletInternal.apiPath,
1625
+ prop
1626
+ });
1627
+ return wrapper[prop];
1628
+ }
1629
+ }
1630
+
1631
+
1632
+
1633
+ if (wrapper.____slothletInternal.state.inFlight) {
1634
+
1635
+
1636
+ return wrapper.___createWaitingProxy([...propChain, prop]);
1637
+ }
1638
+
1639
+
1640
+ return wrapper.___createWaitingProxy([...propChain, prop]);
1641
+ },
1642
+
1643
+ async apply(___target, ___thisArg, args) {
1644
+ wrapper.slothlet.debug("wrapper", {
1645
+ key: "DEBUG_MODE_WAITING_APPLY_ENTRY",
1646
+ apiPath: wrapper.____slothletInternal.apiPath,
1647
+ propChain: propChain.join(","),
1648
+ args: args.join(",")
1649
+ });
1650
+ const chainLabel = propChain.map((prop) => String(prop)).join(".");
1651
+
1652
+ if (
1653
+ wrapper.____slothletInternal.mode === "lazy" &&
1654
+ !wrapper.____slothletInternal.state.materialized &&
1655
+ !wrapper.____slothletInternal.state.inFlight
1656
+ ) {
1657
+ wrapper.slothlet.debug("wrapper", {
1658
+ key: "DEBUG_MODE_WAITING_APPLY_MATERIALIZE",
1659
+ apiPath: wrapper.____slothletInternal.apiPath
1660
+ });
1661
+ await wrapper._materialize();
1662
+ wrapper.slothlet.debug("wrapper", {
1663
+ key: "DEBUG_MODE_WAITING_APPLY_MATERIALIZED",
1664
+ apiPath: wrapper.____slothletInternal.apiPath
1665
+ });
1666
+ } else if (
1667
+ wrapper.____slothletInternal.mode === "lazy" &&
1668
+ !wrapper.____slothletInternal.state.materialized &&
1669
+ wrapper.____slothletInternal.state.inFlight
1670
+ ) {
1671
+
1672
+
1673
+
1674
+
1675
+ if (wrapper.____slothletInternal.materializationPromise) {
1676
+ await wrapper.____slothletInternal.materializationPromise;
1677
+
1678
+
1679
+ } else {
1680
+
1681
+ await wrapper._materialize();
1682
+ }
1683
+
1684
+ }
1685
+
1686
+ wrapper.slothlet.debug("wrapper", {
1687
+ key: "DEBUG_MODE_WAITING_APPLY_START_WALK",
1688
+ apiPath: wrapper.____slothletInternal.apiPath,
1689
+ propChain: propChain.join(",")
1690
+ });
1691
+ let current = wrapper.createProxy();
1692
+ let lastWrapper = wrapper;
1693
+ let lastObject = null;
1694
+
1695
+ for (const prop of propChain) {
1696
+ wrapper.slothlet.debug("wrapper", {
1697
+ key: "DEBUG_MODE_WAITING_APPLY_WALK",
1698
+ prop: String(prop),
1699
+ typeOf: typeof current,
1700
+ constructorName: current?.constructor?.name
1701
+ });
1702
+ if (!current) {
1703
+
1704
+
1705
+
1706
+
1707
+
1708
+ if (propChain.some((p) => typeof p === "symbol")) {
1709
+ return undefined;
1710
+ }
1711
+
1712
+
1713
+
1714
+
1715
+
1716
+ if (
1717
+ wrapper.____slothletInternal.invalid ||
1718
+ wrapper.____slothletInternal.impl === null ||
1719
+ (lastWrapper && (lastWrapper.__invalid || lastWrapper._impl === null))
1720
+ ) {
1721
+ return undefined;
1722
+ }
1723
+
1724
+
1725
+
1726
+
1727
+ const finalProp = propChain[propChain.length - 1];
1728
+ if (
1729
+ finalProp === "hasAttribute" ||
1730
+ finalProp === "toJSON" ||
1731
+ finalProp === Symbol.toStringTag ||
1732
+ finalProp === "constructor" ||
1733
+ typeof finalProp === "symbol" ||
1734
+ typeof prop === "symbol"
1735
+ ) {
1736
+ return undefined;
1737
+ }
1738
+ throw new wrapper.slothlet.SlothletError(
1739
+ "CHAIN_ACCESS_UNDEFINED",
1740
+ {
1741
+ apiPath: wrapper.____slothletInternal.apiPath,
1742
+ chainLabel,
1743
+ prop: String(prop)
1744
+ },
1745
+ null,
1746
+ { validationError: true }
1747
+ );
1748
+ }
1749
+
1750
+ const currentWrapper = resolveWrapper(current);
1751
+
1752
+
1753
+ if (currentWrapper) {
1754
+ const state = currentWrapper.____slothletInternal.state;
1755
+ if (!state.materialized) {
1756
+
1757
+
1758
+ if (!state.inFlight && typeof current._materialize === "function") {
1759
+ await current._materialize();
1760
+ }
1761
+
1762
+
1763
+
1764
+ while (!currentWrapper.____slothletInternal.state.materialized) {
1765
+ const nextState = currentWrapper.____slothletInternal.state;
1766
+ if (!nextState.inFlight && !nextState.materialized) {
1767
+ throw new wrapper.slothlet.SlothletError(
1768
+ "CHAIN_MATERIALIZE_FAILED",
1769
+ {
1770
+ apiPath: wrapper.____slothletInternal.apiPath,
1771
+ chainLabel,
1772
+ prop: String(prop)
1773
+ },
1774
+ null,
1775
+ { validationError: true }
1776
+ );
1777
+ }
1778
+ await new Promise((resolve) => setImmediate(resolve));
1779
+ }
1780
+
1781
+ }
1782
+ }
1783
+
1784
+
1785
+
1786
+ if (current && currentWrapper) {
1787
+ lastWrapper = currentWrapper;
1788
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
1789
+ if (!isInternal && prop in currentWrapper) {
1790
+ lastObject = current;
1791
+ current = currentWrapper[prop];
1792
+ continue;
1793
+ }
1794
+
1795
+ if (
1796
+ currentWrapper.____slothletInternal.impl &&
1797
+ typeof currentWrapper.____slothletInternal.impl === "object" &&
1798
+ currentWrapper.____slothletInternal.impl !== null &&
1799
+ prop in currentWrapper.____slothletInternal.impl
1800
+ ) {
1801
+ lastObject = currentWrapper.____slothletInternal.impl;
1802
+ current = currentWrapper.____slothletInternal.impl[prop];
1803
+ continue;
1804
+ }
1805
+ }
1806
+
1807
+ lastObject = current;
1808
+ current = current[prop];
1809
+ }
1810
+
1811
+ wrapper.slothlet.debug("wrapper", {
1812
+ key: "DEBUG_MODE_WAITING_APPLY",
1813
+ apiPath: wrapper.____slothletInternal.apiPath,
1814
+ propChain: propChain.join(","),
1815
+ typeOf: typeof current,
1816
+ currentName: current?.name,
1817
+ isFunction: typeof current === "function"
1818
+ });
1819
+
1820
+ if (typeof current === "function") {
1821
+
1822
+
1823
+
1824
+ return Reflect.apply(current, lastObject, args);
1825
+ }
1826
+
1827
+
1828
+
1829
+
1830
+
1831
+ const _finalChainProp = propChain[propChain.length - 1];
1832
+
1833
+
1834
+ if (_finalChainProp === "hasAttribute" || _finalChainProp === "toJSON") {
1835
+ return undefined;
1836
+ }
1837
+
1838
+
1839
+
1840
+
1841
+ if (current === undefined || current === null) {
1842
+ throw new wrapper.slothlet.SlothletError(
1843
+ "CHAIN_NOT_CALLABLE",
1844
+ {
1845
+ apiPath: wrapper.____slothletInternal.apiPath,
1846
+ chainLabel
1847
+ },
1848
+ null,
1849
+ { validationError: true }
1850
+ );
1851
+ }
1852
+
1853
+ throw new wrapper.slothlet.SlothletError(
1854
+ "CHAIN_NOT_CALLABLE",
1855
+ {
1856
+ apiPath: wrapper.____slothletInternal.apiPath,
1857
+ chainLabel
1858
+ },
1859
+ null,
1860
+ { validationError: true }
1861
+ );
1862
+ },
1863
+ getPrototypeOf: () => null
1864
+ });
1865
+
1866
+
1867
+
1868
+
1869
+ _proxyRegistry.set(waitingProxy, wrapper);
1870
+
1871
+
1872
+ wrapper.____slothletInternal.waitingProxyCache.set(cacheKey, waitingProxy);
1873
+
1874
+ return waitingProxy;
1875
+ }
1876
+
1877
+
1878
+ createProxy() {
1879
+ const wrapper = this;
1880
+ if (wrapper.____slothletInternal.proxy) {
1881
+ return wrapper.____slothletInternal.proxy;
1882
+ }
1883
+
1884
+
1885
+
1886
+ if (
1887
+ wrapper.____slothletInternal.materializeOnCreate &&
1888
+ wrapper.____slothletInternal.mode === "lazy" &&
1889
+ !wrapper.____slothletInternal.state.materialized &&
1890
+ wrapper.____slothletInternal.materializeFunc
1891
+ ) {
1892
+ wrapper._materialize();
1893
+ }
1894
+
1895
+
1896
+
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+ const mightBeCallable =
1903
+ wrapper.____slothletInternal.isCallable ||
1904
+ (wrapper.____slothletInternal.mode === "lazy" && !wrapper.____slothletInternal.isCallableLocked);
1905
+ let proxyTarget;
1906
+ if (mightBeCallable) {
1907
+
1908
+
1909
+ proxyTarget = createNamedProxyTarget(wrapper.____slothletInternal.apiPath, "callableProxy");
1910
+ } else {
1911
+
1912
+ proxyTarget = wrapper;
1913
+ }
1914
+
1915
+
1916
+ if (!(util.inspect.custom in proxyTarget)) {
1917
+ Object.defineProperty(proxyTarget, util.inspect.custom, {
1918
+ value: function () {
1919
+
1920
+ const childKeys = Object.keys(wrapper).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
1921
+ if (childKeys.length > 0 && !wrapper.____slothletInternal.isCallable) {
1922
+ const obj = {};
1923
+ for (const key of childKeys) {
1924
+
1925
+ const child = wrapper[key];
1926
+
1927
+
1928
+ if (child && typeof child.createProxy === "function") {
1929
+ obj[key] = child.createProxy();
1930
+ } else {
1931
+ obj[key] = child;
1932
+ }
1933
+ }
1934
+ return obj;
1935
+ }
1936
+
1937
+
1938
+
1939
+ if (
1940
+ wrapper.____slothletInternal.mode === "lazy" &&
1941
+ !wrapper.____slothletInternal.state.materialized &&
1942
+ (wrapper.____slothletInternal.impl === null || wrapper.____slothletInternal.impl === undefined)
1943
+ ) {
1944
+
1945
+
1946
+
1947
+ return wrapper.____slothletInternal.proxy || wrapper;
1948
+ }
1949
+
1950
+ return wrapper.____slothletInternal.impl;
1951
+ },
1952
+ writable: false,
1953
+ enumerable: false,
1954
+ configurable: true
1955
+ });
1956
+ }
1957
+
1958
+
1959
+ const getTrap = (target, prop, ____receiver) => {
1960
+
1961
+
1962
+ if (target !== wrapper && prop in target) {
1963
+ const desc = Object.getOwnPropertyDescriptor(target, prop);
1964
+
1965
+
1966
+ if (desc && !desc.configurable) {
1967
+
1968
+
1969
+ if (typeof prop === "string" && prop.startsWith("__")) {
1970
+ return wrapper[prop];
1971
+ }
1972
+ return target[prop];
1973
+ }
1974
+
1975
+ }
1976
+
1977
+
1978
+
1979
+
1980
+ if (target === wrapper && typeof prop === "string") {
1981
+ const desc = Object.getOwnPropertyDescriptor(target, prop);
1982
+ if (desc && !desc.configurable) {
1983
+ return target[prop];
1984
+ }
1985
+ }
1986
+
1987
+
1988
+
1989
+
1990
+ const isInternalProp = typeof prop === "string" && UnifiedWrapper.INTERNAL_KEYS.has(prop);
1991
+
1992
+
1993
+
1994
+
1995
+ const allowedInternals = new Set([
1996
+ "_materialize",
1997
+ "__mode",
1998
+ "__apiPath",
1999
+ "__isCallable",
2000
+ "__materializeOnCreate",
2001
+ "__displayName",
2002
+ "__type",
2003
+ "__materialized",
2004
+ "__inFlight",
2005
+ "__slothletPath",
2006
+ "__metadata",
2007
+
2008
+ "__filePath",
2009
+ "__sourceFolder",
2010
+ "__moduleID"
2011
+ ]);
2012
+ if (isInternalProp && !allowedInternals.has(prop)) {
2013
+ return undefined;
2014
+ }
2015
+
2016
+
2017
+ if (prop === "power" || prop === "add") {
2018
+ this.slothlet.debug("wrapper", {
2019
+ key: "DEBUG_MODE_GET_START",
2020
+ apiPath: wrapper.____slothletInternal.apiPath,
2021
+ prop: String(prop),
2022
+ mode: wrapper.____slothletInternal.mode,
2023
+
2024
+
2025
+ collisionMode: wrapper.____slothletInternal.state.collisionMode || "none",
2026
+ materialized: wrapper.____slothletInternal.state.materialized,
2027
+ hasImpl: wrapper.____slothletInternal.impl !== null,
2028
+ inWrapper: !isInternalProp && hasOwn(wrapper, prop)
2029
+ });
2030
+ }
2031
+
2032
+ if (prop === "__mode") return wrapper.____slothletInternal.mode;
2033
+ if (prop === "__apiPath") return wrapper.____slothletInternal.apiPath;
2034
+ if (prop === "__isCallable") return wrapper.____slothletInternal.isCallable;
2035
+ if (prop === "__materializeOnCreate") return wrapper.____slothletInternal.materializeOnCreate;
2036
+ if (prop === "__materialized") return wrapper.____slothletInternal.state.materialized;
2037
+ if (prop === "__inFlight") return wrapper.____slothletInternal.state.inFlight;
2038
+ if (prop === "__displayName") return wrapper.____slothletInternal.displayName;
2039
+ if (prop === "__type") {
2040
+
2041
+ if (
2042
+ wrapper.____slothletInternal.mode === "lazy" &&
2043
+ !wrapper.____slothletInternal.state.materialized &&
2044
+ !wrapper.____slothletInternal.state.inFlight
2045
+ ) {
2046
+ wrapper._materialize();
2047
+ }
2048
+
2049
+
2050
+ if (wrapper.____slothletInternal.mode === "lazy" && wrapper.____slothletInternal.state.inFlight) {
2051
+ return TYPE_STATES.IN_FLIGHT;
2052
+ }
2053
+ if (wrapper.____slothletInternal.mode === "lazy" && !wrapper.____slothletInternal.state.materialized) {
2054
+ return TYPE_STATES.UNMATERIALIZED;
2055
+ }
2056
+
2057
+
2058
+ const impl = wrapper.____slothletInternal.impl;
2059
+ if (typeof impl === "function") {
2060
+ return "function";
2061
+ }
2062
+ if (impl && typeof impl === "object" && typeof impl.default === "function") {
2063
+ return "function";
2064
+ }
2065
+ if (impl && typeof impl === "object") {
2066
+ return "object";
2067
+ }
2068
+
2069
+ if (typeof impl === "string") {
2070
+ return "string";
2071
+ }
2072
+ if (typeof impl === "number") {
2073
+ return "number";
2074
+ }
2075
+ if (typeof impl === "boolean") {
2076
+ return "boolean";
2077
+ }
2078
+ if (typeof impl === "symbol") {
2079
+ return "symbol";
2080
+ }
2081
+ if (typeof impl === "bigint") {
2082
+ return "bigint";
2083
+ }
2084
+ return "undefined";
2085
+ }
2086
+ if (prop === "_materialize") return wrapper._materialize.bind(wrapper);
2087
+ if (prop === "__slothletPath") return wrapper.____slothletInternal.apiPath;
2088
+
2089
+ if (prop === "__metadata") {
2090
+
2091
+ if (wrapper.slothlet.handlers?.metadata) {
2092
+ return wrapper.slothlet.handlers.metadata.getMetadata(wrapper);
2093
+ }
2094
+ return {};
2095
+ }
2096
+
2097
+
2098
+
2099
+ if (prop === "__filePath") return wrapper.____slothletInternal.filePath ?? undefined;
2100
+
2101
+
2102
+ if (prop === "__sourceFolder") return wrapper.____slothletInternal.sourceFolder ?? undefined;
2103
+
2104
+
2105
+ if (prop === "__moduleID") return wrapper.____slothletInternal.moduleID ?? undefined;
2106
+
2107
+
2108
+ if (prop === "__invalid") return wrapper.____slothletInternal.invalid;
2109
+ if (prop === "then") return undefined;
2110
+ if (prop === "constructor") return Object.prototype.constructor;
2111
+ if (prop === util.inspect.custom) {
2112
+
2113
+ return () => {
2114
+
2115
+ const childKeys = Object.keys(wrapper).filter((k) => !k.startsWith("_") && !k.startsWith("__"));
2116
+ if (childKeys.length > 0 && !wrapper.____slothletInternal.isCallable) {
2117
+ const obj = {};
2118
+ for (const key of childKeys) {
2119
+ const child = wrapper[key];
2120
+
2121
+
2122
+ if (child && typeof child.createProxy === "function") {
2123
+ obj[key] = child.createProxy();
2124
+ } else {
2125
+ obj[key] = child;
2126
+ }
2127
+ }
2128
+ return obj;
2129
+ }
2130
+
2131
+
2132
+
2133
+ if (
2134
+ wrapper.____slothletInternal.mode === "lazy" &&
2135
+ !wrapper.____slothletInternal.state.materialized &&
2136
+ (wrapper.____slothletInternal.impl === null || wrapper.____slothletInternal.impl === undefined)
2137
+ ) {
2138
+
2139
+ this.slothlet.debug("wrapper", {
2140
+ key: "DEBUG_MODE_INSPECT_LAZY_UNMATERIALIZED",
2141
+ apiPath: wrapper.apiPath,
2142
+ wrapper: wrapper,
2143
+ ____proxy: wrapper.____slothletInternal.proxy
2144
+ });
2145
+
2146
+
2147
+ return wrapper || wrapper.____slothletInternal.proxy;
2148
+ }
2149
+
2150
+ return wrapper.____slothletInternal.impl;
2151
+ };
2152
+ }
2153
+ if (prop === Symbol.toStringTag) {
2154
+
2155
+ const impl = wrapper.____slothletInternal.impl;
2156
+ if (typeof impl === "function") {
2157
+ return "Function";
2158
+ }
2159
+ if (impl && typeof impl === "object" && typeof impl.default === "function") {
2160
+ return "Function";
2161
+ }
2162
+ return "Object";
2163
+ }
2164
+ if (typeof prop === "symbol") return undefined;
2165
+ if (prop === "length") {
2166
+
2167
+ const impl = wrapper.____slothletInternal.impl;
2168
+ if (typeof impl === "function") {
2169
+ return impl.length;
2170
+ }
2171
+ if (impl && typeof impl === "object" && typeof impl.default === "function") {
2172
+ return impl.default.length;
2173
+ }
2174
+ return 0;
2175
+ }
2176
+ if (prop === "name") {
2177
+
2178
+
2179
+
2180
+
2181
+ if (wrapper.____slothletInternal.apiPath) {
2182
+ const pathParts = wrapper.____slothletInternal.apiPath.split(".");
2183
+ const lastPart = pathParts[pathParts.length - 1];
2184
+
2185
+
2186
+ if (lastPart) {
2187
+ return lastPart;
2188
+ }
2189
+ }
2190
+
2191
+
2192
+ return target.name || "unifiedWrapperProxy";
2193
+ }
2194
+ if (prop === "toString") {
2195
+
2196
+ const impl = wrapper.____slothletInternal.impl;
2197
+ if (typeof impl === "function") {
2198
+ return impl.toString.bind(impl);
2199
+ }
2200
+ if (impl && typeof impl === "object" && typeof impl.default === "function") {
2201
+ return impl.default.toString.bind(impl.default);
2202
+ }
2203
+
2204
+ if (typeof target === "function") {
2205
+ return Function.prototype.toString.bind(target);
2206
+ }
2207
+ return () => `[UnifiedWrapper: ${wrapper.____slothletInternal.apiPath}]`;
2208
+ }
2209
+ if (prop === "valueOf") {
2210
+
2211
+ const impl = wrapper.____slothletInternal.impl;
2212
+ if (typeof impl === "function") {
2213
+ return impl.valueOf.bind(impl);
2214
+ }
2215
+ if (impl && typeof impl === "object" && typeof impl.default === "function") {
2216
+ return impl.default.valueOf.bind(impl.default);
2217
+ }
2218
+ return Function.prototype.valueOf.bind(target);
2219
+ }
2220
+ if (prop === "toJSON") {
2221
+
2222
+
2223
+
2224
+ const impl = wrapper.____slothletInternal.impl;
2225
+
2226
+
2227
+ if (impl && typeof impl.toJSON === "function") {
2228
+ return impl.toJSON.bind(impl);
2229
+ }
2230
+
2231
+ return () => undefined;
2232
+ }
2233
+
2234
+ if (wrapper.____slothletInternal.invalid) {
2235
+ return undefined;
2236
+ }
2237
+
2238
+ if (
2239
+ wrapper.____slothletInternal.mode === "lazy" &&
2240
+ !wrapper.____slothletInternal.state.materialized &&
2241
+ !wrapper.____slothletInternal.state.inFlight
2242
+ ) {
2243
+ wrapper._materialize();
2244
+ }
2245
+
2246
+
2247
+
2248
+
2249
+
2250
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
2251
+ if (!isInternal && hasOwn(wrapper, prop)) {
2252
+
2253
+ if (wrapper.____slothletInternal.state.collisionMode === "replace" && (prop === "power" || prop === "add")) {
2254
+ this.slothlet.debug("wrapper", {
2255
+ key: "DEBUG_MODE_GET_CACHED_REPLACE",
2256
+ apiPath: wrapper.apiPath,
2257
+ prop: String(prop),
2258
+ collisionMode: wrapper.____slothletInternal.state.collisionMode,
2259
+ wrapperKeys: Object.keys(wrapper)
2260
+ .filter((k) => !k.startsWith("_") && !k.startsWith("__"))
2261
+ .join(", ")
2262
+ });
2263
+ }
2264
+ this.slothlet.debug("wrapper", {
2265
+ key: "DEBUG_MODE_GET_CACHED",
2266
+ apiPath: wrapper.____slothletInternal.apiPath,
2267
+ prop: String(prop),
2268
+ materialized: wrapper.____slothletInternal.state.materialized,
2269
+ hasImpl: wrapper.____slothletInternal.impl !== null
2270
+ });
2271
+ const cached = wrapper[prop];
2272
+
2273
+
2274
+ const _cachedWrapper = resolveWrapper(cached);
2275
+ if (_cachedWrapper?.____slothletInternal?.impl !== null && _cachedWrapper?.____slothletInternal?.impl !== undefined) {
2276
+ const cachedImpl = _cachedWrapper.____slothletInternal.impl;
2277
+
2278
+ const cachedType = typeof cachedImpl;
2279
+ if (
2280
+ cachedType === "string" ||
2281
+ cachedType === "number" ||
2282
+ cachedType === "boolean" ||
2283
+ cachedType === "bigint" ||
2284
+ cachedType === "symbol"
2285
+ ) {
2286
+ return cachedImpl;
2287
+ }
2288
+ }
2289
+
2290
+ if (_cachedWrapper) {
2291
+ const cachedWrapper = _cachedWrapper;
2292
+ if (
2293
+ cachedWrapper.____slothletInternal.mode === "lazy" &&
2294
+ !cachedWrapper.____slothletInternal.state.materialized &&
2295
+ !cachedWrapper.____slothletInternal.state.inFlight
2296
+ ) {
2297
+ cachedWrapper._materialize();
2298
+ }
2299
+ }
2300
+
2301
+ return cached;
2302
+ }
2303
+
2304
+
2305
+
2306
+
2307
+
2308
+ if (wrapper.____slothletInternal.impl !== null && wrapper.____slothletInternal.impl !== undefined) {
2309
+
2310
+
2311
+ if (typeof wrapper.____slothletInternal.impl === "object" && util.types.isProxy(wrapper.____slothletInternal.impl)) {
2312
+ return wrapper.____slothletInternal.impl[prop];
2313
+ }
2314
+
2315
+
2316
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
2317
+
2318
+
2319
+ if (!isInternal && hasOwn(wrapper, prop)) {
2320
+ if (prop === "power" || prop === "add") {
2321
+ this.slothlet.debug("wrapper", {
2322
+ key: "DEBUG_MODE_GET_PROXYGET_ACCESSING",
2323
+ prop,
2324
+ wrapperId: wrapper.____slothletInternal.id,
2325
+ apiPath: wrapper.apiPath,
2326
+ collisionMode: wrapper.____slothletInternal.state.collisionMode || "none"
2327
+ });
2328
+ this.slothlet.debug("wrapper", {
2329
+ key: "DEBUG_MODE_GET_PROXYGET_FOUND",
2330
+ wrapperKeys: Object.keys(wrapper)
2331
+ .filter((k) => !k.startsWith("_") && !k.startsWith("__"))
2332
+ .join(", ")
2333
+ });
2334
+ }
2335
+ const cached = wrapper[prop];
2336
+
2337
+ const _cachedWrapper4 = resolveWrapper(cached);
2338
+ if (_cachedWrapper4) {
2339
+ const cachedWrapper = _cachedWrapper4;
2340
+ if (
2341
+ cachedWrapper.____slothletInternal.mode === "lazy" &&
2342
+ !cachedWrapper.____slothletInternal.state.materialized &&
2343
+ !cachedWrapper.____slothletInternal.state.inFlight
2344
+ ) {
2345
+ cachedWrapper._materialize();
2346
+ }
2347
+ }
2348
+ return cached;
2349
+ }
2350
+
2351
+ }
2352
+
2353
+
2354
+
2355
+
2356
+ const isInternalProp2 = typeof prop === "string" && UnifiedWrapper.INTERNAL_KEYS.has(prop);
2357
+ if (
2358
+ wrapper.____slothletInternal.mode === "lazy" &&
2359
+ wrapper.____slothletInternal.state.materialized &&
2360
+ !isInternalProp2 &&
2361
+ !hasOwn(wrapper, prop) &&
2362
+ wrapper.____slothletInternal.impl &&
2363
+ !(prop in wrapper.____slothletInternal.impl)
2364
+ ) {
2365
+ return undefined;
2366
+ }
2367
+
2368
+ if (
2369
+ wrapper.____slothletInternal.mode === "lazy" &&
2370
+ (wrapper.____slothletInternal.state.inFlight || !wrapper.____slothletInternal.impl)
2371
+ ) {
2372
+
2373
+
2374
+
2375
+
2376
+
2377
+ if (!wrapper.____slothletInternal.state.materialized && !wrapper.____slothletInternal.state.inFlight) {
2378
+ wrapper._materialize();
2379
+ }
2380
+
2381
+ this.slothlet.debug("wrapper", {
2382
+ key: "DEBUG_MODE_LAZY_GET_CREATE_WAITING_PROXY",
2383
+ prop: String(prop),
2384
+
2385
+
2386
+ collisionMode: wrapper.____slothletInternal.state.collisionMode || "none",
2387
+ apiPath: wrapper.____slothletInternal.apiPath
2388
+ });
2389
+
2390
+
2391
+
2392
+
2393
+ if (
2394
+ wrapper.____slothletInternal.impl &&
2395
+ typeof wrapper.____slothletInternal.impl === "object" &&
2396
+ util.types.isProxy(wrapper.____slothletInternal.impl)
2397
+ ) {
2398
+ const value = wrapper.____slothletInternal.impl[prop];
2399
+ return value;
2400
+ }
2401
+
2402
+ return wrapper.___createWaitingProxy([prop]);
2403
+ }
2404
+
2405
+
2406
+
2407
+
2408
+ if (
2409
+ wrapper.____slothletInternal.impl &&
2410
+ typeof wrapper.____slothletInternal.impl === "object" &&
2411
+ util.types.isProxy(wrapper.____slothletInternal.impl)
2412
+ ) {
2413
+ const value = wrapper.____slothletInternal.impl[prop];
2414
+
2415
+
2416
+ return value;
2417
+ }
2418
+
2419
+
2420
+
2421
+
2422
+
2423
+
2424
+ let value = wrapper.____slothletInternal.impl ? wrapper.____slothletInternal.impl[prop] : undefined;
2425
+
2426
+
2427
+ if (value === undefined && wrapper.____slothletInternal.impl) {
2428
+ const descriptor = Object.getOwnPropertyDescriptor(wrapper.____slothletInternal.impl, prop);
2429
+
2430
+
2431
+ if (descriptor && descriptor.get) {
2432
+
2433
+ value = descriptor.get.call(wrapper.____slothletInternal.impl);
2434
+ }
2435
+
2436
+ }
2437
+
2438
+
2439
+
2440
+
2441
+ if (value === undefined && Object.prototype.hasOwnProperty.call(target, prop)) {
2442
+ value = target[prop];
2443
+ }
2444
+
2445
+ if (value === undefined) {
2446
+ return undefined;
2447
+ }
2448
+
2449
+
2450
+
2451
+ const valueType = typeof value;
2452
+ if (
2453
+ value === null ||
2454
+ valueType === "string" ||
2455
+ valueType === "number" ||
2456
+ valueType === "boolean" ||
2457
+ valueType === "bigint" ||
2458
+ valueType === "symbol"
2459
+ ) {
2460
+ return value;
2461
+ }
2462
+
2463
+
2464
+
2465
+
2466
+ if (
2467
+ value instanceof Map ||
2468
+ value instanceof Set ||
2469
+ value instanceof WeakMap ||
2470
+ value instanceof WeakSet ||
2471
+ value instanceof Date ||
2472
+ value instanceof RegExp ||
2473
+ value instanceof Promise ||
2474
+ value instanceof Error ||
2475
+ ArrayBuffer.isView(value) ||
2476
+ value instanceof ArrayBuffer
2477
+ ) {
2478
+ return value;
2479
+ }
2480
+
2481
+
2482
+
2483
+
2484
+
2485
+
2486
+
2487
+ if (value && typeof value === "object" && util.types.isProxy(value)) {
2488
+ return value;
2489
+ }
2490
+
2491
+ if (value && (typeof value === "object" || typeof value === "function") && resolveWrapper(value) !== null) {
2492
+ return value;
2493
+ }
2494
+
2495
+ const wrapped = wrapper.___createChildWrapper(prop, value);
2496
+
2497
+
2498
+ if (wrapped) {
2499
+ Object.defineProperty(wrapper, prop, {
2500
+ value: wrapped,
2501
+ writable: false,
2502
+ enumerable: true,
2503
+ configurable: true
2504
+ });
2505
+ return wrapped;
2506
+ }
2507
+
2508
+
2509
+
2510
+
2511
+
2512
+ return value;
2513
+ };
2514
+
2515
+
2516
+ const applyTrap = (target, thisArg, args) => {
2517
+ if (wrapper.____slothletInternal.invalid) {
2518
+
2519
+
2520
+ throw new TypeError(`${wrapper.____slothletInternal.apiPath || "api"} is invalidated`);
2521
+ }
2522
+
2523
+
2524
+ const hookManager = wrapper.slothlet.handlers?.hookManager;
2525
+
2526
+ const hasHooks = hookManager && hookManager.enabled && !wrapper.____slothletInternal.apiPath.startsWith("slothlet.hook");
2527
+
2528
+
2529
+ const api = wrapper.slothlet.boundApi;
2530
+ const ctx = wrapper.slothlet.config?.context || {};
2531
+
2532
+
2533
+ let result;
2534
+ let finalResult;
2535
+ let isAsync = false;
2536
+
2537
+ try {
2538
+
2539
+ if (hasHooks) {
2540
+ const beforeResult = hookManager.executeBeforeHooks(wrapper.____slothletInternal.apiPath, args, api, ctx);
2541
+ args = beforeResult.args;
2542
+
2543
+
2544
+ if (beforeResult.shortCircuit) {
2545
+
2546
+ finalResult = beforeResult.value;
2547
+ return beforeResult.value;
2548
+ }
2549
+ }
2550
+
2551
+
2552
+ if (
2553
+ wrapper.____slothletInternal.mode === "lazy" &&
2554
+ !wrapper.____slothletInternal.state.materialized &&
2555
+ !wrapper.____slothletInternal.state.inFlight
2556
+ ) {
2557
+ wrapper._materialize();
2558
+ }
2559
+
2560
+
2561
+ if (wrapper.____slothletInternal.mode === "lazy" && wrapper.____slothletInternal.state.inFlight) {
2562
+ return new Promise((resolve, reject) => {
2563
+ const checkMaterialized = () => {
2564
+ if (wrapper.____slothletInternal.state.materialized) {
2565
+ const impl = wrapper.____slothletInternal.impl;
2566
+ if (typeof impl === "function") {
2567
+ if (wrapper.slothlet.contextManager) {
2568
+ resolve(wrapper.slothlet.contextManager.runInContext(wrapper.instanceID, impl, thisArg, args, wrapper));
2569
+ } else {
2570
+ resolve(impl.apply(thisArg, args));
2571
+ }
2572
+ } else if (impl && typeof impl === "object" && typeof impl.default === "function") {
2573
+ if (wrapper.contextManager) {
2574
+ resolve(wrapper.contextManager.runInContext(wrapper.instanceID, impl.default, impl, args, wrapper));
2575
+ } else {
2576
+ resolve(impl.default.apply(impl, args));
2577
+ }
2578
+ } else {
2579
+ reject(
2580
+ new wrapper.slothlet.SlothletError(
2581
+ "INVALID_CONFIG_NOT_A_FUNCTION",
2582
+ {
2583
+ apiPath: wrapper.____slothletInternal.apiPath,
2584
+ actualType: typeof impl
2585
+ },
2586
+ null,
2587
+ { validationError: true }
2588
+ )
2589
+ );
2590
+ }
2591
+ return;
2592
+ }
2593
+ if (!wrapper.____slothletInternal.state.inFlight) {
2594
+ reject(
2595
+ new wrapper.slothlet.SlothletError(
2596
+ "INVALID_CONFIG_LAZY_MATERIALIZATION_FAILED",
2597
+ { apiPath: wrapper.____slothletInternal.apiPath },
2598
+ null,
2599
+ {
2600
+ validationError: true
2601
+ }
2602
+ )
2603
+ );
2604
+ return;
2605
+ }
2606
+ setImmediate(checkMaterialized);
2607
+ };
2608
+ checkMaterialized();
2609
+ });
2610
+ }
2611
+
2612
+
2613
+ const impl = wrapper.____slothletInternal.impl;
2614
+
2615
+ if (typeof impl === "function") {
2616
+ if (wrapper.slothlet.contextManager) {
2617
+ result = wrapper.slothlet.contextManager.runInContext(wrapper.instanceID, impl, thisArg, args, wrapper);
2618
+ } else {
2619
+ result = impl.apply(thisArg, args);
2620
+ }
2621
+ } else if (impl && typeof impl === "object" && typeof impl.default === "function") {
2622
+ if (wrapper.slothlet.contextManager) {
2623
+ result = wrapper.slothlet.contextManager.runInContext(wrapper.instanceID, impl.default, impl, args, wrapper);
2624
+ } else {
2625
+ result = impl.default.apply(impl, args);
2626
+ }
2627
+ } else {
2628
+ throw new wrapper.SlothletError(
2629
+ "INVALID_CONFIG_NOT_A_FUNCTION",
2630
+ {
2631
+ apiPath: wrapper.____slothletInternal.apiPath,
2632
+ actualType: typeof impl
2633
+ },
2634
+ null,
2635
+ { validationError: true }
2636
+ );
2637
+ }
2638
+
2639
+
2640
+ if (result && typeof result === "object" && typeof result.then === "function") {
2641
+
2642
+ isAsync = true;
2643
+
2644
+ return result.then(
2645
+ (resolvedResult) => {
2646
+ try {
2647
+
2648
+ if (hasHooks) {
2649
+ const afterResult = hookManager.executeAfterHooks(wrapper.____slothletInternal.apiPath, resolvedResult, args, api, ctx);
2650
+ const finalResult = afterResult.modified ? afterResult.result : resolvedResult;
2651
+ hookManager.executeAlwaysHooks(wrapper.____slothletInternal.apiPath, args, finalResult, false, [], api, ctx);
2652
+ return finalResult;
2653
+ }
2654
+ return resolvedResult;
2655
+ } catch (error) {
2656
+
2657
+
2658
+
2659
+ if (hasHooks) {
2660
+ const originalError = unwrapError(error);
2661
+ const sourceInfo = {
2662
+ type: "after",
2663
+ timestamp: Date.now(),
2664
+ stack: originalError.stack
2665
+ };
2666
+ hookManager.executeErrorHooks(wrapper.____slothletInternal.apiPath, originalError, sourceInfo, args, api, ctx);
2667
+ hookManager.executeAlwaysHooks(wrapper.____slothletInternal.apiPath, args, undefined, true, [originalError], api, ctx);
2668
+ }
2669
+
2670
+
2671
+ const suppressErrors = wrapper.slothlet.config?.hook?.suppressErrors === true;
2672
+ if (suppressErrors) {
2673
+ return undefined;
2674
+ }
2675
+
2676
+ throw error;
2677
+ }
2678
+ },
2679
+ (error) => {
2680
+
2681
+ if (hasHooks && !error[ERROR_HOOK_PROCESSED]) {
2682
+ const originalError = unwrapError(error);
2683
+ const sourceInfo = {
2684
+ type: "function",
2685
+ timestamp: Date.now(),
2686
+ stack: originalError.stack
2687
+ };
2688
+ hookManager.executeErrorHooks(wrapper.____slothletInternal.apiPath, originalError, sourceInfo, args, api, ctx);
2689
+ }
2690
+
2691
+ if (hasHooks) {
2692
+ const originalError = unwrapError(error);
2693
+ hookManager.executeAlwaysHooks(wrapper.____slothletInternal.apiPath, args, undefined, true, [originalError], api, ctx);
2694
+ }
2695
+
2696
+
2697
+ const suppressErrors = wrapper.slothlet.config?.hook?.suppressErrors === true;
2698
+ if (suppressErrors) {
2699
+ return undefined;
2700
+ }
2701
+
2702
+ throw error;
2703
+ }
2704
+ );
2705
+ }
2706
+
2707
+
2708
+ finalResult = result;
2709
+ if (hasHooks) {
2710
+ const afterResult = hookManager.executeAfterHooks(wrapper.____slothletInternal.apiPath, result, args, api, ctx);
2711
+ if (afterResult.modified) {
2712
+ finalResult = afterResult.result;
2713
+ }
2714
+ }
2715
+ return finalResult;
2716
+ } catch (error) {
2717
+
2718
+ this.lastSyncError = error;
2719
+ if (hasHooks && !error[ERROR_HOOK_PROCESSED]) {
2720
+ const originalError = unwrapError(error);
2721
+ const sourceInfo = {
2722
+ type: "function",
2723
+ timestamp: Date.now(),
2724
+ stack: originalError.stack
2725
+ };
2726
+ hookManager.executeErrorHooks(wrapper.____slothletInternal.apiPath, originalError, sourceInfo, args, api, ctx);
2727
+ }
2728
+
2729
+
2730
+ const suppressErrors = wrapper.slothlet.config?.hook?.suppressErrors === true;
2731
+ if (suppressErrors) {
2732
+
2733
+ return undefined;
2734
+ }
2735
+
2736
+ throw error;
2737
+ } finally {
2738
+
2739
+
2740
+
2741
+ if (hasHooks && !isAsync) {
2742
+
2743
+ const syncError = this.lastSyncError;
2744
+ this.lastSyncError = null;
2745
+
2746
+ const resultValue = syncError ? undefined : typeof finalResult !== "undefined" ? finalResult : result;
2747
+ const errors = syncError ? [unwrapError(syncError)] : [];
2748
+ hookManager.executeAlwaysHooks(wrapper.____slothletInternal.apiPath, args, resultValue, !!syncError, errors, api, ctx);
2749
+ }
2750
+ }
2751
+ };
2752
+
2753
+
2754
+ const hasTrap = (target, prop) => {
2755
+ if (prop === "_materialize") {
2756
+ return true;
2757
+ }
2758
+
2759
+ if (
2760
+ wrapper.____slothletInternal.mode === "lazy" &&
2761
+ !wrapper.____slothletInternal.state.materialized &&
2762
+ !wrapper.____slothletInternal.state.inFlight
2763
+ ) {
2764
+ wrapper._materialize();
2765
+ }
2766
+
2767
+
2768
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
2769
+ if (!isInternal && hasOwn(wrapper, prop)) {
2770
+ return true;
2771
+ }
2772
+
2773
+ if (
2774
+ wrapper.____slothletInternal.impl &&
2775
+ (typeof wrapper.____slothletInternal.impl === "object" || typeof wrapper.____slothletInternal.impl === "function") &&
2776
+ prop in wrapper.____slothletInternal.impl
2777
+ ) {
2778
+ return true;
2779
+ }
2780
+
2781
+ return Object.prototype.hasOwnProperty.call(target, prop);
2782
+ };
2783
+
2784
+
2785
+ const getOwnPropertyDescriptorTrap = (target, prop) => {
2786
+ if (
2787
+ wrapper.____slothletInternal.mode === "lazy" &&
2788
+ !wrapper.____slothletInternal.state.materialized &&
2789
+ !wrapper.____slothletInternal.state.inFlight
2790
+ ) {
2791
+ wrapper._materialize();
2792
+ }
2793
+
2794
+ if (prop === "____slothletInternal") return undefined;
2795
+
2796
+ if (prop === "prototype" && typeof target === "function") {
2797
+ const desc = Object.getOwnPropertyDescriptor(target, "prototype");
2798
+
2799
+
2800
+
2801
+ if (desc) {
2802
+ return desc;
2803
+ }
2804
+ }
2805
+
2806
+ if (Object.prototype.hasOwnProperty.call(target, prop)) {
2807
+ return Object.getOwnPropertyDescriptor(target, prop);
2808
+ }
2809
+
2810
+
2811
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
2812
+ if (!isInternal && hasOwn(wrapper, prop)) {
2813
+ const desc = Object.getOwnPropertyDescriptor(wrapper, prop);
2814
+
2815
+
2816
+
2817
+ if (desc) {
2818
+ return desc;
2819
+ }
2820
+ }
2821
+
2822
+ if (
2823
+ wrapper.____slothletInternal.impl &&
2824
+ (typeof wrapper.____slothletInternal.impl === "object" || typeof wrapper.____slothletInternal.impl === "function") &&
2825
+ prop in wrapper.____slothletInternal.impl
2826
+ ) {
2827
+ return Object.getOwnPropertyDescriptor(wrapper.____slothletInternal.impl, prop);
2828
+ }
2829
+
2830
+ return undefined;
2831
+ };
2832
+
2833
+
2834
+ const ownKeysTrap = (target) => {
2835
+ if (
2836
+ wrapper.____slothletInternal.mode === "lazy" &&
2837
+ !wrapper.____slothletInternal.state.materialized &&
2838
+ !wrapper.____slothletInternal.state.inFlight
2839
+ ) {
2840
+ wrapper._materialize();
2841
+ }
2842
+
2843
+ const keys = new Set();
2844
+
2845
+
2846
+
2847
+
2848
+ if (typeof target === "function" || (target && target.__isCallable)) {
2849
+ keys.add("prototype");
2850
+ keys.add("length");
2851
+ keys.add("name");
2852
+ }
2853
+
2854
+
2855
+ for (const key of Reflect.ownKeys(target)) {
2856
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
2857
+
2858
+
2859
+ if (!descriptor.configurable || descriptor.enumerable) {
2860
+ keys.add(key);
2861
+ }
2862
+ }
2863
+
2864
+
2865
+
2866
+ if (target !== wrapper) {
2867
+ for (const key of Reflect.ownKeys(wrapper)) {
2868
+ const descriptor = Object.getOwnPropertyDescriptor(wrapper, key);
2869
+
2870
+
2871
+ if (descriptor && descriptor.enumerable) {
2872
+ keys.add(key);
2873
+ }
2874
+ }
2875
+ }
2876
+
2877
+
2878
+ const implKeys =
2879
+ wrapper.____slothletInternal.impl &&
2880
+ (typeof wrapper.____slothletInternal.impl === "object" || typeof wrapper.____slothletInternal.impl === "function")
2881
+ ? Reflect.ownKeys(wrapper.____slothletInternal.impl)
2882
+ : [];
2883
+ for (const key of implKeys) {
2884
+
2885
+ if (key !== "prototype") {
2886
+ keys.add(key);
2887
+ }
2888
+ }
2889
+
2890
+ return Array.from(keys);
2891
+ };
2892
+
2893
+
2894
+ const setTrap = (target, prop, value) => {
2895
+ if (
2896
+ wrapper.____slothletInternal.mode === "lazy" &&
2897
+ !wrapper.____slothletInternal.state.materialized &&
2898
+ !wrapper.____slothletInternal.state.inFlight
2899
+ ) {
2900
+ wrapper._materialize();
2901
+ }
2902
+
2903
+
2904
+
2905
+
2906
+ if (UnifiedWrapper.INTERNAL_KEYS.has(prop) && prop !== "_materialize") return true;
2907
+
2908
+ const internalKeys = new Set(["_materialize"]);
2909
+ if (!internalKeys.has(prop)) {
2910
+
2911
+ if (hasOwn(wrapper, prop)) {
2912
+ delete wrapper[prop];
2913
+ }
2914
+ Object.defineProperty(wrapper, prop, {
2915
+ value: value,
2916
+ writable: false,
2917
+ enumerable: true,
2918
+ configurable: true
2919
+ });
2920
+ } else {
2921
+
2922
+ target[prop] = value;
2923
+ }
2924
+ return true;
2925
+ };
2926
+
2927
+
2928
+ const deletePropertyTrap = (target, prop) => {
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2936
+
2937
+
2938
+ const internalKeys = new Set([
2939
+
2940
+ "____slothletInternal",
2941
+ "__impl",
2942
+ "___setImpl",
2943
+ "___resetLazy",
2944
+ "_materialize",
2945
+ "___invalidate",
2946
+ "_impl",
2947
+ "___getState",
2948
+ "__state",
2949
+
2950
+ "__mode",
2951
+ "__apiPath",
2952
+ "__slothletPath",
2953
+ "__isCallable",
2954
+ "__materializeOnCreate",
2955
+ "__displayName",
2956
+ "__type",
2957
+ "__metadata",
2958
+ "__invalid",
2959
+ "__filePath",
2960
+ "__sourceFolder",
2961
+ "__moduleID",
2962
+ "__materialized",
2963
+ "__inFlight"
2964
+ ]);
2965
+ if (internalKeys.has(prop)) {
2966
+ return true;
2967
+ }
2968
+
2969
+
2970
+ const isInternal = typeof prop === "string" && (prop.startsWith("_") || prop.startsWith("__"));
2971
+ if (!isInternal && hasOwn(wrapper, prop)) {
2972
+ const childWrapper = wrapper[prop];
2973
+ const childWrapperRaw = resolveWrapper(childWrapper);
2974
+
2975
+
2976
+ if (childWrapperRaw) {
2977
+ childWrapperRaw.___invalidate();
2978
+ }
2979
+ const descriptor = Object.getOwnPropertyDescriptor(wrapper, prop);
2980
+
2981
+
2982
+ if (descriptor?.configurable) {
2983
+ delete wrapper[prop];
2984
+ }
2985
+ }
2986
+
2987
+
2988
+ if (
2989
+ wrapper.____slothletInternal.impl &&
2990
+ typeof wrapper.____slothletInternal.impl === "object" &&
2991
+ prop in wrapper.____slothletInternal.impl
2992
+ ) {
2993
+ delete wrapper.____slothletInternal.impl[prop];
2994
+ }
2995
+
2996
+
2997
+ delete target[prop];
2998
+
2999
+ return true;
3000
+ };
3001
+
3002
+ wrapper.____slothletInternal.proxy = new Proxy(proxyTarget, {
3003
+ get: getTrap,
3004
+ apply: applyTrap,
3005
+ has: hasTrap,
3006
+ getOwnPropertyDescriptor: getOwnPropertyDescriptorTrap,
3007
+ ownKeys: ownKeysTrap,
3008
+ set: setTrap,
3009
+ deleteProperty: deletePropertyTrap,
3010
+ getPrototypeOf: () => null
3011
+ });
3012
+
3013
+ _proxyRegistry.set(wrapper.____slothletInternal.proxy, wrapper);
3014
+ return wrapper.____slothletInternal.proxy;
3015
+ }
3016
+ }
3017
+
3018
+
3019
+ export function resolveWrapper(value) {
3020
+ if (!value) return null;
3021
+
3022
+
3023
+
3024
+ const registered = _proxyRegistry.get(value);
3025
+ if (registered) return registered;
3026
+
3027
+
3028
+
3029
+ if (value instanceof UnifiedWrapper && value.____slothletInternal != null) return value;
3030
+ return null;
3031
+ }