@cldmv/slothlet 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +6 -8
  2. package/REFERENCE.md +23 -0
  3. package/dist/lib/builders/api-assignment.mjs +1 -589
  4. package/dist/lib/builders/api_builder.mjs +1 -1385
  5. package/dist/lib/builders/builder.mjs +1 -78
  6. package/dist/lib/builders/modes-processor.mjs +1 -1800
  7. package/dist/lib/errors.mjs +9 -211
  8. package/dist/lib/factories/component-base.mjs +1 -80
  9. package/dist/lib/factories/context.mjs +1 -22
  10. package/dist/lib/handlers/api-cache-manager.mjs +1 -200
  11. package/dist/lib/handlers/api-manager.mjs +1 -2536
  12. package/dist/lib/handlers/context-async.mjs +1 -172
  13. package/dist/lib/handlers/context-live.mjs +1 -173
  14. package/dist/lib/handlers/hook-manager.mjs +1 -667
  15. package/dist/lib/handlers/lifecycle-token.mjs +1 -28
  16. package/dist/lib/handlers/lifecycle.mjs +1 -115
  17. package/dist/lib/handlers/materialize-manager.mjs +1 -48
  18. package/dist/lib/handlers/metadata.mjs +1 -501
  19. package/dist/lib/handlers/ownership.mjs +1 -322
  20. package/dist/lib/handlers/permission-manager.mjs +1 -392
  21. package/dist/lib/handlers/unified-wrapper.mjs +1 -3110
  22. package/dist/lib/handlers/version-manager.mjs +1 -885
  23. package/dist/lib/helpers/class-instance-wrapper.mjs +1 -109
  24. package/dist/lib/helpers/config.mjs +1 -439
  25. package/dist/lib/helpers/eventemitter-context.mjs +1 -349
  26. package/dist/lib/helpers/hint-detector.mjs +1 -47
  27. package/dist/lib/helpers/modes-utils.mjs +1 -37
  28. package/dist/lib/helpers/pattern-matcher.mjs +1 -125
  29. package/dist/lib/helpers/resolve-from-caller.mjs +1 -169
  30. package/dist/lib/helpers/sanitize.mjs +1 -340
  31. package/dist/lib/helpers/utilities.mjs +1 -70
  32. package/dist/lib/i18n/translations.mjs +1 -126
  33. package/dist/lib/modes/eager.mjs +1 -59
  34. package/dist/lib/modes/lazy.mjs +1 -81
  35. package/dist/lib/processors/flatten.mjs +1 -437
  36. package/dist/lib/processors/loader.mjs +1 -339
  37. package/dist/lib/processors/type-generator.mjs +1 -275
  38. package/dist/lib/processors/typescript.mjs +1 -172
  39. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +1 -113
  40. package/dist/lib/runtime/runtime-livebindings.mjs +1 -78
  41. package/dist/lib/runtime/runtime.mjs +1 -102
  42. package/dist/slothlet.mjs +1 -817
  43. package/package.json +34 -31
  44. package/types/dist/lib/builders/api-assignment.d.mts +3 -92
  45. package/types/dist/lib/builders/api-assignment.d.mts.map +1 -1
  46. package/types/dist/lib/builders/api_builder.d.mts +102 -91
  47. package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
  48. package/types/dist/lib/builders/builder.d.mts +1 -55
  49. package/types/dist/lib/builders/builder.d.mts.map +1 -1
  50. package/types/dist/lib/builders/modes-processor.d.mts +3 -27
  51. package/types/dist/lib/builders/modes-processor.d.mts.map +1 -1
  52. package/types/dist/lib/errors.d.mts +19 -109
  53. package/types/dist/lib/errors.d.mts.map +1 -1
  54. package/types/dist/lib/factories/component-base.d.mts +7 -177
  55. package/types/dist/lib/factories/component-base.d.mts.map +1 -1
  56. package/types/dist/lib/factories/context.d.mts +4 -22
  57. package/types/dist/lib/factories/context.d.mts.map +1 -1
  58. package/types/dist/lib/handlers/api-cache-manager.d.mts +20 -203
  59. package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -1
  60. package/types/dist/lib/handlers/api-manager.d.mts +33 -408
  61. package/types/dist/lib/handlers/api-manager.d.mts.map +1 -1
  62. package/types/dist/lib/handlers/context-async.d.mts +23 -61
  63. package/types/dist/lib/handlers/context-async.d.mts.map +1 -1
  64. package/types/dist/lib/handlers/context-live.d.mts +22 -59
  65. package/types/dist/lib/handlers/context-live.d.mts.map +1 -1
  66. package/types/dist/lib/handlers/hook-manager.d.mts +46 -185
  67. package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -1
  68. package/types/dist/lib/handlers/lifecycle-token.d.mts +3 -48
  69. package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -1
  70. package/types/dist/lib/handlers/lifecycle.d.mts +5 -82
  71. package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -1
  72. package/types/dist/lib/handlers/materialize-manager.d.mts +8 -70
  73. package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -1
  74. package/types/dist/lib/handlers/metadata.d.mts +17 -221
  75. package/types/dist/lib/handlers/metadata.d.mts.map +1 -1
  76. package/types/dist/lib/handlers/ownership.d.mts +44 -160
  77. package/types/dist/lib/handlers/ownership.d.mts.map +1 -1
  78. package/types/dist/lib/handlers/permission-manager.d.mts +37 -141
  79. package/types/dist/lib/handlers/permission-manager.d.mts.map +1 -1
  80. package/types/dist/lib/handlers/unified-wrapper.d.mts +26 -239
  81. package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -1
  82. package/types/dist/lib/handlers/version-manager.d.mts +28 -225
  83. package/types/dist/lib/handlers/version-manager.d.mts.map +1 -1
  84. package/types/dist/lib/helpers/class-instance-wrapper.d.mts +2 -52
  85. package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -1
  86. package/types/dist/lib/helpers/config.d.mts +125 -139
  87. package/types/dist/lib/helpers/config.d.mts.map +1 -1
  88. package/types/dist/lib/helpers/eventemitter-context.d.mts +3 -29
  89. package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -1
  90. package/types/dist/lib/helpers/hint-detector.d.mts +2 -15
  91. package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -1
  92. package/types/dist/lib/helpers/modes-utils.d.mts +3 -30
  93. package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -1
  94. package/types/dist/lib/helpers/pattern-matcher.d.mts +3 -43
  95. package/types/dist/lib/helpers/pattern-matcher.d.mts.map +1 -1
  96. package/types/dist/lib/helpers/resolve-from-caller.d.mts +3 -27
  97. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
  98. package/types/dist/lib/helpers/sanitize.d.mts +4 -92
  99. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
  100. package/types/dist/lib/helpers/utilities.d.mts +4 -52
  101. package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
  102. package/types/dist/lib/i18n/translations.d.mts +4 -37
  103. package/types/dist/lib/i18n/translations.d.mts.map +1 -1
  104. package/types/dist/lib/modes/eager.d.mts +8 -30
  105. package/types/dist/lib/modes/eager.d.mts.map +1 -1
  106. package/types/dist/lib/modes/lazy.d.mts +10 -43
  107. package/types/dist/lib/modes/lazy.d.mts.map +1 -1
  108. package/types/dist/lib/processors/flatten.d.mts +56 -107
  109. package/types/dist/lib/processors/flatten.d.mts.map +1 -1
  110. package/types/dist/lib/processors/loader.d.mts +6 -41
  111. package/types/dist/lib/processors/loader.d.mts.map +1 -1
  112. package/types/dist/lib/processors/type-generator.d.mts +2 -16
  113. package/types/dist/lib/processors/type-generator.d.mts.map +1 -1
  114. package/types/dist/lib/processors/typescript.d.mts +6 -53
  115. package/types/dist/lib/processors/typescript.d.mts.map +1 -1
  116. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +3 -71
  117. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  118. package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -37
  119. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  120. package/types/dist/lib/runtime/runtime.d.mts +3 -39
  121. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  122. package/types/dist/slothlet.d.mts +3 -249
  123. package/types/dist/slothlet.d.mts.map +1 -1
  124. package/types/index.d.mts +36 -16
  125. package/types/index.d.mts.map +1 -0
  126. package/AGENT-USAGE.md +0 -736
  127. package/docs/API-RULES.md +0 -712
@@ -14,129 +14,4 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
-
18
-
19
-
20
-
21
- import { readFileSync } from "fs";
22
- import { fileURLToPath } from "url";
23
- import { dirname, join } from "path";
24
-
25
-
26
- const translations_dirname = dirname(fileURLToPath(import.meta.url));
27
-
28
-
29
- const defaultTranslations = JSON.parse(readFileSync(join(translations_dirname, "languages", "en-us.json"), "utf-8"));
30
-
31
-
32
- let currentTranslations = defaultTranslations.translations;
33
-
34
-
35
- let currentLanguage = "en-us";
36
-
37
-
38
- function i18n_detectLanguage() {
39
-
40
- const envLang = process.env.LANG || process.env.LANGUAGE || process.env.LC_ALL;
41
- if (envLang) {
42
- const lang = envLang.split(".")[0].split("_")[0].toLowerCase();
43
-
44
- if (lang === "en") return "en-us";
45
-
46
- if (lang === "c" || lang === "posix") return "en-us";
47
- if (lang === "es") return "es-mx";
48
- return lang;
49
- }
50
-
51
-
52
- return "en-us";
53
- }
54
-
55
-
56
- function i18n_loadLanguageSync(lang) {
57
- try {
58
-
59
- const langFilePath = join(translations_dirname, "languages", `${lang}.json`);
60
- const langData = JSON.parse(readFileSync(langFilePath, "utf-8"));
61
- return langData.translations;
62
- } catch (___error) {
63
-
64
- return null;
65
- }
66
- }
67
-
68
-
69
- export function setLanguage(lang) {
70
-
71
- currentTranslations = { ...defaultTranslations.translations };
72
-
73
-
74
- if (lang !== "en-us") {
75
- const langTranslations = i18n_loadLanguageSync(lang);
76
- if (langTranslations) {
77
-
78
- currentTranslations = { ...currentTranslations, ...langTranslations };
79
- currentLanguage = lang;
80
- } else {
81
-
82
- console.warn(`Failed to load language '${lang}', falling back to English.`);
83
- currentLanguage = "en-us";
84
- }
85
- } else {
86
- currentLanguage = "en-us";
87
- }
88
- }
89
-
90
-
91
- export function getLanguage() {
92
- return currentLanguage;
93
- }
94
-
95
-
96
- export function translate(errorCode, params = {}) {
97
-
98
- let template = currentTranslations[errorCode];
99
-
100
-
101
- if (!template && errorCode.startsWith("INVALID_CONFIG_")) {
102
- template = currentTranslations.INVALID_CONFIG_generic;
103
- }
104
-
105
-
106
- let message = template || `Error: ${errorCode}`;
107
- for (const [key, value] of Object.entries(params)) {
108
- message = message.replace(new RegExp(`\\{${key}\\}`, "g"), value !== undefined ? String(value) : "");
109
- }
110
-
111
-
112
- message = message
113
- .replace(/\{\w+\}/g, "")
114
- .replace(/\s+/g, " ")
115
- .trim();
116
-
117
- return message;
118
- }
119
-
120
-
121
- export function initI18n(options = {}) {
122
- try {
123
- if (options.language) {
124
- setLanguage(options.language);
125
- } else {
126
-
127
- const detected = i18n_detectLanguage();
128
- setLanguage(detected);
129
- }
130
- } catch (___error) {
131
-
132
- console.warn("i18n initialization failed, using English:", ___error.message);
133
- currentLanguage = "en-us";
134
- currentTranslations = defaultTranslations.translations;
135
- }
136
- }
137
-
138
-
139
- initI18n();
140
-
141
-
142
- export const t = translate;
17
+ import{readFileSync}from"fs";import{fileURLToPath}from"url";import{dirname,join}from"path";const translations_dirname=dirname(fileURLToPath(import.meta.url));const defaultTranslations=JSON.parse(readFileSync(join(translations_dirname,"languages","en-us.json"),"utf-8"));let currentTranslations=defaultTranslations.translations;let currentLanguage="en-us";function i18n_detectLanguage(){const envLang=process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL;if(envLang){const lang=envLang.split(".")[0].split("_")[0].toLowerCase();if(lang==="en")return"en-us";if(lang==="c"||lang==="posix")return"en-us";if(lang==="es")return"es-mx";return lang}return"en-us"}function i18n_loadLanguageSync(lang){try{const langFilePath=join(translations_dirname,"languages",`${lang}.json`);const langData=JSON.parse(readFileSync(langFilePath,"utf-8"));return langData.translations}catch(___error){return null}}function setLanguage(lang){currentTranslations={...defaultTranslations.translations};if(lang!=="en-us"){const langTranslations=i18n_loadLanguageSync(lang);if(langTranslations){currentTranslations={...currentTranslations,...langTranslations};currentLanguage=lang}else{console.warn(`Failed to load language '${lang}', falling back to English.`);currentLanguage="en-us"}}else{currentLanguage="en-us"}}function getLanguage(){return currentLanguage}function translate(errorCode,params={}){let template=currentTranslations[errorCode];if(!template&&errorCode.startsWith("INVALID_CONFIG_")){template=currentTranslations.INVALID_CONFIG_generic}let message=template||`Error: ${errorCode}`;for(const[key,value]of Object.entries(params)){message=message.replace(new RegExp(`\\{${key}\\}`,"g"),value!==void 0?String(value):"")}message=message.replace(/\{\w+\}/g,"").replace(/\s+/g," ").trim();return message}function initI18n(options={}){try{if(options.language){setLanguage(options.language)}else{const detected=i18n_detectLanguage();setLanguage(detected)}}catch(___error){console.warn("i18n initialization failed, using English:",___error.message);currentLanguage="en-us";currentTranslations=defaultTranslations.translations}}initI18n();const t=translate;export{getLanguage,initI18n,setLanguage,t,translate};
@@ -14,62 +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
- export class EagerMode extends ComponentBase {
24
- static slothletProperty = "eager";
25
-
26
-
27
- constructor(slothlet) {
28
- super(slothlet);
29
- }
30
-
31
-
32
- async buildAPI({
33
- dir,
34
- apiPathPrefix = "",
35
- collisionContext = "initial",
36
- moduleID,
37
- apiDepth = Infinity,
38
- cacheBust = null,
39
- fileFilter = null
40
- }) {
41
- const api = {};
42
-
43
- const { modesProcessor } = this.slothlet.builders;
44
- const { loader } = this.slothlet.processors;
45
-
46
- const structure = await loader.scanDirectory(dir, { maxDepth: apiDepth, fileFilter });
47
-
48
- const rootDirectory = {
49
- name: ".",
50
- path: dir,
51
- children: {
52
- files: structure.files,
53
- directories: structure.directories
54
- }
55
- };
56
-
57
- const rootDefaultFunction = await modesProcessor.processFiles(
58
- api,
59
- structure.files,
60
- rootDirectory,
61
- 0,
62
- "eager",
63
- true,
64
- true,
65
- false,
66
- apiPathPrefix,
67
- collisionContext,
68
- moduleID,
69
- dir,
70
- cacheBust
71
- );
72
-
73
- return modesProcessor.applyRootContributor(api, rootDefaultFunction, "eager");
74
- }
75
- }
17
+ import{ComponentBase}from"@cldmv/slothlet/factories/component-base";class EagerMode extends ComponentBase{static slothletProperty="eager";constructor(slothlet){super(slothlet)}async buildAPI({dir,apiPathPrefix="",collisionContext="initial",moduleID,apiDepth=Infinity,cacheBust=null,fileFilter=null}){const api={};const{modesProcessor}=this.slothlet.builders;const{loader}=this.slothlet.processors;const structure=await loader.scanDirectory(dir,{maxDepth:apiDepth,fileFilter});const rootDirectory={name:".",path:dir,children:{files:structure.files,directories:structure.directories}};const rootDefaultFunction=await modesProcessor.processFiles(api,structure.files,rootDirectory,0,"eager",true,true,false,apiPathPrefix,collisionContext,moduleID,dir,cacheBust);return modesProcessor.applyRootContributor(api,rootDefaultFunction,"eager")}}export{EagerMode};
@@ -14,84 +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
- export class LazyMode extends ComponentBase {
24
- static slothletProperty = "lazy";
25
-
26
-
27
- constructor(slothlet) {
28
- super(slothlet);
29
- }
30
-
31
-
32
- createNamedMaterializeFunc(apiPath, handler) {
33
- const safePath = String(apiPath || "api")
34
- .replace(/\./g, "__")
35
- .replace(/[^A-Za-z0-9_$]/g, "_");
36
- const normalized = /^[A-Za-z_$]/.test(safePath[0]) ? safePath : `_${safePath}`;
37
- const funcName = `${normalized}__lazy_materializeFunc`;
38
- return {
39
- [funcName]: async function (...args) {
40
- return handler(...args);
41
- }
42
- }[funcName];
43
- }
44
-
45
-
46
- async buildAPI({
47
- dir,
48
- apiPathPrefix = "",
49
- collisionContext = "initial",
50
- collisionMode = null,
51
- moduleID,
52
- apiDepth = Infinity,
53
- cacheBust = null,
54
- fileFilter = null
55
- }) {
56
- this.slothlet.debug("modes", {
57
- key: "DEBUG_MODE_BUILD_LAZY_API_CALLED",
58
- apiPathPrefix,
59
- collisionMode,
60
- collisionContext
61
- });
62
- const api = {};
63
-
64
- const { modesProcessor } = this.slothlet.builders;
65
- const { loader } = this.slothlet.processors;
66
-
67
- const structure = await loader.scanDirectory(dir, { maxDepth: apiDepth, fileFilter });
68
-
69
- const rootDirectory = {
70
- name: ".",
71
- path: dir,
72
- children: {
73
- files: structure.files,
74
- directories: structure.directories
75
- }
76
- };
77
-
78
- const rootDefaultFunction = await modesProcessor.processFiles(
79
- api,
80
- structure.files,
81
- rootDirectory,
82
- 0,
83
- "lazy",
84
- true,
85
- false,
86
- false,
87
- apiPathPrefix,
88
- collisionContext,
89
- moduleID,
90
- dir,
91
- cacheBust,
92
- collisionMode
93
- );
94
-
95
- return modesProcessor.applyRootContributor(api, rootDefaultFunction, "lazy");
96
- }
97
- }
17
+ import{ComponentBase}from"@cldmv/slothlet/factories/component-base";class LazyMode extends ComponentBase{static slothletProperty="lazy";constructor(slothlet){super(slothlet)}createNamedMaterializeFunc(apiPath,handler){const safePath=String(apiPath||"api").replace(/\./g,"__").replace(/[^A-Za-z0-9_$]/g,"_");const normalized=/^[A-Za-z_$]/.test(safePath[0])?safePath:`_${safePath}`;const funcName=`${normalized}__lazy_materializeFunc`;return{[funcName]:async function(...args){return handler(...args)}}[funcName]}async buildAPI({dir,apiPathPrefix="",collisionContext="initial",collisionMode=null,moduleID,apiDepth=Infinity,cacheBust=null,fileFilter=null}){this.slothlet.debug("modes",{key:"DEBUG_MODE_BUILD_LAZY_API_CALLED",apiPathPrefix,collisionMode,collisionContext});const api={};const{modesProcessor}=this.slothlet.builders;const{loader}=this.slothlet.processors;const structure=await loader.scanDirectory(dir,{maxDepth:apiDepth,fileFilter});const rootDirectory={name:".",path:dir,children:{files:structure.files,directories:structure.directories}};const rootDefaultFunction=await modesProcessor.processFiles(api,structure.files,rootDirectory,0,"lazy",true,false,false,apiPathPrefix,collisionContext,moduleID,dir,cacheBust,collisionMode);return modesProcessor.applyRootContributor(api,rootDefaultFunction,"lazy")}}export{LazyMode};