@cldmv/slothlet 2.11.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/AGENT-USAGE.md +355 -325
  2. package/README.md +554 -238
  3. package/dist/lib/builders/api-assignment.mjs +605 -0
  4. package/dist/lib/builders/api_builder.mjs +1073 -0
  5. package/dist/lib/builders/builder.mjs +94 -0
  6. package/dist/lib/builders/modes-processor.mjs +1816 -0
  7. package/dist/lib/errors.mjs +227 -0
  8. package/dist/lib/factories/component-base.mjs +96 -0
  9. package/dist/lib/factories/context.mjs +38 -0
  10. package/dist/lib/handlers/api-cache-manager.mjs +216 -0
  11. package/dist/lib/handlers/api-manager.mjs +2364 -0
  12. package/dist/lib/handlers/context-async.mjs +184 -0
  13. package/dist/lib/handlers/context-live.mjs +184 -0
  14. package/dist/lib/handlers/hook-manager.mjs +789 -0
  15. package/dist/lib/handlers/lifecycle-token.mjs +44 -0
  16. package/dist/lib/handlers/lifecycle.mjs +131 -0
  17. package/dist/lib/handlers/materialize-manager.mjs +64 -0
  18. package/dist/lib/handlers/metadata.mjs +500 -0
  19. package/dist/lib/handlers/ownership.mjs +338 -0
  20. package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
  21. package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
  22. package/dist/lib/helpers/config.mjs +343 -0
  23. package/dist/lib/helpers/eventemitter-context.mjs +365 -0
  24. package/dist/lib/helpers/hint-detector.mjs +63 -0
  25. package/dist/lib/helpers/modes-utils.mjs +53 -0
  26. package/dist/lib/helpers/resolve-from-caller.mjs +123 -117
  27. package/dist/lib/helpers/sanitize.mjs +247 -168
  28. package/dist/lib/helpers/utilities.mjs +46 -81
  29. package/dist/lib/i18n/languages/de-de.json +377 -0
  30. package/dist/lib/i18n/languages/en-gb.json +377 -0
  31. package/dist/lib/i18n/languages/en-us.json +377 -0
  32. package/dist/lib/i18n/languages/es-mx.json +377 -0
  33. package/dist/lib/i18n/languages/fr-fr.json +377 -0
  34. package/dist/lib/i18n/languages/hi-in.json +377 -0
  35. package/dist/lib/i18n/languages/ja-jp.json +377 -0
  36. package/dist/lib/i18n/languages/ko-kr.json +377 -0
  37. package/dist/lib/i18n/languages/pt-br.json +377 -0
  38. package/dist/lib/i18n/languages/ru-ru.json +377 -0
  39. package/dist/lib/i18n/languages/zh-cn.json +377 -0
  40. package/dist/lib/i18n/translations.mjs +140 -0
  41. package/dist/lib/modes/eager.mjs +75 -0
  42. package/dist/lib/modes/lazy.mjs +97 -0
  43. package/dist/lib/processors/flatten.mjs +453 -0
  44. package/dist/lib/processors/loader.mjs +355 -0
  45. package/dist/lib/processors/type-generator.mjs +291 -0
  46. package/dist/lib/processors/typescript.mjs +188 -0
  47. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
  48. package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
  49. package/dist/lib/runtime/runtime.mjs +39 -159
  50. package/dist/slothlet.mjs +525 -744
  51. package/docs/API-RULES.md +338 -486
  52. package/index.cjs +4 -4
  53. package/index.mjs +82 -45
  54. package/package.json +143 -30
  55. package/types/dist/lib/builders/api-assignment.d.mts +97 -0
  56. package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
  57. package/types/dist/lib/builders/api_builder.d.mts +96 -0
  58. package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
  59. package/types/dist/lib/builders/builder.d.mts +60 -0
  60. package/types/dist/lib/builders/builder.d.mts.map +1 -0
  61. package/types/dist/lib/builders/modes-processor.d.mts +32 -0
  62. package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
  63. package/types/dist/lib/errors.d.mts +118 -0
  64. package/types/dist/lib/errors.d.mts.map +1 -0
  65. package/types/dist/lib/factories/component-base.d.mts +182 -0
  66. package/types/dist/lib/factories/component-base.d.mts.map +1 -0
  67. package/types/dist/lib/factories/context.d.mts +26 -0
  68. package/types/dist/lib/factories/context.d.mts.map +1 -0
  69. package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
  70. package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
  71. package/types/dist/lib/handlers/api-manager.d.mts +392 -0
  72. package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
  73. package/types/dist/lib/handlers/context-async.d.mts +66 -0
  74. package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
  75. package/types/dist/lib/handlers/context-live.d.mts +65 -0
  76. package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
  77. package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
  78. package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
  79. package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
  80. package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
  81. package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
  82. package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
  83. package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
  84. package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
  85. package/types/dist/lib/handlers/metadata.d.mts +215 -0
  86. package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
  87. package/types/dist/lib/handlers/ownership.d.mts +170 -0
  88. package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
  89. package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
  90. package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
  91. package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
  92. package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
  93. package/types/dist/lib/helpers/config.d.mts +96 -0
  94. package/types/dist/lib/helpers/config.d.mts.map +1 -0
  95. package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
  96. package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
  97. package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
  98. package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
  99. package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
  100. package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
  101. package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
  102. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
  103. package/types/dist/lib/helpers/sanitize.d.mts +95 -94
  104. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
  105. package/types/dist/lib/helpers/utilities.d.mts +53 -116
  106. package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
  107. package/types/dist/lib/i18n/translations.d.mts +39 -0
  108. package/types/dist/lib/i18n/translations.d.mts.map +1 -0
  109. package/types/dist/lib/modes/eager.d.mts +36 -0
  110. package/types/dist/lib/modes/eager.d.mts.map +1 -0
  111. package/types/dist/lib/modes/lazy.d.mts +49 -0
  112. package/types/dist/lib/modes/lazy.d.mts.map +1 -0
  113. package/types/dist/lib/processors/flatten.d.mts +114 -0
  114. package/types/dist/lib/processors/flatten.d.mts.map +1 -0
  115. package/types/dist/lib/processors/loader.d.mts +47 -0
  116. package/types/dist/lib/processors/loader.d.mts.map +1 -0
  117. package/types/dist/lib/processors/type-generator.d.mts +19 -0
  118. package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
  119. package/types/dist/lib/processors/typescript.d.mts +55 -0
  120. package/types/dist/lib/processors/typescript.d.mts.map +1 -0
  121. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
  122. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  123. package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
  124. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  125. package/types/dist/lib/runtime/runtime.d.mts +39 -9
  126. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  127. package/types/dist/slothlet.d.mts +184 -111
  128. package/types/dist/slothlet.d.mts.map +1 -1
  129. package/types/index.d.mts +1 -3
  130. package/dist/lib/engine/README.md +0 -21
  131. package/dist/lib/engine/slothlet_child.mjs +0 -59
  132. package/dist/lib/engine/slothlet_engine.mjs +0 -372
  133. package/dist/lib/engine/slothlet_esm.mjs +0 -230
  134. package/dist/lib/engine/slothlet_helpers.mjs +0 -455
  135. package/dist/lib/engine/slothlet_worker.mjs +0 -149
  136. package/dist/lib/helpers/als-eventemitter.mjs +0 -256
  137. package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
  138. package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
  139. package/dist/lib/helpers/api_builder/construction.mjs +0 -495
  140. package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
  141. package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
  142. package/dist/lib/helpers/api_builder.mjs +0 -41
  143. package/dist/lib/helpers/auto-wrap.mjs +0 -62
  144. package/dist/lib/helpers/hooks.mjs +0 -389
  145. package/dist/lib/helpers/instance-manager.mjs +0 -111
  146. package/dist/lib/helpers/metadata-api.mjs +0 -201
  147. package/dist/lib/helpers/multidefault.mjs +0 -216
  148. package/dist/lib/modes/slothlet_eager.mjs +0 -154
  149. package/dist/lib/modes/slothlet_lazy.mjs +0 -594
  150. package/docs/API-RULES-CONDITIONS.md +0 -712
  151. package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
  152. package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
  153. package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
  154. package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
  155. package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
  156. package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
  157. package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
  158. package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
  159. package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
  160. package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
  161. package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
  162. package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
  163. package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
  164. package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
  165. package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
  166. package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
  167. package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
  168. package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
  169. package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
  170. package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
  171. package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
  172. package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
  173. package/types/dist/lib/helpers/api_builder.d.mts +0 -6
  174. package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
  175. package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
  176. package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
  177. package/types/dist/lib/helpers/hooks.d.mts +0 -342
  178. package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
  179. package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
  180. package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
  181. package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
  182. package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
  183. package/types/dist/lib/helpers/multidefault.d.mts +0 -90
  184. package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
  185. package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
  186. package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
  187. package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
  188. package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
  189. package/types/index.d.mts.map +0 -1
@@ -14,165 +14,42 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- 
18
17
 
19
18
 
20
19
 
21
- import { AsyncLocalStorage } from "node:async_hooks";
22
- import {
23
- detectCurrentInstanceId,
24
- getInstanceData,
25
- setActiveInstance,
26
- getCurrentActiveInstanceId
27
- } from "@cldmv/slothlet/helpers/instance-manager";
28
- import { metadataAPI } from "@cldmv/slothlet/helpers/metadata-api";
29
20
 
30
-
31
- export const requestALS = new AsyncLocalStorage();
32
-
33
-
34
- function getCurrentInstanceContext() {
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
- const instanceId = detectCurrentInstanceId();
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
- if (instanceId) {
61
- const instanceData = getInstanceData(instanceId);
62
- if (instanceData) {
63
- return instanceData;
64
- }
65
- }
66
-
67
-
68
-
69
-
70
- return null;
71
- }
21
+ import { liveRuntime } from "@cldmv/slothlet/factories/context";
22
+ import { SlothletError } from "@cldmv/slothlet/errors";
72
23
 
73
24
 
74
25
  export const self = new Proxy(
75
26
  {},
76
27
  {
77
- get(target, prop) {
78
- const ctx = getCurrentInstanceContext();
79
- if (ctx && ctx.self) {
80
- return ctx.self[prop];
81
- }
82
- return undefined;
83
- },
84
-
85
- set(target, prop, value) {
86
- const ctx = getCurrentInstanceContext();
87
- if (ctx && ctx.self) {
88
- ctx.self[prop] = value;
89
- return true;
28
+ get(_, prop) {
29
+ const ctx = liveRuntime.getContext();
30
+ if (!ctx || !ctx.self) {
31
+ throw new SlothletError("RUNTIME_NO_ACTIVE_CONTEXT_SELF", {}, null, { validationError: true });
90
32
  }
91
- return false;
33
+ return ctx.self[prop];
92
34
  },
93
-
94
- ownKeys(_) {
95
-
96
-
97
-
98
-
99
- const ctx = getCurrentInstanceContext();
100
- if (ctx && ctx.self) {
101
- return Reflect.ownKeys(ctx.self);
102
- }
103
- return [];
35
+ ownKeys() {
36
+ const ctx = liveRuntime.getContext();
37
+ if (!ctx || !ctx.self) return [];
38
+ return Reflect.ownKeys(ctx.self);
104
39
  },
105
-
106
- has(target, prop) {
107
- const ctx = getCurrentInstanceContext();
108
- if (ctx && ctx.self) {
109
- return prop in ctx.self;
110
- }
111
- return false;
40
+ has(_, prop) {
41
+ const ctx = liveRuntime.getContext();
42
+ if (!ctx || !ctx.self) return false;
43
+ return prop in ctx.self;
112
44
  },
113
-
114
- getOwnPropertyDescriptor(target, prop) {
115
- const ctx = getCurrentInstanceContext();
116
- if (ctx && ctx.self) {
117
- return Reflect.getOwnPropertyDescriptor(ctx.self, prop);
118
- }
119
- return undefined;
120
- }
121
- }
122
- );
123
-
124
-
125
- export const context = new Proxy(
126
- {},
127
- {
128
- get(target, prop) {
129
- const ctx = getCurrentInstanceContext();
130
- const baseContext = ctx?.context || {};
131
- const requestContext = requestALS.getStore() || {};
132
-
133
-
45
+ getOwnPropertyDescriptor(_, prop) {
46
+ const ctx = liveRuntime.getContext();
47
+ if (!ctx || !ctx.self) return undefined;
48
+ const desc = Reflect.getOwnPropertyDescriptor(ctx.self, prop);
134
49
 
135
- const isDeepMerge = ctx?.config?.scope?.merge === "deep";
136
-
137
- if (isDeepMerge && Object.keys(requestContext).length > 0) {
138
-
139
- return requestContext[prop];
140
- }
141
-
142
50
 
143
- const merged = { ...baseContext, ...requestContext };
144
- return merged[prop];
145
- },
146
-
147
- set(target, prop, value) {
148
- const ctx = getCurrentInstanceContext();
149
- if (ctx && ctx.context) {
150
- ctx.context[prop] = value;
151
- return true;
152
- }
153
- return false;
154
- },
155
-
156
- ownKeys(_) {
157
- const ctx = getCurrentInstanceContext();
158
- if (ctx && ctx.context) {
159
- return Reflect.ownKeys(ctx.context);
160
- }
161
- return [];
162
- },
163
-
164
- has(target, prop) {
165
- const ctx = getCurrentInstanceContext();
166
- if (ctx && ctx.context) {
167
- return prop in ctx.context;
168
- }
169
- return false;
170
- },
171
-
172
- getOwnPropertyDescriptor(target, prop) {
173
- const ctx = getCurrentInstanceContext();
174
- if (ctx && ctx.context) {
175
- return Reflect.getOwnPropertyDescriptor(ctx.context, prop);
51
+ if (desc) {
52
+ return { ...desc, configurable: true };
176
53
  }
177
54
  return undefined;
178
55
  }
@@ -180,260 +57,38 @@ export const context = new Proxy(
180
57
  );
181
58
 
182
59
 
183
- export const reference = new Proxy(
60
+ export const context = new Proxy(
184
61
  {},
185
62
  {
186
- get(target, prop) {
187
- const ctx = getCurrentInstanceContext();
188
- if (ctx && ctx.reference) {
189
- return ctx.reference[prop];
190
- }
191
- return undefined;
192
- },
193
-
194
- set(target, prop, value) {
195
- const ctx = getCurrentInstanceContext();
196
- if (ctx && ctx.reference) {
197
- ctx.reference[prop] = value;
198
- return true;
199
- }
200
- return false;
201
- },
202
-
203
- ownKeys(_) {
204
- const ctx = getCurrentInstanceContext();
205
- if (ctx && ctx.reference) {
206
- return Reflect.ownKeys(ctx.reference);
63
+ get(_, prop) {
64
+ const ctx = liveRuntime.getContext();
65
+ if (!ctx || !ctx.context) {
66
+ return undefined;
207
67
  }
208
- return [];
68
+ return ctx.context[prop];
209
69
  },
210
-
211
- has(target, prop) {
212
- const ctx = getCurrentInstanceContext();
213
- if (ctx && ctx.reference) {
214
- return prop in ctx.reference;
215
- }
216
- return false;
217
- },
218
-
219
- getOwnPropertyDescriptor(target, prop) {
220
- const ctx = getCurrentInstanceContext();
221
- if (ctx && ctx.reference) {
222
- return Reflect.getOwnPropertyDescriptor(ctx.reference, prop);
223
- }
224
- return undefined;
225
- }
226
- }
227
- );
228
-
229
-
230
- export const instanceId = new Proxy(
231
- {},
232
- {
233
- get(target, prop) {
234
- if (prop === "valueOf" || prop === "toString" || prop === Symbol.toPrimitive) {
235
- const currentId = detectCurrentInstanceId();
236
- return () => currentId || "unknown";
70
+ set(_, prop, value) {
71
+ const ctx = liveRuntime.getContext();
72
+ if (!ctx || !ctx.context) {
73
+ throw new SlothletError("RUNTIME_NO_ACTIVE_CONTEXT_CONTEXT", {}, null, { validationError: true });
237
74
  }
238
- return detectCurrentInstanceId() || "unknown";
75
+ ctx.context[prop] = value;
76
+ return true;
239
77
  },
240
-
241
- ownKeys(_) {
242
- return ["valueOf", "toString"];
78
+ ownKeys() {
79
+ const ctx = liveRuntime.getContext();
80
+ if (!ctx || !ctx.context) return [];
81
+ return Reflect.ownKeys(ctx.context);
243
82
  },
244
-
245
- has(target, prop) {
246
- return prop === "valueOf" || prop === "toString" || prop === Symbol.toPrimitive;
83
+ has(_, prop) {
84
+ const ctx = liveRuntime.getContext();
85
+ if (!ctx || !ctx.context) return false;
86
+ return prop in ctx.context;
247
87
  },
248
-
249
- getOwnPropertyDescriptor(target, prop) {
250
- if (prop === "valueOf" || prop === "toString" || prop === Symbol.toPrimitive) {
251
- return {
252
- configurable: true,
253
- enumerable: false,
254
- writable: false,
255
- value: () => detectCurrentInstanceId() || "unknown"
256
- };
257
- }
258
- return undefined;
88
+ getOwnPropertyDescriptor(_, prop) {
89
+ const ctx = liveRuntime.getContext();
90
+ if (!ctx || !ctx.context) return undefined;
91
+ return Reflect.getOwnPropertyDescriptor(ctx.context, prop);
259
92
  }
260
93
  }
261
94
  );
262
-
263
-
264
- export function runWithCtx(ctx, fn, thisArg, args) {
265
-
266
- const previousActiveInstance = getCurrentActiveInstanceId();
267
-
268
-
269
- if (ctx && ctx.instanceId) {
270
- setActiveInstance(ctx.instanceId);
271
- }
272
-
273
- try {
274
-
275
- if (!ctx.hookManager?.enabled || !fn.__slothletPath) {
276
- return Reflect.apply(fn, thisArg, args);
277
- }
278
-
279
-
280
- const path = fn.__slothletPath;
281
-
282
- try {
283
-
284
- const beforeResult = ctx.hookManager.executeBeforeHooks(path, args);
285
-
286
-
287
- if (beforeResult.cancelled) {
288
- ctx.hookManager.executeAlwaysHooks(path, beforeResult.value, []);
289
- return beforeResult.value;
290
- }
291
-
292
-
293
- const actualArgs = beforeResult.args;
294
-
295
-
296
- const result = Reflect.apply(fn, thisArg, actualArgs);
297
-
298
-
299
- if (result && typeof result === "object" && typeof result.then === "function") {
300
- return result.then(
301
- (resolvedResult) => {
302
-
303
- const finalResult = ctx.hookManager.executeAfterHooks(path, resolvedResult);
304
- ctx.hookManager.executeAlwaysHooks(path, finalResult, []);
305
- return finalResult;
306
- },
307
- (error) => {
308
-
309
- if (!ctx.hookManager.reportedErrors.has(error)) {
310
- ctx.hookManager.reportedErrors.add(error);
311
- ctx.hookManager.executeErrorHooks(path, error, { type: "function" });
312
- }
313
-
314
- ctx.hookManager.executeAlwaysHooks(path, undefined, [error]);
315
-
316
- if (!ctx.hookManager.suppressErrors) {
317
- throw error;
318
- }
319
- return undefined;
320
- }
321
- );
322
- }
323
-
324
-
325
- const finalResult = ctx.hookManager.executeAfterHooks(path, result);
326
- ctx.hookManager.executeAlwaysHooks(path, finalResult, []);
327
- return finalResult;
328
- } catch (error) {
329
-
330
- if (!ctx.hookManager.reportedErrors.has(error)) {
331
- ctx.hookManager.reportedErrors.add(error);
332
- ctx.hookManager.executeErrorHooks(path, error, { type: "function" });
333
- }
334
-
335
- ctx.hookManager.executeAlwaysHooks(path, undefined, [error]);
336
-
337
- if (!ctx.hookManager.suppressErrors) {
338
- throw error;
339
- }
340
- return undefined;
341
- }
342
- } finally {
343
-
344
- setActiveInstance(previousActiveInstance);
345
- }
346
- }
347
-
348
-
349
- export function makeWrapper(ctx) {
350
- const cache = new WeakMap();
351
-
352
- return function wrapperFunction(obj, currentPath = "") {
353
- if (obj == null || (typeof obj !== "object" && typeof obj !== "function")) {
354
- return obj;
355
- }
356
-
357
-
358
- if (cache.has(obj)) {
359
- return cache.get(obj);
360
- }
361
-
362
- const proxied = new Proxy(obj, {
363
- apply(target, thisArg, args) {
364
-
365
- return runWithCtx(ctx, target, thisArg, args);
366
- },
367
- get(target, prop, receiver) {
368
- const value = Reflect.get(target, prop, receiver);
369
-
370
-
371
- const newPath = currentPath ? `${currentPath}.${String(prop)}` : String(prop);
372
-
373
-
374
- const isInternalProperty = currentPath === "" && ["hooks", "__ctx", "shutdown", "_impl"].includes(String(prop));
375
- const isInternalPath =
376
- newPath === "hooks" ||
377
- newPath.startsWith("hooks.") ||
378
- newPath === "__ctx" ||
379
- newPath.startsWith("__ctx.") ||
380
- newPath === "shutdown" ||
381
- newPath.startsWith("shutdown.") ||
382
- newPath === "_impl" ||
383
- newPath.startsWith("_impl.");
384
-
385
-
386
- if (typeof value === "function" && !value.__slothletPath && !isInternalProperty && !isInternalPath) {
387
- try {
388
- Object.defineProperty(value, "__slothletPath", {
389
- value: newPath,
390
- writable: false,
391
- enumerable: false,
392
- configurable: true
393
- });
394
- } catch {
395
-
396
- }
397
- }
398
-
399
-
400
- if ((typeof value === "function" || (value && typeof value === "object")) && !isInternalPath) {
401
- return wrapperFunction(value, newPath);
402
- }
403
-
404
- return value;
405
- }
406
- });
407
-
408
- cache.set(obj, proxied);
409
- return proxied;
410
- };
411
- }
412
-
413
-
414
-
415
-
416
-
417
- export function getContext() {
418
- return getCurrentInstanceContext();
419
- }
420
-
421
- export function setContext(newContext) {
422
-
423
-
424
- const ctx = getCurrentInstanceContext();
425
- if (ctx) {
426
-
427
- Object.assign(ctx, newContext);
428
- }
429
-
430
- }
431
-
432
- export const contextManager = {
433
- get: getContext,
434
- set: setContext,
435
- runWithCtx
436
- };
437
-
438
-
439
- export { metadataAPI };