@cldmv/slothlet 2.11.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.
- package/AGENT-USAGE.md +355 -325
- package/README.md +554 -238
- package/dist/lib/builders/api-assignment.mjs +605 -0
- package/dist/lib/builders/api_builder.mjs +1073 -0
- package/dist/lib/builders/builder.mjs +94 -0
- package/dist/lib/builders/modes-processor.mjs +1816 -0
- package/dist/lib/errors.mjs +227 -0
- package/dist/lib/factories/component-base.mjs +96 -0
- package/dist/lib/factories/context.mjs +38 -0
- package/dist/lib/handlers/api-cache-manager.mjs +216 -0
- package/dist/lib/handlers/api-manager.mjs +2364 -0
- package/dist/lib/handlers/context-async.mjs +184 -0
- package/dist/lib/handlers/context-live.mjs +184 -0
- package/dist/lib/handlers/hook-manager.mjs +789 -0
- package/dist/lib/handlers/lifecycle-token.mjs +44 -0
- package/dist/lib/handlers/lifecycle.mjs +131 -0
- package/dist/lib/handlers/materialize-manager.mjs +64 -0
- package/dist/lib/handlers/metadata.mjs +500 -0
- package/dist/lib/handlers/ownership.mjs +338 -0
- package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
- package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
- package/dist/lib/helpers/config.mjs +343 -0
- package/dist/lib/helpers/eventemitter-context.mjs +365 -0
- package/dist/lib/helpers/hint-detector.mjs +63 -0
- package/dist/lib/helpers/modes-utils.mjs +53 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +119 -116
- package/dist/lib/helpers/sanitize.mjs +247 -168
- package/dist/lib/helpers/utilities.mjs +46 -81
- package/dist/lib/i18n/languages/de-de.json +377 -0
- package/dist/lib/i18n/languages/en-gb.json +377 -0
- package/dist/lib/i18n/languages/en-us.json +377 -0
- package/dist/lib/i18n/languages/es-mx.json +377 -0
- package/dist/lib/i18n/languages/fr-fr.json +377 -0
- package/dist/lib/i18n/languages/hi-in.json +377 -0
- package/dist/lib/i18n/languages/ja-jp.json +377 -0
- package/dist/lib/i18n/languages/ko-kr.json +377 -0
- package/dist/lib/i18n/languages/pt-br.json +377 -0
- package/dist/lib/i18n/languages/ru-ru.json +377 -0
- package/dist/lib/i18n/languages/zh-cn.json +377 -0
- package/dist/lib/i18n/translations.mjs +140 -0
- package/dist/lib/modes/eager.mjs +75 -0
- package/dist/lib/modes/lazy.mjs +97 -0
- package/dist/lib/processors/flatten.mjs +453 -0
- package/dist/lib/processors/loader.mjs +355 -0
- package/dist/lib/processors/type-generator.mjs +291 -0
- package/dist/lib/processors/typescript.mjs +188 -0
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
- package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
- package/dist/lib/runtime/runtime.mjs +39 -159
- package/dist/slothlet.mjs +525 -744
- package/docs/API-RULES.md +338 -486
- package/index.cjs +4 -4
- package/index.mjs +82 -45
- package/package.json +138 -25
- package/types/dist/lib/builders/api-assignment.d.mts +97 -0
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
- package/types/dist/lib/builders/api_builder.d.mts +96 -0
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
- package/types/dist/lib/builders/builder.d.mts +60 -0
- package/types/dist/lib/builders/builder.d.mts.map +1 -0
- package/types/dist/lib/builders/modes-processor.d.mts +32 -0
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
- package/types/dist/lib/errors.d.mts +118 -0
- package/types/dist/lib/errors.d.mts.map +1 -0
- package/types/dist/lib/factories/component-base.d.mts +182 -0
- package/types/dist/lib/factories/component-base.d.mts.map +1 -0
- package/types/dist/lib/factories/context.d.mts +26 -0
- package/types/dist/lib/factories/context.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-manager.d.mts +392 -0
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-async.d.mts +66 -0
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-live.d.mts +65 -0
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
- package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/metadata.d.mts +215 -0
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
- package/types/dist/lib/handlers/ownership.d.mts +170 -0
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/config.d.mts +96 -0
- package/types/dist/lib/helpers/config.d.mts.map +1 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
- package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
- package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +95 -94
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +53 -116
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +39 -0
- package/types/dist/lib/i18n/translations.d.mts.map +1 -0
- package/types/dist/lib/modes/eager.d.mts +36 -0
- package/types/dist/lib/modes/eager.d.mts.map +1 -0
- package/types/dist/lib/modes/lazy.d.mts +49 -0
- package/types/dist/lib/modes/lazy.d.mts.map +1 -0
- package/types/dist/lib/processors/flatten.d.mts +114 -0
- package/types/dist/lib/processors/flatten.d.mts.map +1 -0
- package/types/dist/lib/processors/loader.d.mts +47 -0
- package/types/dist/lib/processors/loader.d.mts.map +1 -0
- package/types/dist/lib/processors/type-generator.d.mts +19 -0
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
- package/types/dist/lib/processors/typescript.d.mts +55 -0
- package/types/dist/lib/processors/typescript.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +39 -9
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +184 -111
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +1 -3
- package/dist/lib/engine/README.md +0 -21
- package/dist/lib/engine/slothlet_child.mjs +0 -59
- package/dist/lib/engine/slothlet_engine.mjs +0 -372
- package/dist/lib/engine/slothlet_esm.mjs +0 -230
- package/dist/lib/engine/slothlet_helpers.mjs +0 -455
- package/dist/lib/engine/slothlet_worker.mjs +0 -149
- package/dist/lib/helpers/als-eventemitter.mjs +0 -256
- package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
- package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
- package/dist/lib/helpers/api_builder/construction.mjs +0 -495
- package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
- package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
- package/dist/lib/helpers/api_builder.mjs +0 -41
- package/dist/lib/helpers/auto-wrap.mjs +0 -62
- package/dist/lib/helpers/hooks.mjs +0 -389
- package/dist/lib/helpers/instance-manager.mjs +0 -111
- package/dist/lib/helpers/metadata-api.mjs +0 -201
- package/dist/lib/helpers/multidefault.mjs +0 -216
- package/dist/lib/modes/slothlet_eager.mjs +0 -154
- package/dist/lib/modes/slothlet_lazy.mjs +0 -594
- package/docs/API-RULES-CONDITIONS.md +0 -712
- package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
- package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
- package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
- package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
- package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
- package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
- package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
- package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
- package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder.d.mts +0 -6
- package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
- package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
- package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
- package/types/dist/lib/helpers/hooks.d.mts +0 -342
- package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
- package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
- package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
- package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
- package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
- package/types/dist/lib/helpers/multidefault.d.mts +0 -90
- package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
- package/types/index.d.mts.map +0 -1
|
@@ -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
|
-
|
|
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(
|
|
78
|
-
const ctx =
|
|
79
|
-
if (ctx
|
|
80
|
-
|
|
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
|
|
33
|
+
return ctx.self[prop];
|
|
92
34
|
},
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
|
60
|
+
export const context = new Proxy(
|
|
184
61
|
{},
|
|
185
62
|
{
|
|
186
|
-
get(
|
|
187
|
-
const ctx =
|
|
188
|
-
if (ctx
|
|
189
|
-
return
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
75
|
+
ctx.context[prop] = value;
|
|
76
|
+
return true;
|
|
239
77
|
},
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return [
|
|
78
|
+
ownKeys() {
|
|
79
|
+
const ctx = liveRuntime.getContext();
|
|
80
|
+
if (!ctx || !ctx.context) return [];
|
|
81
|
+
return Reflect.ownKeys(ctx.context);
|
|
243
82
|
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
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 };
|