@cldmv/slothlet 3.3.0 → 3.4.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/README.md +9 -10
- package/REFERENCE.md +23 -0
- package/dist/lib/builders/api-assignment.mjs +1 -589
- package/dist/lib/builders/api_builder.mjs +1 -1385
- package/dist/lib/builders/builder.mjs +1 -78
- package/dist/lib/builders/modes-processor.mjs +1 -1800
- package/dist/lib/errors.mjs +9 -211
- package/dist/lib/factories/component-base.mjs +1 -80
- package/dist/lib/factories/context.mjs +1 -22
- package/dist/lib/handlers/api-cache-manager.mjs +1 -200
- package/dist/lib/handlers/api-manager.mjs +1 -2536
- package/dist/lib/handlers/context-async.mjs +1 -172
- package/dist/lib/handlers/context-live.mjs +1 -173
- package/dist/lib/handlers/hook-manager.mjs +1 -667
- package/dist/lib/handlers/lifecycle-token.mjs +1 -28
- package/dist/lib/handlers/lifecycle.mjs +1 -115
- package/dist/lib/handlers/materialize-manager.mjs +1 -48
- package/dist/lib/handlers/metadata.mjs +1 -501
- package/dist/lib/handlers/ownership.mjs +1 -322
- package/dist/lib/handlers/permission-manager.mjs +1 -392
- package/dist/lib/handlers/unified-wrapper.mjs +1 -3110
- package/dist/lib/handlers/version-manager.mjs +1 -885
- package/dist/lib/helpers/class-instance-wrapper.mjs +1 -109
- package/dist/lib/helpers/config.mjs +1 -439
- package/dist/lib/helpers/eventemitter-context.mjs +1 -349
- package/dist/lib/helpers/hint-detector.mjs +1 -47
- package/dist/lib/helpers/modes-utils.mjs +1 -37
- package/dist/lib/helpers/pattern-matcher.mjs +1 -125
- package/dist/lib/helpers/resolve-from-caller.mjs +1 -169
- package/dist/lib/helpers/sanitize.mjs +1 -340
- package/dist/lib/helpers/utilities.mjs +1 -70
- package/dist/lib/i18n/languages/de-de.json +1 -0
- package/dist/lib/i18n/languages/en-gb.json +1 -0
- package/dist/lib/i18n/languages/en-us.json +1 -0
- package/dist/lib/i18n/languages/es-es.json +412 -0
- package/dist/lib/i18n/languages/es-mx.json +1 -0
- package/dist/lib/i18n/languages/fr-fr.json +1 -0
- package/dist/lib/i18n/languages/hi-in.json +2 -1
- package/dist/lib/i18n/languages/ja-jp.json +1 -0
- package/dist/lib/i18n/languages/ko-kr.json +1 -0
- package/dist/lib/i18n/languages/pt-br.json +21 -20
- package/dist/lib/i18n/languages/ru-ru.json +2 -1
- package/dist/lib/i18n/languages/zh-cn.json +6 -5
- package/dist/lib/i18n/translations.mjs +1 -126
- package/dist/lib/modes/eager.mjs +1 -59
- package/dist/lib/modes/lazy.mjs +1 -81
- package/dist/lib/processors/flatten.mjs +1 -437
- package/dist/lib/processors/loader.mjs +1 -339
- package/dist/lib/processors/type-generator.mjs +1 -275
- package/dist/lib/processors/typescript.mjs +1 -172
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +1 -113
- package/dist/lib/runtime/runtime-livebindings.mjs +1 -78
- package/dist/lib/runtime/runtime.mjs +1 -102
- package/dist/slothlet.mjs +1 -817
- package/package.json +35 -31
- package/types/dist/lib/builders/api-assignment.d.mts +3 -92
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -1
- package/types/dist/lib/builders/api_builder.d.mts +102 -91
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
- package/types/dist/lib/builders/builder.d.mts +1 -55
- package/types/dist/lib/builders/builder.d.mts.map +1 -1
- package/types/dist/lib/builders/modes-processor.d.mts +3 -27
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -1
- package/types/dist/lib/errors.d.mts +19 -109
- package/types/dist/lib/errors.d.mts.map +1 -1
- package/types/dist/lib/factories/component-base.d.mts +7 -177
- package/types/dist/lib/factories/component-base.d.mts.map +1 -1
- package/types/dist/lib/factories/context.d.mts +4 -22
- package/types/dist/lib/factories/context.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-cache-manager.d.mts +20 -203
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-manager.d.mts +34 -408
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-async.d.mts +23 -61
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-live.d.mts +22 -59
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -1
- package/types/dist/lib/handlers/hook-manager.d.mts +46 -185
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle-token.d.mts +3 -48
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle.d.mts +5 -82
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -1
- package/types/dist/lib/handlers/materialize-manager.d.mts +8 -70
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/metadata.d.mts +17 -221
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -1
- package/types/dist/lib/handlers/ownership.d.mts +44 -160
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -1
- package/types/dist/lib/handlers/permission-manager.d.mts +40 -141
- package/types/dist/lib/handlers/permission-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/unified-wrapper.d.mts +26 -239
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -1
- package/types/dist/lib/handlers/version-manager.d.mts +28 -225
- package/types/dist/lib/handlers/version-manager.d.mts.map +1 -1
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +2 -52
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -1
- package/types/dist/lib/helpers/config.d.mts +125 -139
- package/types/dist/lib/helpers/config.d.mts.map +1 -1
- package/types/dist/lib/helpers/eventemitter-context.d.mts +3 -29
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -1
- package/types/dist/lib/helpers/hint-detector.d.mts +2 -15
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -1
- package/types/dist/lib/helpers/modes-utils.d.mts +3 -30
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -1
- package/types/dist/lib/helpers/pattern-matcher.d.mts +3 -43
- package/types/dist/lib/helpers/pattern-matcher.d.mts.map +1 -1
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +3 -27
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +4 -92
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +4 -52
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +4 -37
- package/types/dist/lib/i18n/translations.d.mts.map +1 -1
- package/types/dist/lib/modes/eager.d.mts +8 -30
- package/types/dist/lib/modes/eager.d.mts.map +1 -1
- package/types/dist/lib/modes/lazy.d.mts +10 -43
- package/types/dist/lib/modes/lazy.d.mts.map +1 -1
- package/types/dist/lib/processors/flatten.d.mts +56 -107
- package/types/dist/lib/processors/flatten.d.mts.map +1 -1
- package/types/dist/lib/processors/loader.d.mts +6 -41
- package/types/dist/lib/processors/loader.d.mts.map +1 -1
- package/types/dist/lib/processors/type-generator.d.mts +2 -16
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -1
- package/types/dist/lib/processors/typescript.d.mts +6 -53
- package/types/dist/lib/processors/typescript.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +3 -71
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -37
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +3 -39
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +3 -249
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +36 -16
- package/types/index.d.mts.map +1 -0
- package/AGENT-USAGE.md +0 -736
- package/docs/API-RULES.md +0 -712
package/dist/lib/errors.mjs
CHANGED
|
@@ -14,214 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
17
|
+
import{translate}from"@cldmv/slothlet/i18n";import{detectHint}from"@cldmv/slothlet/helpers/hint-detector";class SlothletError extends Error{constructor(code,context={},originalError=null,options={}){const{validationError:ctxValidation,stub:ctxStub,...contextData}=context;const{validationError:optsValidation,stub:optsStub}=options;const validationError=ctxValidation??optsValidation;const stub=ctxStub??optsStub;const enrichedContext=originalError?{...contextData,error:originalError.message}:contextData;const translatedMessage=translate(code,enrichedContext);const skipHint=stub||validationError;const hintKey=originalError&&!skipHint?detectHint(originalError,code):void 0;let translatedHint=hintKey?translate(hintKey,enrichedContext):void 0;if(!translatedHint&&validationError){const staticHintKey=`HINT_${code}`;const staticHint=translate(staticHintKey,enrichedContext);if(staticHint&&!staticHint.startsWith("Error:")){translatedHint=staticHint}}const messageWithCode=`[${code}] ${translatedMessage}`;super(messageWithCode);this.name="SlothletError";Object.defineProperty(this,"code",{value:code,enumerable:false,writable:false});Object.defineProperty(this,"context",{value:context,enumerable:false,writable:false});Object.defineProperty(this,"originalError",{value:originalError,enumerable:false,writable:false});Object.defineProperty(this,"hint",{value:translatedHint,enumerable:false,writable:false});Error.captureStackTrace(this,SlothletError)}toString(){let output=`
|
|
18
|
+
[${this.code}] ${this.name}
|
|
19
|
+
`;if(this.hint){output+=`
|
|
20
|
+
\u{1F4A1} ${this.hint}
|
|
21
|
+
`}const criticalKeys=["modulePath","moduleID","apiPath"];const detailKeys=Object.keys(this.context).filter(k=>criticalKeys.includes(k));if(detailKeys.length>0){output+="\nDetails:\n";for(const key of detailKeys){output+=` ${key}: ${this.context[key]}
|
|
22
|
+
`}}return output}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()+`
|
|
23
|
+
${this.stack}`}toJSON(){return{name:this.name,code:this.code,message:this.message,hint:this.context.hint}}}class SlothletWarning{static captured=[];static suppressConsole=false;constructor(code,context={}){const{key:msgKey,...contextData}=context;const translationKey=msgKey??code;const translatedMessage=translate(translationKey,contextData);this.name="SlothletWarning";this.code=code;this.message=translatedMessage;this.context=context;if(!SlothletWarning.suppressConsole){console.warn(`
|
|
24
|
+
\u26A0\uFE0F [${this.code}] ${this.name}
|
|
25
|
+
${this.message}`);if(Object.keys(contextData).length>0){console.warn("Context:",contextData)}}else{SlothletWarning.captured.push(this)}}toString(){return`[${this.code}] ${this.name}: ${this.message}`}static clearCaptured(){SlothletWarning.captured=[]}}class SlothletDebug{constructor(config={}){this.config=config;this.debugFlags=config.debug||{}}log(code,context={}){if(!this.debugFlags||!this.debugFlags[code]){return}const{key:msgKey,message,...contextParams}=context;const translationKey=msgKey??`DEBUG_${code.toUpperCase()}`;const translatedMessage=translate(translationKey,contextParams);const hasTranslation=translatedMessage&&!translatedMessage.startsWith("Error:");const label=`[DEBUG:${code.toUpperCase()}]`;if(hasTranslation){console.log(`${label} ${translatedMessage}`)}else if(message){console.log(`${label} ${message}`)}else{console.log(label,contextParams)}if((hasTranslation||message)&&Object.keys(contextParams).length>0){console.log(`${label} Context:`,contextParams)}}toString(){return`[SlothletDebug] flags: ${Object.keys(this.debugFlags).filter(k=>this.debugFlags[k]).join(", ")}`}}export{SlothletDebug,SlothletError,SlothletWarning};
|
|
@@ -14,83 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
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
|
-
}
|
|
17
|
+
class ComponentBase{#slothlet;constructor(slothlet){this.#slothlet=slothlet}get ____slothlet(){return this.#slothlet}get slothlet(){return this.#slothlet}get ____config(){return this.____slothlet.config}get instanceID(){return this.____slothlet.instanceID}get SlothletError(){return this.____slothlet.SlothletError}get SlothletWarning(){return this.____slothlet.SlothletWarning}static INTERNAL_KEYS=new Set(["____slothletInternal","____slothlet","___getState","___setImpl","___resetLazy","___invalidate","__state","__invalid","__mode","__apiPath","__slothletPath","__isCallable","__materializeOnCreate","__displayName","__type","__metadata","__filePath","__sourceFolder","__moduleID","__materialized","__inFlight","__impl","_impl","_materialize","slothlet","shutdown","destroy"])}export{ComponentBase};
|
|
@@ -14,25 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
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 };
|
|
17
|
+
import{asyncContextManager}from"@cldmv/slothlet/handlers/context-async";import{liveContextManager}from"@cldmv/slothlet/handlers/context-live";function getContextManager(runtime="async"){return runtime==="live"?liveContextManager:asyncContextManager}const contextManager=asyncContextManager;const asyncRuntime=asyncContextManager;const liveRuntime=liveContextManager;export{asyncContextManager,asyncRuntime,contextManager,getContextManager,liveContextManager,liveRuntime};
|
|
@@ -14,203 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
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
|
-
}
|
|
17
|
+
import{ComponentBase}from"@cldmv/slothlet/factories/component-base";class ApiCacheManager extends ComponentBase{static slothletProperty="apiCacheManager";constructor(slothlet){super(slothlet);this.caches=new Map}set(moduleID,entry){if(!moduleID||typeof moduleID!=="string"){throw new this.SlothletError("INVALID_ARGUMENT",{argument:"moduleID",expected:"non-empty string",received:typeof moduleID,validationError:true})}if(!entry||!entry.api){throw new this.SlothletError("INVALID_ARGUMENT",{argument:"entry.api",expected:"API tree object",received:typeof entry?.api,validationError:true})}if(entry.moduleID&&entry.moduleID!==moduleID){throw new this.SlothletError("CACHE_MODULEID_MISMATCH",{cacheKey:moduleID,entryModuleID:entry.moduleID,validationError:true})}this.caches.set(moduleID,entry);this.slothlet.debug("cache",{key:"DEBUG_MODE_CACHE_ENTRY_STORED",moduleID,endpoint:entry.endpoint,mode:entry.mode,timestamp:entry.timestamp})}get(moduleID){return this.caches.get(moduleID)}has(moduleID){return this.caches.has(moduleID)}delete(moduleID){const deleted=this.caches.delete(moduleID);if(deleted){this.slothlet.debug("cache",{key:"DEBUG_MODE_CACHE_ENTRY_DELETED",moduleID})}return deleted}getAllModuleIDs(){return Array.from(this.caches.keys())}getCacheDiagnostics(){const caches=[];for(const[moduleID,entry]of this.caches.entries()){const pathCount=this._countPaths(entry.api);caches.push({moduleID,endpoint:entry.endpoint,folderPath:entry.folderPath,mode:entry.mode,pathCount,timestamp:entry.timestamp})}return{totalCaches:this.caches.size,caches}}_countPaths(api,visited=new WeakSet){if(!api||typeof api!=="object"||visited.has(api)){return 0}visited.add(api);let count=0;for(const[key,value]of Object.entries(api)){if(key.startsWith("__")||key.startsWith("_")){continue}count+=1;if(value&&typeof value==="object"){count+=this._countPaths(value,visited)}}return count}clear(){this.caches.clear();this.slothlet.debug("cache",{key:"DEBUG_MODE_ALL_CACHES_CLEARED"})}async rebuildCache(moduleID){const entry=this.get(moduleID);if(!entry){throw new this.SlothletError("CACHE_NOT_FOUND",{moduleID,operation:"rebuild",validationError:true})}this.slothlet.debug("cache",{key:"DEBUG_MODE_REBUILDING_CACHE_FROM_DISK",moduleID,folderPath:entry.folderPath,mode:entry.mode});const freshApi=await this.slothlet.builders.builder.buildAPI({dir:entry.folderPath,mode:entry.mode,sanitize:entry.sanitizeOptions,moduleID,apiPathPrefix:entry.endpoint==="."?"":entry.endpoint,collisionMode:entry.collisionMode,collisionContext:entry.endpoint==="."?"initial":"addApi",cacheBust:Date.now()});this.slothlet.debug("cache",{key:"DEBUG_MODE_CACHE_REBUILT_SUCCESSFULLY",moduleID,timestamp:Date.now()});return freshApi}}export{ApiCacheManager};
|