@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.
Files changed (189) hide show
  1. package/AGENT-USAGE.md +355 -325
  2. package/README.md +554 -238
  3. package/dist/lib/builders/api-assignment.mjs +605 -0
  4. package/dist/lib/builders/api_builder.mjs +1073 -0
  5. package/dist/lib/builders/builder.mjs +94 -0
  6. package/dist/lib/builders/modes-processor.mjs +1816 -0
  7. package/dist/lib/errors.mjs +227 -0
  8. package/dist/lib/factories/component-base.mjs +96 -0
  9. package/dist/lib/factories/context.mjs +38 -0
  10. package/dist/lib/handlers/api-cache-manager.mjs +216 -0
  11. package/dist/lib/handlers/api-manager.mjs +2364 -0
  12. package/dist/lib/handlers/context-async.mjs +184 -0
  13. package/dist/lib/handlers/context-live.mjs +184 -0
  14. package/dist/lib/handlers/hook-manager.mjs +789 -0
  15. package/dist/lib/handlers/lifecycle-token.mjs +44 -0
  16. package/dist/lib/handlers/lifecycle.mjs +131 -0
  17. package/dist/lib/handlers/materialize-manager.mjs +64 -0
  18. package/dist/lib/handlers/metadata.mjs +500 -0
  19. package/dist/lib/handlers/ownership.mjs +338 -0
  20. package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
  21. package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
  22. package/dist/lib/helpers/config.mjs +343 -0
  23. package/dist/lib/helpers/eventemitter-context.mjs +365 -0
  24. package/dist/lib/helpers/hint-detector.mjs +63 -0
  25. package/dist/lib/helpers/modes-utils.mjs +53 -0
  26. package/dist/lib/helpers/resolve-from-caller.mjs +123 -117
  27. package/dist/lib/helpers/sanitize.mjs +247 -168
  28. package/dist/lib/helpers/utilities.mjs +46 -81
  29. package/dist/lib/i18n/languages/de-de.json +377 -0
  30. package/dist/lib/i18n/languages/en-gb.json +377 -0
  31. package/dist/lib/i18n/languages/en-us.json +377 -0
  32. package/dist/lib/i18n/languages/es-mx.json +377 -0
  33. package/dist/lib/i18n/languages/fr-fr.json +377 -0
  34. package/dist/lib/i18n/languages/hi-in.json +377 -0
  35. package/dist/lib/i18n/languages/ja-jp.json +377 -0
  36. package/dist/lib/i18n/languages/ko-kr.json +377 -0
  37. package/dist/lib/i18n/languages/pt-br.json +377 -0
  38. package/dist/lib/i18n/languages/ru-ru.json +377 -0
  39. package/dist/lib/i18n/languages/zh-cn.json +377 -0
  40. package/dist/lib/i18n/translations.mjs +140 -0
  41. package/dist/lib/modes/eager.mjs +75 -0
  42. package/dist/lib/modes/lazy.mjs +97 -0
  43. package/dist/lib/processors/flatten.mjs +453 -0
  44. package/dist/lib/processors/loader.mjs +355 -0
  45. package/dist/lib/processors/type-generator.mjs +291 -0
  46. package/dist/lib/processors/typescript.mjs +188 -0
  47. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
  48. package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
  49. package/dist/lib/runtime/runtime.mjs +39 -159
  50. package/dist/slothlet.mjs +525 -744
  51. package/docs/API-RULES.md +338 -486
  52. package/index.cjs +4 -4
  53. package/index.mjs +82 -45
  54. package/package.json +143 -30
  55. package/types/dist/lib/builders/api-assignment.d.mts +97 -0
  56. package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
  57. package/types/dist/lib/builders/api_builder.d.mts +96 -0
  58. package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
  59. package/types/dist/lib/builders/builder.d.mts +60 -0
  60. package/types/dist/lib/builders/builder.d.mts.map +1 -0
  61. package/types/dist/lib/builders/modes-processor.d.mts +32 -0
  62. package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
  63. package/types/dist/lib/errors.d.mts +118 -0
  64. package/types/dist/lib/errors.d.mts.map +1 -0
  65. package/types/dist/lib/factories/component-base.d.mts +182 -0
  66. package/types/dist/lib/factories/component-base.d.mts.map +1 -0
  67. package/types/dist/lib/factories/context.d.mts +26 -0
  68. package/types/dist/lib/factories/context.d.mts.map +1 -0
  69. package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
  70. package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
  71. package/types/dist/lib/handlers/api-manager.d.mts +392 -0
  72. package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
  73. package/types/dist/lib/handlers/context-async.d.mts +66 -0
  74. package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
  75. package/types/dist/lib/handlers/context-live.d.mts +65 -0
  76. package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
  77. package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
  78. package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
  79. package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
  80. package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
  81. package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
  82. package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
  83. package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
  84. package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
  85. package/types/dist/lib/handlers/metadata.d.mts +215 -0
  86. package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
  87. package/types/dist/lib/handlers/ownership.d.mts +170 -0
  88. package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
  89. package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
  90. package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
  91. package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
  92. package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
  93. package/types/dist/lib/helpers/config.d.mts +96 -0
  94. package/types/dist/lib/helpers/config.d.mts.map +1 -0
  95. package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
  96. package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
  97. package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
  98. package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
  99. package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
  100. package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
  101. package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
  102. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
  103. package/types/dist/lib/helpers/sanitize.d.mts +95 -94
  104. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
  105. package/types/dist/lib/helpers/utilities.d.mts +53 -116
  106. package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
  107. package/types/dist/lib/i18n/translations.d.mts +39 -0
  108. package/types/dist/lib/i18n/translations.d.mts.map +1 -0
  109. package/types/dist/lib/modes/eager.d.mts +36 -0
  110. package/types/dist/lib/modes/eager.d.mts.map +1 -0
  111. package/types/dist/lib/modes/lazy.d.mts +49 -0
  112. package/types/dist/lib/modes/lazy.d.mts.map +1 -0
  113. package/types/dist/lib/processors/flatten.d.mts +114 -0
  114. package/types/dist/lib/processors/flatten.d.mts.map +1 -0
  115. package/types/dist/lib/processors/loader.d.mts +47 -0
  116. package/types/dist/lib/processors/loader.d.mts.map +1 -0
  117. package/types/dist/lib/processors/type-generator.d.mts +19 -0
  118. package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
  119. package/types/dist/lib/processors/typescript.d.mts +55 -0
  120. package/types/dist/lib/processors/typescript.d.mts.map +1 -0
  121. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
  122. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  123. package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
  124. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  125. package/types/dist/lib/runtime/runtime.d.mts +39 -9
  126. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  127. package/types/dist/slothlet.d.mts +184 -111
  128. package/types/dist/slothlet.d.mts.map +1 -1
  129. package/types/index.d.mts +1 -3
  130. package/dist/lib/engine/README.md +0 -21
  131. package/dist/lib/engine/slothlet_child.mjs +0 -59
  132. package/dist/lib/engine/slothlet_engine.mjs +0 -372
  133. package/dist/lib/engine/slothlet_esm.mjs +0 -230
  134. package/dist/lib/engine/slothlet_helpers.mjs +0 -455
  135. package/dist/lib/engine/slothlet_worker.mjs +0 -149
  136. package/dist/lib/helpers/als-eventemitter.mjs +0 -256
  137. package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
  138. package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
  139. package/dist/lib/helpers/api_builder/construction.mjs +0 -495
  140. package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
  141. package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
  142. package/dist/lib/helpers/api_builder.mjs +0 -41
  143. package/dist/lib/helpers/auto-wrap.mjs +0 -62
  144. package/dist/lib/helpers/hooks.mjs +0 -389
  145. package/dist/lib/helpers/instance-manager.mjs +0 -111
  146. package/dist/lib/helpers/metadata-api.mjs +0 -201
  147. package/dist/lib/helpers/multidefault.mjs +0 -216
  148. package/dist/lib/modes/slothlet_eager.mjs +0 -154
  149. package/dist/lib/modes/slothlet_lazy.mjs +0 -594
  150. package/docs/API-RULES-CONDITIONS.md +0 -712
  151. package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
  152. package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
  153. package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
  154. package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
  155. package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
  156. package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
  157. package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
  158. package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
  159. package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
  160. package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
  161. package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
  162. package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
  163. package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
  164. package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
  165. package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
  166. package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
  167. package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
  168. package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
  169. package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
  170. package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
  171. package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
  172. package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
  173. package/types/dist/lib/helpers/api_builder.d.mts +0 -6
  174. package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
  175. package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
  176. package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
  177. package/types/dist/lib/helpers/hooks.d.mts +0 -342
  178. package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
  179. package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
  180. package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
  181. package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
  182. package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
  183. package/types/dist/lib/helpers/multidefault.d.mts +0 -90
  184. package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
  185. package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
  186. package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
  187. package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
  188. package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
  189. package/types/index.d.mts.map +0 -1
@@ -0,0 +1,60 @@
1
+ /**
2
+ * API builder class for orchestrating mode-based API construction.
3
+ * @class Builder
4
+ * @extends ComponentBase
5
+ * @package
6
+ *
7
+ * @description
8
+ * Orchestrates API building by delegating to mode-specific builders (eager/lazy).
9
+ * Extends ComponentBase for access to Slothlet configuration and error classes.
10
+ *
11
+ * @example
12
+ * const builder = new Builder(slothlet);
13
+ * const api = await builder.buildAPI({ dir: "./api" });
14
+ */
15
+ export class Builder extends ComponentBase {
16
+ static slothletProperty: string;
17
+ /**
18
+ * Build API from directory or file.
19
+ * @param {Object} options - Build options
20
+ * @param {string} options.dir - Directory or file to build from
21
+ * @param {string} [options.mode="eager"] - Loading mode (eager or lazy)
22
+ * @param {Object} [options.ownership] - Ownership manager (uses slothlet's if not provided)
23
+ * @param {Object} [options.contextManager] - Context manager (uses slothlet's if not provided)
24
+ * @param {string} [options.instanceID] - Instance ID (uses slothlet's if not provided)
25
+ * @param {Object} [options.config] - Configuration (uses slothlet's if not provided)
26
+ * @param {string} [options.apiPathPrefix=""] - Prefix for API paths (for api.add support)
27
+ * @param {string} [options.collisionContext="initial"] - Collision context
28
+ * @param {Function|null} [options.fileFilter=null] - Optional filter function (fileName) => boolean to load specific files only
29
+ * @returns {Promise<Object>} Raw API object (unwrapped)
30
+ * @public
31
+ *
32
+ * @description
33
+ * Validates inputs and delegates to mode-specific builder (buildEagerAPI or buildLazyAPI).
34
+ * When fileFilter is provided, only files matching the filter are loaded.
35
+ *
36
+ * @example
37
+ * const api = await builder.buildAPI({ dir: "./api_tests/api_test", mode: "eager" });
38
+ *
39
+ * @example
40
+ * // Load specific file only
41
+ * const api = await builder.buildAPI({
42
+ * dir: "./api_tests/api_test",
43
+ * mode: "eager",
44
+ * fileFilter: (fileName) => fileName === "math.mjs"
45
+ * });
46
+ */
47
+ public buildAPI(options: {
48
+ dir: string;
49
+ mode?: string;
50
+ ownership?: any;
51
+ contextManager?: any;
52
+ instanceID?: string;
53
+ config?: any;
54
+ apiPathPrefix?: string;
55
+ collisionContext?: string;
56
+ fileFilter?: Function | null;
57
+ }): Promise<any>;
58
+ }
59
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
60
+ //# sourceMappingURL=builder.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.mts","sourceRoot":"","sources":["../../../../dist/lib/builders/builder.mjs"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;GAaG;AACH;IACC,gCAAoC;IAiBpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,yBA3BG;QAAwB,GAAG,EAAnB,MAAM;QACW,IAAI,GAArB,MAAM;QACW,SAAS;QACT,cAAc;QACd,UAAU,GAA3B,MAAM;QACW,MAAM;QACN,aAAa,GAA9B,MAAM;QACW,gBAAgB,GAAjC,MAAM;QACkB,UAAU,GAAlC,WAAS,IAAI;KACrB,GAAU,OAAO,KAAQ,CA+E3B;CACD;8BA9H6B,0CAA0C"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ModesProcessor - Handles mode-specific file and directory processing.
3
+ *
4
+ * @class
5
+ * @extends ComponentBase
6
+ * @package
7
+ */
8
+ export class ModesProcessor extends ComponentBase {
9
+ static slothletProperty: string;
10
+ processFiles(api: any, files: any, directory: any, currentDepth: any, mode: any, isRoot: any, recursive: any, populateDirectly?: boolean, apiPathPrefix?: string, collisionContext?: string, moduleID?: any, sourceFolder?: any, cacheBust?: any, collisionModeOverride?: any): Promise<any>;
11
+ /**
12
+ * Create lazy wrapper for subdirectory (lazy mode only)
13
+ * @param {Object} dir - Directory structure
14
+ * @param {string} apiPath - Current API path
15
+ * @param {Object} config - Configuration
16
+ * @returns {Proxy} Lazy unified wrapper
17
+ * @public
18
+ */
19
+ public createLazySubdirectoryWrapper(dir: any, apiPath: string, moduleID?: any, sourceFolder?: any, cacheBust?: any, fileFolderCollisionImpl?: any, collisionMode?: string): ProxyConstructor;
20
+ /**
21
+ * Apply root contributor pattern - merge API into root function
22
+ * @param {Object} api - API object with properties
23
+ * @param {Function|null} rootFunction - Root contributor function
24
+ * @param {Object} config - Configuration
25
+ * @param {string} mode - Mode name for debug messages
26
+ * @returns {Promise<Object|Function>} Final API (function if root contributor, object otherwise)
27
+ * @public
28
+ */
29
+ public applyRootContributor(api: any, rootFunction: Function | null, mode: string): Promise<any | Function>;
30
+ }
31
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
32
+ //# sourceMappingURL=modes-processor.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modes-processor.d.mts","sourceRoot":"","sources":["../../../../dist/lib/builders/modes-processor.mjs"],"names":[],"mappings":"AA8BA;;;;;;GAMG;AACH;IACC,gCAA2C;IAS3C,6RA+3CC;IACD;;;;;;;OAOG;IACH,wDALW,MAAM,gIA6WhB;IACD;;;;;;;;OAQG;IACH,oDANW,WAAS,IAAI,QAEb,MAAM,GACJ,OAAO,CAAC,cAAe,CAAC,CAoBpC;CACD;8BAjyD6B,0CAA0C"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Custom error class for Slothlet-specific errors with context and i18n
3
+ * @public
4
+ */
5
+ export class SlothletError extends Error {
6
+ /**
7
+ * Create a new SlothletError with automatic translation and hint detection
8
+ * @param {string} code - Error code identifier
9
+ * @param {Object} context - Additional context about the error
10
+ * @param {boolean} [context.validationError] - Mark as validation error (no originalError needed)
11
+ * @param {boolean} [context.stub] - Mark as stub error (not-yet-implemented feature)
12
+ * @param {Error} [originalError] - The original error that caused this SlothletError
13
+ * @param {Object} [options] - Additional options (alternative to embedding flags in context)
14
+ * @param {boolean} [options.validationError] - Mark as validation error (no originalError needed)
15
+ * @param {boolean} [options.stub] - Mark as stub error (not-yet-implemented feature)
16
+ * @public
17
+ */
18
+ constructor(code: string, context?: {
19
+ validationError?: boolean;
20
+ stub?: boolean;
21
+ }, originalError?: Error, options?: {
22
+ validationError?: boolean;
23
+ stub?: boolean;
24
+ });
25
+ /**
26
+ * Prevent JSON serialization of context (cleaner error display)
27
+ * @returns {Object} Simplified error object
28
+ */
29
+ toJSON(): any;
30
+ }
31
+ /**
32
+ * Warning class for non-fatal issues with i18n support
33
+ * @public
34
+ */
35
+ export class SlothletWarning {
36
+ static captured: any[];
37
+ static suppressConsole: boolean;
38
+ /**
39
+ * Clear captured warnings (for testing)
40
+ * @public
41
+ */
42
+ public static clearCaptured(): void;
43
+ /**
44
+ * Create and emit a warning with automatic translation
45
+ * @param {string} code - Warning code identifier
46
+ * @param {Object} context - Additional context about the warning
47
+ * @param {string} [context.key] - Optional translation key override. When provided, this key
48
+ * is used for translation instead of `code`. All other context properties are used as
49
+ * interpolation params. Allows sub-key variants without changing the warning code.
50
+ * @public
51
+ */
52
+ constructor(code: string, context?: {
53
+ key?: string;
54
+ });
55
+ name: string;
56
+ code: string;
57
+ message: string;
58
+ context: {
59
+ key?: string;
60
+ };
61
+ /**
62
+ * Custom string representation
63
+ * @returns {string} Formatted warning string
64
+ */
65
+ toString(): string;
66
+ }
67
+ /**
68
+ * Debug utility class for centralized conditional console output with i18n
69
+ * @public
70
+ */
71
+ export class SlothletDebug {
72
+ /**
73
+ * Create a debug logger instance bound to a config
74
+ * @param {Object} config - Configuration object (typically slothlet.config)
75
+ * @public
76
+ */
77
+ constructor(config?: any);
78
+ config: any;
79
+ debugFlags: any;
80
+ /**
81
+ * Log a debug message if the code's debug flag is enabled
82
+ * @param {string} code - Debug code/category (e.g., "modes", "wrapper", "api")
83
+ * @param {Object} context - Contextual information to display
84
+ * @param {string} [context.key] - Translation key for the message (e.g. "DEBUG_MODE_FLATTENING").
85
+ * When provided, translates via i18n using the remaining context properties as interpolation
86
+ * params - no `await t()` needed at the call site. Falls back to `DEBUG_{CODE}` category key
87
+ * if omitted, then to `context.message` for backwards compatibility.
88
+ * @param {string} [context.message] - Raw message string (backwards-compat fallback).
89
+ * Prefer `context.key` for new call sites so messages are translatable.
90
+ * @public
91
+ *
92
+ * @description
93
+ * Centralized debug logging that respects debug configuration flags.
94
+ * Only outputs when the specified code matches a truthy debug flag.
95
+ * Translates messages using i18n system with the following key resolution order:
96
+ * 1. `context.key` - explicit per-message translation key (preferred)
97
+ * 2. `DEBUG_{CODE}` - category-level key (e.g. DEBUG_MODES)
98
+ * 3. `context.message` - raw string fallback for backwards compatibility
99
+ *
100
+ * @example
101
+ * // Preferred: pass translation key directly - no await needed
102
+ * this.debug("modes", { key: "DEBUG_MODE_FLATTENING", mode, categoryName });
103
+ *
104
+ * @example
105
+ * // Legacy: raw message string (still works, but not translatable)
106
+ * this.debug("wrapper", { message: "Category reuse - using existing wrapper", apiPath });
107
+ */
108
+ public log(code: string, context?: {
109
+ key?: string;
110
+ message?: string;
111
+ }): void;
112
+ /**
113
+ * Custom string representation
114
+ * @returns {string} Debug info
115
+ */
116
+ toString(): string;
117
+ }
118
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../../../dist/lib/errors.mjs"],"names":[],"mappings":"AAqBA;;;GAGG;AACH;IACC;;;;;;;;;;;OAWG;IACH,kBAVW,MAAM,YAEd;QAA0B,eAAe,GAAjC,OAAO;QACW,IAAI,GAAtB,OAAO;KACf,kBAAQ,KAAK,YAEb;QAA0B,eAAe,GAAjC,OAAO;QACW,IAAI,GAAtB,OAAO;KACf,EAkEF;IAoCD;;;OAGG;IACH,cAOC;CACD;AAED;;;GAGG;AACH;IAEC,uBAAqB;IACrB,gCAA+B;IA8C/B;;;OAGG;IACH,oCAEC;IAlDD;;;;;;;;OAQG;IACH,kBAPW,MAAM,YAEd;QAAyB,GAAG,GAApB,MAAM;KAGd,EA2BF;IAjBA,aAA6B;IAC7B,aAAgB;IAChB,gBAAgC;IAChC;cAhBU,MAAM;MAgBM;IAgBvB;;;OAGG;IACH,YAFa,MAAM,CAIlB;CASD;AAED;;;GAGG;AACH;IACC;;;;OAIG;IACH,0BAGC;IAFA,YAAoB;IACpB,gBAAoC;IAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,iBA1BW,MAAM,YAEd;QAAyB,GAAG,GAApB,MAAM;QAIW,OAAO,GAAxB,MAAM;KAEd,QAoDF;IAED;;;OAGG;IACH,YAFa,MAAM,CAMlB;CACD"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * @Project: @cldmv/slothlet
3
+ * @Filename: /src/lib/factories/component-base.mjs
4
+ * @Date: 2026-01-24 09:30:16 -08:00 (1737735016)
5
+ * @Author: Nate Corcoran <CLDMV>
6
+ * @Email: <Shinrai@users.noreply.github.com>
7
+ * -----
8
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
+ * @Last modified time: 2026-03-01 20:21:36 -08:00 (1772425296)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+ /**
14
+ * @fileoverview Base class for Slothlet component classes providing common Slothlet access.
15
+ * @module @cldmv/slothlet/factories/component-base
16
+ * @internal
17
+ * @package
18
+ *
19
+ * @description
20
+ * Provides common getters for all Slothlet component classes (handlers, builders, processors).
21
+ * All components extend this class to access the Slothlet instance's configuration and API
22
+ * references without passing them through function parameters. Components become modular
23
+ * extensions of the Slothlet class itself.
24
+ *
25
+ * @example
26
+ * // ESM
27
+ * import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
28
+ * class MyHandler extends ComponentBase {
29
+ * doSomething() {
30
+ * if (this.debug?.api) {
31
+ * console.log("Debug mode enabled");
32
+ * }
33
+ * throw new this.SlothletError("ERROR_CODE", { details: "info" });
34
+ * }
35
+ * }
36
+ *
37
+ * @example
38
+ * // CJS
39
+ * const { ComponentBase } = require("@cldmv/slothlet/factories/component-base");
40
+ * class MyHandler extends ComponentBase {
41
+ * doSomething() {
42
+ * return this.____config.mode;
43
+ * }
44
+ * }
45
+ */
46
+ /**
47
+ * Base class for Slothlet component classes.
48
+ * @class ComponentBase
49
+ * @package
50
+ *
51
+ * @description
52
+ * Provides common Slothlet property access for handlers, builders, and processors.
53
+ * All component classes should extend this to gain consistent access to the Slothlet
54
+ * instance's configuration, API references, and error classes. Components are instantiated
55
+ * with a reference to the Slothlet class itself, making them modular extensions.
56
+ *
57
+ * @example
58
+ * class ApiManager extends ComponentBase {
59
+ * constructor(slothlet) {
60
+ * super(slothlet);
61
+ * this.state = { addHistory: [] };
62
+ * }
63
+ *
64
+ * someMethod() {
65
+ * if (this.debug?.api) {
66
+ * console.log(`Slothlet: ${this.instanceID}`);
67
+ * }
68
+ * throw new this.SlothletError("INVALID_CONFIG", { reason: "bad input" });
69
+ * }
70
+ * }
71
+ */
72
+ export class ComponentBase {
73
+ /**
74
+ * Complete set of property names reserved by the slothlet framework.
75
+ *
76
+ * @description
77
+ * These keys are either private wrapper internals, read-only info props exposed
78
+ * through the proxy, write-blocked lifecycle keys, or builtin namespace keys
79
+ * injected at the API root level. Used by all components to distinguish framework
80
+ * internals from user-defined properties when:
81
+ * - Collecting user-set custom properties for preservation across reload
82
+ * (`_collectCustomProperties` in api-manager.mjs)
83
+ * - Extracting child keys for impl reconstruction (`_extractFullImpl`)
84
+ * - Determining whether a set(trap) write should be silently absorbed (`setTrap`)
85
+ * - Filtering what getTrap exposes externally on wrapper proxies
86
+ *
87
+ * Note: `_materialize` is included here (skip for collection/extraction) but
88
+ * setTrap exempts it since the framework needs to write it directly.
89
+ *
90
+ * @type {Set<string>}
91
+ * @static
92
+ */
93
+ static INTERNAL_KEYS: Set<string>;
94
+ /**
95
+ * Create a component base instance.
96
+ * @param {object} slothlet - Slothlet class instance.
97
+ * @package
98
+ *
99
+ * @description
100
+ * Stores the Slothlet reference for access via getters. The Slothlet class itself
101
+ * is passed (not a separate "instance" object), making components modular extensions
102
+ * of Slothlet.
103
+ *
104
+ * @example
105
+ * super(slothlet);
106
+ */
107
+ constructor(slothlet: object);
108
+ /**
109
+ * Get Slothlet instance via the canonical internal accessor name.
110
+ * @returns {object} Slothlet instance.
111
+ * @package
112
+ *
113
+ * @description
114
+ * Prototype getter — NOT an own property — so the JS Proxy invariant for
115
+ * non-configurable own properties never applies. UnifiedWrapper's getTrap blocks
116
+ * this name via the underscore-filter before it can reach the getter.
117
+ *
118
+ * @example
119
+ * const s = this.____slothlet;
120
+ */
121
+ get ____slothlet(): object;
122
+ /**
123
+ * Get Slothlet instance (internal access).
124
+ * @returns {object} Slothlet instance.
125
+ * @package
126
+ *
127
+ * @description
128
+ * Provides direct access to the Slothlet instance for legacy code compatibility.
129
+ * Prefer using specific getters (config, helpers, handlers) when possible.
130
+ *
131
+ * @example
132
+ * this.slothlet.debug("api", { action: "assigned" });
133
+ */
134
+ get slothlet(): object;
135
+ /**
136
+ * Get Slothlet configuration.
137
+ * @returns {object} Slothlet configuration object.
138
+ * @package
139
+ *
140
+ * @description
141
+ * Provides access to the Slothlet config for collision modes, debug settings, etc.
142
+ * Named with ____ prefix to avoid shadowing user API names like 'config'.
143
+ *
144
+ * @example
145
+ * const collisionMode = this.____config.collision.api;
146
+ */
147
+ get ____config(): object;
148
+ /**
149
+ * Get Slothlet instance ID.
150
+ * @returns {string} Slothlet instance identifier.
151
+ * @package
152
+ */
153
+ get instanceID(): string;
154
+ /**
155
+ * Get SlothletError class.
156
+ * @returns {Function} SlothletError constructor.
157
+ * @package
158
+ *
159
+ * @description
160
+ * Provides access to SlothletError without importing in every file.
161
+ * Components can throw errors via `new this.SlothletError(...)`.
162
+ *
163
+ * @example
164
+ * throw new this.SlothletError("INVALID_CONFIG", { reason: "missing dir" });
165
+ */
166
+ get SlothletError(): Function;
167
+ /**
168
+ * Get SlothletWarning class.
169
+ * @returns {Function} SlothletWarning constructor.
170
+ * @package
171
+ *
172
+ * @description
173
+ * Provides access to SlothletWarning without importing in every file.
174
+ * Components can issue warnings via `new this.SlothletWarning(...)`.
175
+ *
176
+ * @example
177
+ * new this.SlothletWarning("WARNING_DEPRECATED", { feature: "oldApi" });
178
+ */
179
+ get SlothletWarning(): Function;
180
+ #private;
181
+ }
182
+ //# sourceMappingURL=component-base.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-base.d.mts","sourceRoot":"","sources":["../../../../dist/lib/factories/component-base.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH;IAuHC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,sBAHU,GAAG,CAAC,MAAM,CAAC,CAoClB;IAhKH;;;;;;;;;;;;OAYG;IACH,sBAXW,MAAM,EAahB;IAED;;;;;;;;;;;;OAYG;IACH,oBAXa,MAAM,CAalB;IAED;;;;;;;;;;;OAWG;IACH,gBAVa,MAAM,CAYlB;IAED;;;;;;;;;;;OAWG;IACH,kBAVa,MAAM,CAYlB;IAED;;;;OAIG;IACH,kBAHa,MAAM,CAKlB;IAED;;;;;;;;;;;OAWG;IACH,8BAEC;IAED;;;;;;;;;;;OAWG;IACH,gCAEC;;CAwDD"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Get context manager for specified runtime type
3
+ * @param {string} runtime - Runtime type ("async" or "live")
4
+ * @returns {Object} Context manager instance
5
+ * @public
6
+ */
7
+ export function getContextManager(runtime?: string): any;
8
+ /**
9
+ * Default context manager (async)
10
+ * @public
11
+ */
12
+ export const contextManager: import("@cldmv/slothlet/handlers/context-async").AsyncContextManager;
13
+ /**
14
+ * Async runtime for runtime exports
15
+ * @public
16
+ */
17
+ export const asyncRuntime: import("@cldmv/slothlet/handlers/context-async").AsyncContextManager;
18
+ /**
19
+ * Live runtime for runtime exports
20
+ * @public
21
+ */
22
+ export const liveRuntime: import("@cldmv/slothlet/handlers/context-live").LiveContextManager;
23
+ import { asyncContextManager } from "@cldmv/slothlet/handlers/context-async";
24
+ import { liveContextManager } from "@cldmv/slothlet/handlers/context-live";
25
+ export { asyncContextManager, liveContextManager };
26
+ //# sourceMappingURL=context.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.mts","sourceRoot":"","sources":["../../../../dist/lib/factories/context.mjs"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,4CAJW,MAAM,OAMhB;AAED;;;GAGG;AACH,kGAAkD;AAElD;;;GAGG;AACH,gGAAgD;AAEhD;;;GAGG;AACH,6FAA8C;oCA7BV,wCAAwC;mCACzC,uCAAuC"}
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Cache entry structure for API tree storage and rebuild parameters.
3
+ * @typedef {Object} CacheEntry
4
+ * @property {string} endpoint - API path endpoint (e.g., ".", "plugins")
5
+ * @property {string} moduleID - Module identifier
6
+ * @property {Object} api - Complete buildAPI result tree (primary storage)
7
+ * @property {string} folderPath - Source folder path
8
+ * @property {string} mode - Loading mode: 'lazy' or 'eager'
9
+ * @property {Object} sanitizeOptions - Sanitization configuration
10
+ * @property {string} collisionMode - Collision handling mode
11
+ * @property {Object} config - Config snapshot at add time
12
+ * @property {number} timestamp - Cache creation time (Unix ms)
13
+ */
14
+ /**
15
+ * Manages API caches - complete buildAPI results per moduleID
16
+ * @class ApiCacheManager
17
+ * @extends ComponentBase
18
+ * @public
19
+ *
20
+ * @description
21
+ * Stores complete API trees for each moduleID with all rebuild parameters.
22
+ * The cache is the PRIMARY storage - live API references cached trees.
23
+ * Enables hot reload by rebuilding caches from disk and updating live references.
24
+ *
25
+ * @example
26
+ * const cacheManager = new ApiCacheManager(slothlet);
27
+ * cacheManager.set("module_abc", { api: tree, folderPath: "./plugins", ... });
28
+ */
29
+ export class ApiCacheManager extends ComponentBase {
30
+ static slothletProperty: string;
31
+ /**
32
+ * Cache storage - moduleID → CacheEntry
33
+ * @type {Map<string, CacheEntry>}
34
+ * @private
35
+ */
36
+ private caches;
37
+ /**
38
+ * Store cache entry for moduleID
39
+ * @param {string} moduleID - Module identifier
40
+ * @param {CacheEntry} entry - Cache entry with api tree and rebuild parameters
41
+ * @returns {void}
42
+ * @public
43
+ *
44
+ * @description
45
+ * Stores complete buildAPI result. The cached API tree becomes the source of truth.
46
+ * Existing references should point to entry.api, not copy it.
47
+ *
48
+ * @example
49
+ * cache.set("base_abc123", {
50
+ * endpoint: ".",
51
+ * moduleID: "base_abc123",
52
+ * api: apiTree,
53
+ * folderPath: this.____config.dir,
54
+ * mode: "lazy",
55
+ * sanitizeOptions: {},
56
+ * collisionMode: "merge",
57
+ * config: {...this.____config},
58
+ * timestamp: Date.now()
59
+ * });
60
+ */
61
+ public set(moduleID: string, entry: CacheEntry): void;
62
+ /**
63
+ * Get cache entry by moduleID
64
+ * @param {string} moduleID - Module identifier
65
+ * @returns {CacheEntry|undefined} Cache entry or undefined if not found
66
+ * @public
67
+ *
68
+ * @example
69
+ * const cache = cacheManager.get("base_abc123");
70
+ * if (cache) {
71
+ * const api = cache.api; // Get API tree from cache
72
+ * }
73
+ */
74
+ public get(moduleID: string): CacheEntry | undefined;
75
+ /**
76
+ * Check if cache exists for moduleID
77
+ * @param {string} moduleID - Module identifier
78
+ * @returns {boolean} True if cache exists
79
+ * @public
80
+ *
81
+ * @example
82
+ * if (cacheManager.has("base_abc123")) {
83
+ * // Cache exists
84
+ * }
85
+ */
86
+ public has(moduleID: string): boolean;
87
+ /**
88
+ * Delete cache entry by moduleID
89
+ * @param {string} moduleID - Module identifier
90
+ * @returns {boolean} True if cache was deleted
91
+ * @public
92
+ *
93
+ * @description
94
+ * Removes cache entry. Should be called when module is removed via api.remove(moduleID).
95
+ *
96
+ * @example
97
+ * cacheManager.delete("plugins_abc123");
98
+ */
99
+ public delete(moduleID: string): boolean;
100
+ /**
101
+ * Get all moduleIDs in cache
102
+ * @returns {string[]} Array of moduleIDs
103
+ * @public
104
+ *
105
+ * @example
106
+ * const moduleIDs = cacheManager.getAllModuleIDs();
107
+ * // ["base_abc123", "plugins_xyz789", ...]
108
+ */
109
+ public getAllModuleIDs(): string[];
110
+ /**
111
+ * Get cache diagnostics
112
+ * @returns {object} Diagnostic information
113
+ * @public
114
+ *
115
+ * @description
116
+ * Returns diagnostic data about cached modules. Available under api.slothlet.diag.caches
117
+ * when config.debug.diagnostics is enabled.
118
+ *
119
+ * @example
120
+ * const diag = cacheManager.getCacheDiagnostics();
121
+ * // {
122
+ * // totalCaches: 3,
123
+ * // caches: [
124
+ * // { moduleID: "base_abc123", endpoint: ".", pathCount: 42, timestamp: ... },
125
+ * // ...
126
+ * // ]
127
+ * // }
128
+ */
129
+ public getCacheDiagnostics(): object;
130
+ /**
131
+ * Count API paths in a tree
132
+ * @param {object} api - API tree
133
+ * @param {WeakSet} [visited] - Visited objects (prevent circular refs)
134
+ * @returns {number} Number of paths
135
+ * @private
136
+ */
137
+ private _countPaths;
138
+ /**
139
+ * Clear all caches
140
+ * @returns {void}
141
+ * @public
142
+ *
143
+ * @description
144
+ * Removes all cache entries. Used during shutdown or full reload.
145
+ *
146
+ * @example
147
+ * cacheManager.clear();
148
+ */
149
+ public clear(): void;
150
+ /**
151
+ * Rebuild cache from disk by calling buildAPI with stored parameters
152
+ * @param {string} moduleID - Module identifier to rebuild
153
+ * @returns {Promise<object>} Fresh API tree from buildAPI
154
+ * @public
155
+ *
156
+ * @description
157
+ * Reloads module source files and rebuilds API tree. Does NOT update cache -
158
+ * caller must call set() with fresh tree. Returns the new API tree.
159
+ *
160
+ * @example
161
+ * const freshApi = await cacheManager.rebuildCache("plugins_abc123");
162
+ * cacheManager.set("plugins_abc123", { ...existingEntry, api: freshApi, timestamp: Date.now() });
163
+ */
164
+ public rebuildCache(moduleID: string): Promise<object>;
165
+ }
166
+ /**
167
+ * Cache entry structure for API tree storage and rebuild parameters.
168
+ */
169
+ export type CacheEntry = {
170
+ /**
171
+ * - API path endpoint (e.g., ".", "plugins")
172
+ */
173
+ endpoint: string;
174
+ /**
175
+ * - Module identifier
176
+ */
177
+ moduleID: string;
178
+ /**
179
+ * - Complete buildAPI result tree (primary storage)
180
+ */
181
+ api: any;
182
+ /**
183
+ * - Source folder path
184
+ */
185
+ folderPath: string;
186
+ /**
187
+ * - Loading mode: 'lazy' or 'eager'
188
+ */
189
+ mode: string;
190
+ /**
191
+ * - Sanitization configuration
192
+ */
193
+ sanitizeOptions: any;
194
+ /**
195
+ * - Collision handling mode
196
+ */
197
+ collisionMode: string;
198
+ /**
199
+ * - Config snapshot at add time
200
+ */
201
+ config: any;
202
+ /**
203
+ * - Cache creation time (Unix ms)
204
+ */
205
+ timestamp: number;
206
+ };
207
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
208
+ //# sourceMappingURL=api-cache-manager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-cache-manager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/api-cache-manager.mjs"],"names":[],"mappings":"AAoCA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;GAcG;AACH;IACC,gCAA4C;IAU3C;;;;OAIG;IACH,eAAuB;IAGxB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,qBAtBW,MAAM,SACN,UAAU,GACR,IAAI,CAyDhB;IAED;;;;;;;;;;;OAWG;IACH,qBAVW,MAAM,GACJ,UAAU,GAAC,SAAS,CAWhC;IAED;;;;;;;;;;OAUG;IACH,qBATW,MAAM,GACJ,OAAO,CAUnB;IAED;;;;;;;;;;;OAWG;IACH,wBAVW,MAAM,GACJ,OAAO,CAoBnB;IAED;;;;;;;;OAQG;IACH,0BAPa,MAAM,EAAE,CASpB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,8BAjBa,MAAM,CAsClB;IAED;;;;;;OAMG;IACH,oBAsBC;IAED;;;;;;;;;;OAUG;IACH,gBATa,IAAI,CAehB;IAED;;;;;;;;;;;;;OAaG;IACH,8BAZW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CA8D3B;CACD;;;;;;;;cA/Ua,MAAM;;;;cACN,MAAM;;;;;;;;gBAEN,MAAM;;;;UACN,MAAM;;;;;;;;mBAEN,MAAM;;;;;;;;eAEN,MAAM;;8BAbU,0CAA0C"}