@cldmv/slothlet 3.2.3 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +22 -9
  2. package/REFERENCE.md +23 -0
  3. package/dist/lib/builders/api-assignment.mjs +1 -589
  4. package/dist/lib/builders/api_builder.mjs +1 -1155
  5. package/dist/lib/builders/builder.mjs +1 -78
  6. package/dist/lib/builders/modes-processor.mjs +1 -1800
  7. package/dist/lib/errors.mjs +9 -211
  8. package/dist/lib/factories/component-base.mjs +1 -80
  9. package/dist/lib/factories/context.mjs +1 -22
  10. package/dist/lib/handlers/api-cache-manager.mjs +1 -200
  11. package/dist/lib/handlers/api-manager.mjs +1 -2513
  12. package/dist/lib/handlers/context-async.mjs +1 -168
  13. package/dist/lib/handlers/context-live.mjs +1 -168
  14. package/dist/lib/handlers/hook-manager.mjs +1 -773
  15. package/dist/lib/handlers/lifecycle-token.mjs +1 -28
  16. package/dist/lib/handlers/lifecycle.mjs +1 -115
  17. package/dist/lib/handlers/materialize-manager.mjs +1 -48
  18. package/dist/lib/handlers/metadata.mjs +1 -501
  19. package/dist/lib/handlers/ownership.mjs +1 -322
  20. package/dist/lib/handlers/permission-manager.mjs +17 -0
  21. package/dist/lib/handlers/unified-wrapper.mjs +1 -3042
  22. package/dist/lib/handlers/version-manager.mjs +1 -885
  23. package/dist/lib/helpers/class-instance-wrapper.mjs +1 -109
  24. package/dist/lib/helpers/config.mjs +1 -355
  25. package/dist/lib/helpers/eventemitter-context.mjs +1 -349
  26. package/dist/lib/helpers/hint-detector.mjs +1 -47
  27. package/dist/lib/helpers/modes-utils.mjs +1 -37
  28. package/dist/lib/helpers/pattern-matcher.mjs +17 -0
  29. package/dist/lib/helpers/resolve-from-caller.mjs +1 -169
  30. package/dist/lib/helpers/sanitize.mjs +1 -340
  31. package/dist/lib/helpers/utilities.mjs +1 -70
  32. package/dist/lib/i18n/languages/de-de.json +21 -1
  33. package/dist/lib/i18n/languages/en-gb.json +21 -1
  34. package/dist/lib/i18n/languages/en-us.json +21 -1
  35. package/dist/lib/i18n/languages/es-mx.json +21 -1
  36. package/dist/lib/i18n/languages/fr-fr.json +21 -1
  37. package/dist/lib/i18n/languages/hi-in.json +21 -1
  38. package/dist/lib/i18n/languages/ja-jp.json +21 -1
  39. package/dist/lib/i18n/languages/ko-kr.json +21 -1
  40. package/dist/lib/i18n/languages/pt-br.json +21 -1
  41. package/dist/lib/i18n/languages/ru-ru.json +21 -1
  42. package/dist/lib/i18n/languages/zh-cn.json +21 -1
  43. package/dist/lib/i18n/translations.mjs +1 -126
  44. package/dist/lib/modes/eager.mjs +1 -59
  45. package/dist/lib/modes/lazy.mjs +1 -81
  46. package/dist/lib/processors/flatten.mjs +1 -437
  47. package/dist/lib/processors/loader.mjs +1 -339
  48. package/dist/lib/processors/type-generator.mjs +1 -275
  49. package/dist/lib/processors/typescript.mjs +1 -172
  50. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +1 -113
  51. package/dist/lib/runtime/runtime-livebindings.mjs +1 -78
  52. package/dist/lib/runtime/runtime.mjs +1 -102
  53. package/dist/slothlet.mjs +1 -808
  54. package/package.json +37 -31
  55. package/types/dist/lib/builders/api-assignment.d.mts +3 -92
  56. package/types/dist/lib/builders/api-assignment.d.mts.map +1 -1
  57. package/types/dist/lib/builders/api_builder.d.mts +102 -91
  58. package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
  59. package/types/dist/lib/builders/builder.d.mts +1 -55
  60. package/types/dist/lib/builders/builder.d.mts.map +1 -1
  61. package/types/dist/lib/builders/modes-processor.d.mts +3 -27
  62. package/types/dist/lib/builders/modes-processor.d.mts.map +1 -1
  63. package/types/dist/lib/errors.d.mts +19 -109
  64. package/types/dist/lib/errors.d.mts.map +1 -1
  65. package/types/dist/lib/factories/component-base.d.mts +7 -177
  66. package/types/dist/lib/factories/component-base.d.mts.map +1 -1
  67. package/types/dist/lib/factories/context.d.mts +4 -22
  68. package/types/dist/lib/factories/context.d.mts.map +1 -1
  69. package/types/dist/lib/handlers/api-cache-manager.d.mts +20 -203
  70. package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -1
  71. package/types/dist/lib/handlers/api-manager.d.mts +33 -408
  72. package/types/dist/lib/handlers/api-manager.d.mts.map +1 -1
  73. package/types/dist/lib/handlers/context-async.d.mts +23 -61
  74. package/types/dist/lib/handlers/context-async.d.mts.map +1 -1
  75. package/types/dist/lib/handlers/context-live.d.mts +22 -59
  76. package/types/dist/lib/handlers/context-live.d.mts.map +1 -1
  77. package/types/dist/lib/handlers/hook-manager.d.mts +46 -185
  78. package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -1
  79. package/types/dist/lib/handlers/lifecycle-token.d.mts +3 -48
  80. package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -1
  81. package/types/dist/lib/handlers/lifecycle.d.mts +5 -82
  82. package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -1
  83. package/types/dist/lib/handlers/materialize-manager.d.mts +8 -70
  84. package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -1
  85. package/types/dist/lib/handlers/metadata.d.mts +17 -221
  86. package/types/dist/lib/handlers/metadata.d.mts.map +1 -1
  87. package/types/dist/lib/handlers/ownership.d.mts +44 -160
  88. package/types/dist/lib/handlers/ownership.d.mts.map +1 -1
  89. package/types/dist/lib/handlers/permission-manager.d.mts +47 -0
  90. package/types/dist/lib/handlers/permission-manager.d.mts.map +1 -0
  91. package/types/dist/lib/handlers/unified-wrapper.d.mts +26 -239
  92. package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -1
  93. package/types/dist/lib/handlers/version-manager.d.mts +28 -225
  94. package/types/dist/lib/handlers/version-manager.d.mts.map +1 -1
  95. package/types/dist/lib/helpers/class-instance-wrapper.d.mts +2 -52
  96. package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -1
  97. package/types/dist/lib/helpers/config.d.mts +125 -123
  98. package/types/dist/lib/helpers/config.d.mts.map +1 -1
  99. package/types/dist/lib/helpers/eventemitter-context.d.mts +3 -29
  100. package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -1
  101. package/types/dist/lib/helpers/hint-detector.d.mts +2 -15
  102. package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -1
  103. package/types/dist/lib/helpers/modes-utils.d.mts +3 -30
  104. package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -1
  105. package/types/dist/lib/helpers/pattern-matcher.d.mts +4 -0
  106. package/types/dist/lib/helpers/pattern-matcher.d.mts.map +1 -0
  107. package/types/dist/lib/helpers/resolve-from-caller.d.mts +3 -27
  108. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
  109. package/types/dist/lib/helpers/sanitize.d.mts +4 -92
  110. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
  111. package/types/dist/lib/helpers/utilities.d.mts +4 -52
  112. package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
  113. package/types/dist/lib/i18n/translations.d.mts +4 -37
  114. package/types/dist/lib/i18n/translations.d.mts.map +1 -1
  115. package/types/dist/lib/modes/eager.d.mts +8 -30
  116. package/types/dist/lib/modes/eager.d.mts.map +1 -1
  117. package/types/dist/lib/modes/lazy.d.mts +10 -43
  118. package/types/dist/lib/modes/lazy.d.mts.map +1 -1
  119. package/types/dist/lib/processors/flatten.d.mts +56 -107
  120. package/types/dist/lib/processors/flatten.d.mts.map +1 -1
  121. package/types/dist/lib/processors/loader.d.mts +6 -41
  122. package/types/dist/lib/processors/loader.d.mts.map +1 -1
  123. package/types/dist/lib/processors/type-generator.d.mts +2 -16
  124. package/types/dist/lib/processors/type-generator.d.mts.map +1 -1
  125. package/types/dist/lib/processors/typescript.d.mts +6 -53
  126. package/types/dist/lib/processors/typescript.d.mts.map +1 -1
  127. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +3 -71
  128. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  129. package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -37
  130. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  131. package/types/dist/lib/runtime/runtime.d.mts +3 -39
  132. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  133. package/types/dist/slothlet.d.mts +3 -249
  134. package/types/dist/slothlet.d.mts.map +1 -1
  135. package/types/index.d.mts +36 -16
  136. package/types/index.d.mts.map +1 -0
  137. package/AGENT-USAGE.md +0 -736
  138. package/docs/API-RULES.md +0 -712
@@ -14,171 +14,4 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
-
18
-
19
-
20
- import { AsyncLocalStorage } from "node:async_hooks";
21
- import { SlothletError } from "@cldmv/slothlet/errors";
22
- import { runtime_isClassInstance, runtime_wrapClassInstance } from "@cldmv/slothlet/helpers/class-instance-wrapper";
23
- import { setApiContextChecker } from "@cldmv/slothlet/helpers/eventemitter-context";
24
-
25
-
26
- export class AsyncContextManager {
27
- constructor() {
28
- this.als = new AsyncLocalStorage();
29
- this.instances = new Map();
30
- }
31
-
32
-
33
- registerEventEmitterContextChecker() {
34
- setApiContextChecker(() => {
35
- const store = this.als.getStore();
36
- return store && store.instanceID ? true : false;
37
- });
38
- }
39
-
40
-
41
- initialize(instanceID, config = {}) {
42
- if (this.instances.has(instanceID)) {
43
- throw new SlothletError("CONTEXT_ALREADY_EXISTS", { instanceID }, null, { validationError: true });
44
- }
45
-
46
- const store = {
47
- instanceID,
48
- self: {},
49
- context: {},
50
- config: { ...config },
51
- createdAt: Date.now()
52
- };
53
-
54
- this.instances.set(instanceID, store);
55
- return store;
56
- }
57
-
58
-
59
- runInContext(instanceID, fn, thisArg, args, currentWrapper) {
60
-
61
- const activeStore = this.als.getStore();
62
- let baseStore;
63
-
64
-
65
- const isActiveOurInstance = activeStore && (activeStore.instanceID === instanceID || activeStore.parentInstanceID === instanceID);
66
-
67
- if (isActiveOurInstance) {
68
-
69
- baseStore = activeStore;
70
- } else {
71
-
72
- baseStore = this.instances.get(instanceID);
73
- if (!baseStore) {
74
- throw new SlothletError("CONTEXT_NOT_FOUND", {
75
- instanceID,
76
- availableInstances: Array.from(this.instances.keys())
77
- });
78
- }
79
- }
80
-
81
-
82
- const executionStore = { ...baseStore };
83
- if (currentWrapper) {
84
- executionStore.callerWrapper = baseStore.currentWrapper;
85
- executionStore.currentWrapper = currentWrapper;
86
- }
87
-
88
-
89
- if (isActiveOurInstance) {
90
-
91
- return this.als.run(executionStore, () => {
92
- try {
93
- const result = fn.apply(thisArg, args);
94
-
95
- if (runtime_isClassInstance(result)) {
96
- const instanceCache = new WeakMap();
97
- return runtime_wrapClassInstance(result, this, instanceID, instanceCache);
98
- }
99
- return result;
100
- } catch (error) {
101
- throw new SlothletError(
102
- "CONTEXT_EXECUTION_FAILED",
103
- {
104
- instanceID
105
- },
106
- error
107
- );
108
- }
109
- });
110
- }
111
-
112
-
113
- return this.als.run(executionStore, () => {
114
- try {
115
- const result = fn.apply(thisArg, args);
116
-
117
- if (runtime_isClassInstance(result)) {
118
- const instanceCache = new WeakMap();
119
- return runtime_wrapClassInstance(result, this, instanceID, instanceCache);
120
- }
121
- return result;
122
- } catch (error) {
123
- throw new SlothletError(
124
- "CONTEXT_EXECUTION_FAILED",
125
- {
126
- instanceID
127
- },
128
- error
129
- );
130
- }
131
- });
132
- }
133
-
134
-
135
- getContext() {
136
- const store = this.als.getStore();
137
- if (!store) {
138
- throw new SlothletError("NO_ACTIVE_CONTEXT_ASYNC", {}, null, { validationError: true });
139
- }
140
- return store;
141
- }
142
-
143
-
144
- tryGetContext() {
145
- return this.als.getStore();
146
- }
147
-
148
-
149
- cleanup(instanceID) {
150
- const store = this.instances.get(instanceID);
151
- if (!store) {
152
- throw new SlothletError(
153
- "CONTEXT_NOT_FOUND",
154
- { instanceID, availableInstances: Array.from(this.instances.keys()).join(", ") || "none" },
155
- null,
156
- { validationError: true }
157
- );
158
- }
159
-
160
-
161
- store.self = {};
162
- store.context = {};
163
-
164
-
165
- this.instances.delete(instanceID);
166
- }
167
-
168
-
169
- getDiagnostics() {
170
- return {
171
- type: "async",
172
- activeStore: this.als.getStore()?.instanceID || null,
173
- instances: Array.from(this.instances.entries()).map(([id, store]) => ({
174
- id,
175
- createdAt: store.createdAt,
176
- contextKeys: Object.keys(store.context),
177
- selfKeys: Object.keys(store.self)
178
- }))
179
- };
180
- }
181
- }
182
-
183
-
184
- export const asyncContextManager = new AsyncContextManager();
17
+ import{AsyncLocalStorage}from"node:async_hooks";import{SlothletError}from"@cldmv/slothlet/errors";import{runtime_isClassInstance,runtime_wrapClassInstance}from"@cldmv/slothlet/helpers/class-instance-wrapper";import{setApiContextChecker}from"@cldmv/slothlet/helpers/eventemitter-context";class AsyncContextManager{constructor(){this.als=new AsyncLocalStorage;this.instances=new Map}registerEventEmitterContextChecker(){setApiContextChecker(()=>{const store=this.als.getStore();return store&&store.instanceID?true:false})}initialize(instanceID,config={}){if(this.instances.has(instanceID)){throw new SlothletError("CONTEXT_ALREADY_EXISTS",{instanceID},null,{validationError:true})}const store={instanceID,self:{},context:{},config:{...config},createdAt:Date.now()};this.instances.set(instanceID,store);return store}runInContext(instanceID,fn,thisArg,args,currentWrapper){const activeStore=this.als.getStore();let baseStore;const isActiveOurInstance=activeStore&&(activeStore.instanceID===instanceID||activeStore.parentInstanceID===instanceID);if(isActiveOurInstance){baseStore=activeStore}else{baseStore=this.instances.get(instanceID);if(!baseStore){throw new SlothletError("CONTEXT_NOT_FOUND",{instanceID,availableInstances:Array.from(this.instances.keys())})}}const executionStore={...baseStore};if(currentWrapper){executionStore.callerWrapper=baseStore.currentWrapper;executionStore.currentWrapper=currentWrapper}if(isActiveOurInstance){return this.als.run(executionStore,()=>{try{const result=fn.apply(thisArg,args);if(runtime_isClassInstance(result)){const instanceCache=new WeakMap;return runtime_wrapClassInstance(result,this,instanceID,instanceCache)}return result}catch(error){if(error instanceof SlothletError)throw error;throw new SlothletError("CONTEXT_EXECUTION_FAILED",{instanceID},error)}})}return this.als.run(executionStore,()=>{try{const result=fn.apply(thisArg,args);if(runtime_isClassInstance(result)){const instanceCache=new WeakMap;return runtime_wrapClassInstance(result,this,instanceID,instanceCache)}return result}catch(error){if(error instanceof SlothletError)throw error;throw new SlothletError("CONTEXT_EXECUTION_FAILED",{instanceID},error)}})}getContext(){const store=this.als.getStore();if(!store){throw new SlothletError("NO_ACTIVE_CONTEXT_ASYNC",{},null,{validationError:true})}return store}tryGetContext(){return this.als.getStore()}cleanup(instanceID){const store=this.instances.get(instanceID);if(!store){throw new SlothletError("CONTEXT_NOT_FOUND",{instanceID,availableInstances:Array.from(this.instances.keys()).join(", ")||"none"},null,{validationError:true})}store.self={};store.context={};this.instances.delete(instanceID)}getDiagnostics(){return{type:"async",activeStore:this.als.getStore()?.instanceID||null,instances:Array.from(this.instances.entries()).map(([id,store])=>({id,createdAt:store.createdAt,contextKeys:Object.keys(store.context),selfKeys:Object.keys(store.self)}))}}}const asyncContextManager=new AsyncContextManager;export{AsyncContextManager,asyncContextManager};
@@ -14,171 +14,4 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
-
18
-
19
-
20
- import { SlothletError } from "@cldmv/slothlet/errors";
21
- import { setApiContextChecker } from "@cldmv/slothlet/helpers/eventemitter-context";
22
-
23
-
24
- export class LiveContextManager {
25
- constructor() {
26
- this.instances = new Map();
27
- this.currentInstanceID = null;
28
- }
29
-
30
-
31
- registerEventEmitterContextChecker() {
32
- setApiContextChecker(() => {
33
- return this.currentInstanceID !== null;
34
- });
35
- }
36
-
37
-
38
- initialize(instanceID, config = {}) {
39
- if (this.instances.has(instanceID)) {
40
- throw new SlothletError("CONTEXT_ALREADY_EXISTS", { instanceID }, null, { validationError: true });
41
- }
42
-
43
- const store = {
44
- instanceID,
45
- self: {},
46
- context: {},
47
- config: { ...config },
48
- createdAt: Date.now()
49
- };
50
-
51
- this.instances.set(instanceID, store);
52
-
53
-
54
- if (!this.currentInstanceID) {
55
- this.currentInstanceID = instanceID;
56
- }
57
-
58
- return store;
59
- }
60
-
61
-
62
- runInContext(instanceID, fn, thisArg, args, currentWrapper) {
63
-
64
- const currentID = this.currentInstanceID;
65
- let isAlreadyInContext = false;
66
-
67
- if (currentID) {
68
- const currentStore = this.instances.get(currentID);
69
- isAlreadyInContext =
70
- currentID === instanceID || currentStore?.parentInstanceID === instanceID || currentID.startsWith(instanceID + "__run_");
71
- }
72
-
73
-
74
- const targetInstanceID = isAlreadyInContext ? currentID : instanceID;
75
-
76
- const store = this.instances.get(targetInstanceID);
77
- if (!store) {
78
- throw new SlothletError("CONTEXT_NOT_FOUND", {
79
- instanceID: targetInstanceID,
80
- availableInstances: Array.from(this.instances.keys())
81
- });
82
- }
83
-
84
-
85
- const previousInstanceID = this.currentInstanceID;
86
- const previousWrapper = store.currentWrapper;
87
- const previousCallerWrapper = store.callerWrapper;
88
-
89
- this.currentInstanceID = targetInstanceID;
90
- if (currentWrapper) {
91
- store.callerWrapper = previousWrapper;
92
- store.currentWrapper = currentWrapper;
93
- }
94
-
95
- try {
96
- return fn.apply(thisArg, args);
97
- } catch (error) {
98
- throw new SlothletError(
99
- "CONTEXT_EXECUTION_FAILED",
100
- {
101
- instanceID
102
- },
103
- error
104
- );
105
- } finally {
106
-
107
- this.currentInstanceID = previousInstanceID;
108
- store.currentWrapper = previousWrapper;
109
- store.callerWrapper = previousCallerWrapper;
110
- }
111
- }
112
-
113
-
114
- getContext() {
115
- if (!this.currentInstanceID) {
116
- throw new SlothletError("NO_ACTIVE_CONTEXT_LIVE", {}, null, { validationError: true });
117
- }
118
-
119
- const store = this.instances.get(this.currentInstanceID);
120
- if (!store) {
121
- throw new SlothletError(
122
- "CONTEXT_NOT_FOUND",
123
- {
124
- instanceID: this.currentInstanceID,
125
- availableInstances: Array.from(this.instances.keys()).join(", ") || "none"
126
- },
127
- null,
128
- { validationError: true }
129
- );
130
- }
131
-
132
- return store;
133
- }
134
-
135
-
136
- tryGetContext() {
137
- if (!this.currentInstanceID) {
138
- return undefined;
139
- }
140
- return this.instances.get(this.currentInstanceID);
141
- }
142
-
143
-
144
- cleanup(instanceID) {
145
- const store = this.instances.get(instanceID);
146
- if (!store) {
147
- throw new SlothletError(
148
- "CONTEXT_NOT_FOUND",
149
- { instanceID, availableInstances: Array.from(this.instances.keys()).join(", ") || "none" },
150
- null,
151
- { validationError: true }
152
- );
153
- }
154
-
155
-
156
- store.self = {};
157
- store.context = {};
158
-
159
-
160
- this.instances.delete(instanceID);
161
-
162
-
163
- if (this.currentInstanceID === instanceID) {
164
- this.currentInstanceID = null;
165
- }
166
- }
167
-
168
-
169
- getDiagnostics() {
170
- return {
171
- type: "live",
172
- currentInstanceID: this.currentInstanceID,
173
- instances: Array.from(this.instances.entries()).map(([id, store]) => ({
174
- id,
175
- createdAt: store.createdAt,
176
- contextKeys: Object.keys(store.context),
177
- selfKeys: Object.keys(store.self)
178
- }))
179
- };
180
- }
181
- }
182
-
183
-
184
- export const liveContextManager = new LiveContextManager();
17
+ import{SlothletError}from"@cldmv/slothlet/errors";import{setApiContextChecker}from"@cldmv/slothlet/helpers/eventemitter-context";class LiveContextManager{constructor(){this.instances=new Map;this.currentInstanceID=null}registerEventEmitterContextChecker(){setApiContextChecker(()=>{return this.currentInstanceID!==null})}initialize(instanceID,config={}){if(this.instances.has(instanceID)){throw new SlothletError("CONTEXT_ALREADY_EXISTS",{instanceID},null,{validationError:true})}const store={instanceID,self:{},context:{},config:{...config},createdAt:Date.now()};this.instances.set(instanceID,store);if(!this.currentInstanceID){this.currentInstanceID=instanceID}return store}runInContext(instanceID,fn,thisArg,args,currentWrapper){const currentID=this.currentInstanceID;let isAlreadyInContext=false;if(currentID){const currentStore=this.instances.get(currentID);isAlreadyInContext=currentID===instanceID||currentStore?.parentInstanceID===instanceID||currentID.startsWith(instanceID+"__run_")}const targetInstanceID=isAlreadyInContext?currentID:instanceID;const store=this.instances.get(targetInstanceID);if(!store){throw new SlothletError("CONTEXT_NOT_FOUND",{instanceID:targetInstanceID,availableInstances:Array.from(this.instances.keys())})}const previousInstanceID=this.currentInstanceID;const previousWrapper=store.currentWrapper;const previousCallerWrapper=store.callerWrapper;this.currentInstanceID=targetInstanceID;if(currentWrapper){store.callerWrapper=previousWrapper;store.currentWrapper=currentWrapper}try{return fn.apply(thisArg,args)}catch(error){if(error instanceof SlothletError)throw error;throw new SlothletError("CONTEXT_EXECUTION_FAILED",{instanceID},error)}finally{this.currentInstanceID=previousInstanceID;store.currentWrapper=previousWrapper;store.callerWrapper=previousCallerWrapper}}getContext(){if(!this.currentInstanceID){throw new SlothletError("NO_ACTIVE_CONTEXT_LIVE",{},null,{validationError:true})}const store=this.instances.get(this.currentInstanceID);if(!store){throw new SlothletError("CONTEXT_NOT_FOUND",{instanceID:this.currentInstanceID,availableInstances:Array.from(this.instances.keys()).join(", ")||"none"},null,{validationError:true})}return store}tryGetContext(){if(!this.currentInstanceID){return void 0}return this.instances.get(this.currentInstanceID)}cleanup(instanceID){const store=this.instances.get(instanceID);if(!store){throw new SlothletError("CONTEXT_NOT_FOUND",{instanceID,availableInstances:Array.from(this.instances.keys()).join(", ")||"none"},null,{validationError:true})}store.self={};store.context={};this.instances.delete(instanceID);if(this.currentInstanceID===instanceID){this.currentInstanceID=null}}getDiagnostics(){return{type:"live",currentInstanceID:this.currentInstanceID,instances:Array.from(this.instances.entries()).map(([id,store])=>({id,createdAt:store.createdAt,contextKeys:Object.keys(store.context),selfKeys:Object.keys(store.self)}))}}}const liveContextManager=new LiveContextManager;export{LiveContextManager,liveContextManager};