@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.
- 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 +123 -117
- 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 +143 -30
- 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
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 CLDMV/Shinrai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { translate } from "@cldmv/slothlet/i18n";
|
|
21
|
+
import { detectHint } from "@cldmv/slothlet/helpers/hint-detector";
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export class SlothletError extends Error {
|
|
25
|
+
|
|
26
|
+
constructor(code, context = {}, originalError = null, options = {}) {
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const { validationError: ctxValidation, stub: ctxStub, ...contextData } = context;
|
|
30
|
+
const { validationError: optsValidation, stub: optsStub } = options;
|
|
31
|
+
const validationError = ctxValidation ?? optsValidation;
|
|
32
|
+
const stub = ctxStub ?? optsStub;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const enrichedContext = originalError ? { ...contextData, error: originalError.message } : contextData;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const translatedMessage = translate(code, enrichedContext);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const skipHint = stub || validationError;
|
|
42
|
+
const hintKey = originalError && !skipHint ? detectHint(originalError, code) : undefined;
|
|
43
|
+
let translatedHint = hintKey ? translate(hintKey, enrichedContext) : undefined;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (!translatedHint && validationError) {
|
|
51
|
+
const staticHintKey = `HINT_${code}`;
|
|
52
|
+
const staticHint = translate(staticHintKey, enrichedContext);
|
|
53
|
+
|
|
54
|
+
if (staticHint && !staticHint.startsWith("Error:")) {
|
|
55
|
+
translatedHint = staticHint;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const messageWithCode = `[${code}] ${translatedMessage}`;
|
|
61
|
+
super(messageWithCode);
|
|
62
|
+
this.name = "SlothletError";
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Object.defineProperty(this, "code", {
|
|
66
|
+
value: code,
|
|
67
|
+
enumerable: false,
|
|
68
|
+
writable: false
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
Object.defineProperty(this, "context", {
|
|
72
|
+
value: context,
|
|
73
|
+
enumerable: false,
|
|
74
|
+
writable: false
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Object.defineProperty(this, "originalError", {
|
|
78
|
+
value: originalError,
|
|
79
|
+
enumerable: false,
|
|
80
|
+
writable: false
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
Object.defineProperty(this, "hint", {
|
|
84
|
+
value: translatedHint,
|
|
85
|
+
enumerable: false,
|
|
86
|
+
writable: false
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
Error.captureStackTrace(this, SlothletError);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
toString() {
|
|
94
|
+
let output = `\n[${this.code}] ${this.name}\n`;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if (this.hint) {
|
|
98
|
+
output += `\n💡 ${this.hint}\n`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
const criticalKeys = ["modulePath", "moduleID", "apiPath"];
|
|
103
|
+
const detailKeys = Object.keys(this.context).filter((k) => criticalKeys.includes(k));
|
|
104
|
+
|
|
105
|
+
if (detailKeys.length > 0) {
|
|
106
|
+
output += "\nDetails:\n";
|
|
107
|
+
for (const key of detailKeys) {
|
|
108
|
+
output += ` ${key}: ${this.context[key]}\n`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return output;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
117
|
+
return this.toString() + `\n${this.stack}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
toJSON() {
|
|
122
|
+
return {
|
|
123
|
+
name: this.name,
|
|
124
|
+
code: this.code,
|
|
125
|
+
message: this.message,
|
|
126
|
+
hint: this.context.hint
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
export class SlothletWarning {
|
|
133
|
+
|
|
134
|
+
static captured = [];
|
|
135
|
+
static suppressConsole = false;
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
constructor(code, context = {}) {
|
|
139
|
+
|
|
140
|
+
const { key: msgKey, ...contextData } = context;
|
|
141
|
+
const translationKey = msgKey ?? code;
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const translatedMessage = translate(translationKey, contextData);
|
|
145
|
+
|
|
146
|
+
this.name = "SlothletWarning";
|
|
147
|
+
this.code = code;
|
|
148
|
+
this.message = translatedMessage;
|
|
149
|
+
this.context = context;
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if (!SlothletWarning.suppressConsole) {
|
|
153
|
+
console.warn(`\n⚠️ [${this.code}] ${this.name}\n${this.message}`);
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if (Object.keys(contextData).length > 0) {
|
|
157
|
+
console.warn("Context:", contextData);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
|
|
161
|
+
SlothletWarning.captured.push(this);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
toString() {
|
|
167
|
+
return `[${this.code}] ${this.name}: ${this.message}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
static clearCaptured() {
|
|
172
|
+
SlothletWarning.captured = [];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
export class SlothletDebug {
|
|
178
|
+
|
|
179
|
+
constructor(config = {}) {
|
|
180
|
+
this.config = config;
|
|
181
|
+
this.debugFlags = config.debug || {};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
log(code, context = {}) {
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if (!this.debugFlags || !this.debugFlags[code]) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
const { key: msgKey, message, ...contextParams } = context;
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
const translationKey = msgKey ?? `DEBUG_${code.toUpperCase()}`;
|
|
199
|
+
const translatedMessage = translate(translationKey, contextParams);
|
|
200
|
+
const hasTranslation = translatedMessage && !translatedMessage.startsWith("Error:");
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
const label = `[DEBUG:${code.toUpperCase()}]`;
|
|
204
|
+
|
|
205
|
+
if (hasTranslation) {
|
|
206
|
+
console.log(`${label} ${translatedMessage}`);
|
|
207
|
+
} else if (message) {
|
|
208
|
+
|
|
209
|
+
console.log(`${label} ${message}`);
|
|
210
|
+
} else {
|
|
211
|
+
|
|
212
|
+
console.log(label, contextParams);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
if ((hasTranslation || message) && Object.keys(contextParams).length > 0) {
|
|
217
|
+
console.log(`${label} Context:`, contextParams);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
toString() {
|
|
223
|
+
return `[SlothletDebug] flags: ${Object.keys(this.debugFlags)
|
|
224
|
+
.filter((k) => this.debugFlags[k])
|
|
225
|
+
.join(", ")}`;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
export class ComponentBase {
|
|
23
|
+
|
|
24
|
+
#slothlet;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
constructor(slothlet) {
|
|
28
|
+
this.#slothlet = slothlet;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
get ____slothlet() {
|
|
33
|
+
return this.#slothlet;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
get slothlet() {
|
|
38
|
+
return this.#slothlet;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
get ____config() {
|
|
43
|
+
return this.____slothlet.config;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
get instanceID() {
|
|
48
|
+
return this.____slothlet.instanceID;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get SlothletError() {
|
|
53
|
+
return this.____slothlet.SlothletError;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
get SlothletWarning() {
|
|
58
|
+
return this.____slothlet.SlothletWarning;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
static INTERNAL_KEYS = new Set([
|
|
63
|
+
|
|
64
|
+
"____slothletInternal",
|
|
65
|
+
"____slothlet",
|
|
66
|
+
|
|
67
|
+
"___getState",
|
|
68
|
+
"___setImpl",
|
|
69
|
+
"___resetLazy",
|
|
70
|
+
"___invalidate",
|
|
71
|
+
|
|
72
|
+
"__state",
|
|
73
|
+
"__invalid",
|
|
74
|
+
"__mode",
|
|
75
|
+
"__apiPath",
|
|
76
|
+
"__slothletPath",
|
|
77
|
+
"__isCallable",
|
|
78
|
+
"__materializeOnCreate",
|
|
79
|
+
"__displayName",
|
|
80
|
+
"__type",
|
|
81
|
+
"__metadata",
|
|
82
|
+
"__filePath",
|
|
83
|
+
"__sourceFolder",
|
|
84
|
+
"__moduleID",
|
|
85
|
+
"__materialized",
|
|
86
|
+
"__inFlight",
|
|
87
|
+
"__impl",
|
|
88
|
+
|
|
89
|
+
"_impl",
|
|
90
|
+
"_materialize",
|
|
91
|
+
|
|
92
|
+
"slothlet",
|
|
93
|
+
"shutdown",
|
|
94
|
+
"destroy"
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 CLDMV/Shinrai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { asyncContextManager } from "@cldmv/slothlet/handlers/context-async";
|
|
21
|
+
import { liveContextManager } from "@cldmv/slothlet/handlers/context-live";
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export function getContextManager(runtime = "async") {
|
|
25
|
+
return runtime === "live" ? liveContextManager : asyncContextManager;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export const contextManager = asyncContextManager;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export const asyncRuntime = asyncContextManager;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export const liveRuntime = liveContextManager;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export { asyncContextManager, liveContextManager };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 CLDMV/Shinrai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export class ApiCacheManager extends ComponentBase {
|
|
26
|
+
static slothletProperty = "apiCacheManager";
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
constructor(slothlet) {
|
|
30
|
+
super(slothlet);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
this.caches = new Map();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
set(moduleID, entry) {
|
|
38
|
+
if (!moduleID || typeof moduleID !== "string") {
|
|
39
|
+
throw new this.SlothletError("INVALID_ARGUMENT", {
|
|
40
|
+
argument: "moduleID",
|
|
41
|
+
expected: "non-empty string",
|
|
42
|
+
received: typeof moduleID,
|
|
43
|
+
validationError: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!entry || !entry.api) {
|
|
48
|
+
throw new this.SlothletError("INVALID_ARGUMENT", {
|
|
49
|
+
argument: "entry.api",
|
|
50
|
+
expected: "API tree object",
|
|
51
|
+
received: typeof entry?.api,
|
|
52
|
+
validationError: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if (entry.moduleID && entry.moduleID !== moduleID) {
|
|
58
|
+
throw new this.SlothletError("CACHE_MODULEID_MISMATCH", {
|
|
59
|
+
cacheKey: moduleID,
|
|
60
|
+
entryModuleID: entry.moduleID,
|
|
61
|
+
validationError: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.caches.set(moduleID, entry);
|
|
66
|
+
|
|
67
|
+
this.slothlet.debug("cache", {
|
|
68
|
+
key: "DEBUG_MODE_CACHE_ENTRY_STORED",
|
|
69
|
+
moduleID,
|
|
70
|
+
endpoint: entry.endpoint,
|
|
71
|
+
mode: entry.mode,
|
|
72
|
+
timestamp: entry.timestamp
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
get(moduleID) {
|
|
78
|
+
return this.caches.get(moduleID);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
has(moduleID) {
|
|
83
|
+
return this.caches.has(moduleID);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
delete(moduleID) {
|
|
88
|
+
const deleted = this.caches.delete(moduleID);
|
|
89
|
+
|
|
90
|
+
if (deleted) {
|
|
91
|
+
this.slothlet.debug("cache", {
|
|
92
|
+
key: "DEBUG_MODE_CACHE_ENTRY_DELETED",
|
|
93
|
+
moduleID
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return deleted;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
getAllModuleIDs() {
|
|
102
|
+
return Array.from(this.caches.keys());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
getCacheDiagnostics() {
|
|
107
|
+
const caches = [];
|
|
108
|
+
|
|
109
|
+
for (const [moduleID, entry] of this.caches.entries()) {
|
|
110
|
+
|
|
111
|
+
const pathCount = this._countPaths(entry.api);
|
|
112
|
+
|
|
113
|
+
caches.push({
|
|
114
|
+
moduleID,
|
|
115
|
+
endpoint: entry.endpoint,
|
|
116
|
+
folderPath: entry.folderPath,
|
|
117
|
+
mode: entry.mode,
|
|
118
|
+
pathCount,
|
|
119
|
+
timestamp: entry.timestamp
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
totalCaches: this.caches.size,
|
|
125
|
+
caches
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
_countPaths(api, visited = new WeakSet()) {
|
|
131
|
+
if (!api || typeof api !== "object" || visited.has(api)) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
visited.add(api);
|
|
136
|
+
let count = 0;
|
|
137
|
+
|
|
138
|
+
for (const [key, value] of Object.entries(api)) {
|
|
139
|
+
|
|
140
|
+
if (key.startsWith("__") || key.startsWith("_")) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
count += 1;
|
|
145
|
+
|
|
146
|
+
if (value && typeof value === "object") {
|
|
147
|
+
count += this._countPaths(value, visited);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return count;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
clear() {
|
|
156
|
+
this.caches.clear();
|
|
157
|
+
|
|
158
|
+
this.slothlet.debug("cache", {
|
|
159
|
+
key: "DEBUG_MODE_ALL_CACHES_CLEARED"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
async rebuildCache(moduleID) {
|
|
165
|
+
const entry = this.get(moduleID);
|
|
166
|
+
|
|
167
|
+
if (!entry) {
|
|
168
|
+
throw new this.SlothletError("CACHE_NOT_FOUND", {
|
|
169
|
+
moduleID,
|
|
170
|
+
operation: "rebuild",
|
|
171
|
+
validationError: true
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.slothlet.debug("cache", {
|
|
176
|
+
key: "DEBUG_MODE_REBUILDING_CACHE_FROM_DISK",
|
|
177
|
+
moduleID,
|
|
178
|
+
folderPath: entry.folderPath,
|
|
179
|
+
mode: entry.mode
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
const freshApi = await this.slothlet.builders.builder.buildAPI({
|
|
198
|
+
dir: entry.folderPath,
|
|
199
|
+
mode: entry.mode,
|
|
200
|
+
sanitize: entry.sanitizeOptions,
|
|
201
|
+
moduleID: moduleID,
|
|
202
|
+
apiPathPrefix: entry.endpoint === "." ? "" : entry.endpoint,
|
|
203
|
+
collisionMode: entry.collisionMode,
|
|
204
|
+
collisionContext: entry.endpoint === "." ? "initial" : "addApi",
|
|
205
|
+
cacheBust: Date.now()
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
this.slothlet.debug("cache", {
|
|
209
|
+
key: "DEBUG_MODE_CACHE_REBUILT_SUCCESSFULLY",
|
|
210
|
+
moduleID,
|
|
211
|
+
timestamp: Date.now()
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return freshApi;
|
|
215
|
+
}
|
|
216
|
+
}
|