@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,188 @@
|
|
|
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
|
+
import fs from "fs";
|
|
23
|
+
import path from "path";
|
|
24
|
+
import { SlothletError } from "@cldmv/slothlet/errors";
|
|
25
|
+
|
|
26
|
+
let esbuildInstance = null;
|
|
27
|
+
let typescriptInstance = null;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async function getEsbuild() {
|
|
31
|
+
if (!esbuildInstance) {
|
|
32
|
+
try {
|
|
33
|
+
esbuildInstance = await import("esbuild");
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new SlothletError("TYPESCRIPT_ESBUILD_NOT_INSTALLED", { mode: "fast" }, error);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
return esbuildInstance;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async function getTypeScript() {
|
|
47
|
+
if (!typescriptInstance) {
|
|
48
|
+
try {
|
|
49
|
+
typescriptInstance = await import("typescript");
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new SlothletError("TYPESCRIPT_TSC_NOT_INSTALLED", { mode: "strict" }, error);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
return typescriptInstance;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export async function transformTypeScript(filePath, options = {}) {
|
|
63
|
+
const esbuild = await getEsbuild();
|
|
64
|
+
const code = fs.readFileSync(filePath, "utf8");
|
|
65
|
+
|
|
66
|
+
const result = await esbuild.transform(code, {
|
|
67
|
+
loader: "ts",
|
|
68
|
+
format: options.format || "esm",
|
|
69
|
+
target: options.target || "es2020",
|
|
70
|
+
sourcemap: options.sourcemap || false,
|
|
71
|
+
...options
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return result.code;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
export function createDataUrl(code) {
|
|
79
|
+
|
|
80
|
+
const encoded = encodeURIComponent(code);
|
|
81
|
+
const timestamp = Date.now();
|
|
82
|
+
return `data:text/javascript;charset=utf-8,${encoded}#t=${timestamp}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export async function transformTypeScriptStrict(filePath, options = {}) {
|
|
87
|
+
const ts = await getTypeScript();
|
|
88
|
+
const code = fs.readFileSync(filePath, "utf8");
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const targetMap = {
|
|
92
|
+
es3: ts.ScriptTarget.ES3,
|
|
93
|
+
es5: ts.ScriptTarget.ES5,
|
|
94
|
+
es6: ts.ScriptTarget.ES2015,
|
|
95
|
+
es2015: ts.ScriptTarget.ES2015,
|
|
96
|
+
es2016: ts.ScriptTarget.ES2016,
|
|
97
|
+
es2017: ts.ScriptTarget.ES2017,
|
|
98
|
+
es2018: ts.ScriptTarget.ES2018,
|
|
99
|
+
es2019: ts.ScriptTarget.ES2019,
|
|
100
|
+
es2020: ts.ScriptTarget.ES2020,
|
|
101
|
+
es2021: ts.ScriptTarget.ES2021,
|
|
102
|
+
es2022: ts.ScriptTarget.ES2022,
|
|
103
|
+
esnext: ts.ScriptTarget.ESNext,
|
|
104
|
+
latest: ts.ScriptTarget.Latest
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const moduleMap = {
|
|
109
|
+
none: ts.ModuleKind.None,
|
|
110
|
+
commonjs: ts.ModuleKind.CommonJS,
|
|
111
|
+
amd: ts.ModuleKind.AMD,
|
|
112
|
+
system: ts.ModuleKind.System,
|
|
113
|
+
umd: ts.ModuleKind.UMD,
|
|
114
|
+
es6: ts.ModuleKind.ES2015,
|
|
115
|
+
es2015: ts.ModuleKind.ES2015,
|
|
116
|
+
es2020: ts.ModuleKind.ES2020,
|
|
117
|
+
es2022: ts.ModuleKind.ES2022,
|
|
118
|
+
esnext: ts.ModuleKind.ESNext,
|
|
119
|
+
node16: ts.ModuleKind.Node16,
|
|
120
|
+
nodenext: ts.ModuleKind.NodeNext
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const targetKey = (options.target || "es2020").toLowerCase();
|
|
124
|
+
const moduleKey = (options.module || "esnext").toLowerCase();
|
|
125
|
+
|
|
126
|
+
const compilerOptions = {
|
|
127
|
+
target: targetMap[targetKey] || ts.ScriptTarget.ES2020,
|
|
128
|
+
module: moduleMap[moduleKey] || ts.ModuleKind.ESNext,
|
|
129
|
+
strict: options.strict !== false,
|
|
130
|
+
esModuleInterop: true,
|
|
131
|
+
skipLibCheck: true,
|
|
132
|
+
noEmit: false,
|
|
133
|
+
...(options.typeDefinitionPath && {
|
|
134
|
+
typeRoots: [path.dirname(options.typeDefinitionPath)],
|
|
135
|
+
types: [path.basename(options.typeDefinitionPath, ".d.ts")]
|
|
136
|
+
}),
|
|
137
|
+
...options.compilerOptions
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
let diagnostics = [];
|
|
142
|
+
if (!options.skipTypeCheck) {
|
|
143
|
+
|
|
144
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
const originalReadFile = host.readFile;
|
|
148
|
+
host.readFile = (fileName) => {
|
|
149
|
+
if (fileName === filePath) {
|
|
150
|
+
return code;
|
|
151
|
+
}
|
|
152
|
+
return originalReadFile.call(host, fileName);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
const program = ts.createProgram([filePath], compilerOptions, host);
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
const allDiagnostics = [...program.getSemanticDiagnostics(), ...program.getSyntacticDiagnostics()];
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
diagnostics = allDiagnostics.filter((d) => d.file && d.file.fileName === filePath);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
const result = ts.transpileModule(code, {
|
|
167
|
+
compilerOptions,
|
|
168
|
+
fileName: filePath
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
code: result.outputText,
|
|
173
|
+
diagnostics
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
export function formatDiagnostics(diagnostics, ts) {
|
|
179
|
+
return diagnostics.map((diagnostic) => {
|
|
180
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
181
|
+
if (diagnostic.file && diagnostic.start !== undefined) {
|
|
182
|
+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
183
|
+
const fileName = diagnostic.file.fileName;
|
|
184
|
+
return `${fileName}:${line + 1}:${character + 1} - ${message}`;
|
|
185
|
+
}
|
|
186
|
+
return message;
|
|
187
|
+
});
|
|
188
|
+
}
|