@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,170 @@
1
+ /**
2
+ * Summary result of an unregister operation.
3
+ * @typedef {Object} UnregisterResult
4
+ * @property {string[]} removed - API paths that were removed.
5
+ * @property {Object[]} rolledBack - Entries that were rolled back to a previous owner.
6
+ */
7
+ /**
8
+ * Tracks which modules own which API paths for hot reload and rollback
9
+ * @class OwnershipManager
10
+ * @extends ComponentBase
11
+ * @public
12
+ */
13
+ export class OwnershipManager extends ComponentBase {
14
+ static slothletProperty: string;
15
+ constructor(slothlet: any);
16
+ moduleToPath: Map<any, any>;
17
+ pathToModule: Map<any, any>;
18
+ _unregisteredModules: Set<any>;
19
+ /**
20
+ * Register module ownership of API path with its value
21
+ * @param {Object} options - Registration options
22
+ * @param {string} options.moduleID - Module identifier
23
+ * @param {string} options.apiPath - API path being registered
24
+ * @param {*} options.value - The actual function/object being registered
25
+ * @param {string} [options.source="core"] - Source of registration
26
+ * @param {string} [options.collisionMode="error"] - Collision mode: skip, warn, error, merge, replace
27
+ * @param {Object} [options.config] - Config object for silent mode check
28
+ * @param {string} [options.filePath=null] - File path of the module source (for metadata tracking)
29
+ * @returns {Object|null} Registration entry or null if skipped
30
+ * @public
31
+ */
32
+ public register({ moduleID, apiPath, value, source, collisionMode, config, filePath }: {
33
+ moduleID: string;
34
+ apiPath: string;
35
+ value: any;
36
+ source?: string;
37
+ collisionMode?: string;
38
+ config?: any;
39
+ filePath?: string;
40
+ }): any | null;
41
+ /**
42
+ * @param {string} moduleID - Module to unregister.
43
+ * @returns {UnregisterResult} Removal summary.
44
+ * @public
45
+ *
46
+ * @description
47
+ * Removes all paths owned by the provided moduleID and reports removals and rollbacks.
48
+ *
49
+ * @example
50
+ * const result = ownership.unregister("module-a");
51
+ */
52
+ public unregister(moduleID: string): UnregisterResult;
53
+ /**
54
+ * @param {string} apiPath - API path to modify.
55
+ * @param {string|null} [moduleID=null] - Module to remove (defaults to current owner).
56
+ * @returns {{ action: "delete"|"none"|"restore", removedModuleId: string|null,
57
+ * restoreModuleId: string|null }} Action taken for the path.
58
+ * @public
59
+ *
60
+ * @description
61
+ * Removes a module owner from a specific API path. If the current owner is removed and
62
+ * previous owners exist, the path is restored to the previous owner.
63
+ *
64
+ * @example
65
+ * const result = ownership.removePath("plugins.tools", "module-a");
66
+ */
67
+ public removePath(apiPath: string, moduleID?: string | null): {
68
+ action: "delete" | "none" | "restore";
69
+ removedModuleId: string | null;
70
+ restoreModuleId: string | null;
71
+ };
72
+ /**
73
+ * Get current owner of API path
74
+ * @param {string} apiPath - API path to check
75
+ * @returns {Object|null} Current owner entry or null
76
+ * @public
77
+ */
78
+ public getCurrentOwner(apiPath: string): any | null;
79
+ /**
80
+ * Get current value for API path
81
+ * @param {string} apiPath - API path to check
82
+ * @returns {*} Current value or undefined
83
+ * @public
84
+ */
85
+ public getCurrentValue(apiPath: string): any;
86
+ /**
87
+ * Get all paths owned by module
88
+ * @param {string} moduleID - Module to query
89
+ * @returns {Array<string>} Array of API paths
90
+ * @public
91
+ */
92
+ public getModulePaths(moduleID: string): Array<string>;
93
+ /**
94
+ * Get ownership history for path
95
+ * @param {string} apiPath - API path to query
96
+ * @returns {Array<Object>} Ownership history stack
97
+ * @public
98
+ */
99
+ public getPathHistory(apiPath: string): Array<any>;
100
+ /**
101
+ * Check if module owns path
102
+ * @param {string} moduleID - Module to check
103
+ * @param {string} apiPath - API path to check
104
+ * @returns {boolean} True if module owns path
105
+ * @public
106
+ */
107
+ public ownsPath(moduleID: string, apiPath: string): boolean;
108
+ /**
109
+ * Get diagnostic info about ownership
110
+ * @returns {Object} Diagnostic information
111
+ * @public
112
+ */
113
+ public getDiagnostics(): any;
114
+ /**
115
+ * Get ownership info for a specific API path
116
+ * @param {string} apiPath - API path to check
117
+ * @returns {Set<string>|null} Set of moduleIDs that own this path, or null if path not found
118
+ * @public
119
+ */
120
+ public getPathOwnership(apiPath: string): Set<string> | null;
121
+ /**
122
+ * Recursively register API subtree with ownership
123
+ * @param {object} api - API object or subtree
124
+ * @param {string} moduleID - Module identifier (owner)
125
+ * @param {string} path - Current API path
126
+ * @param {WeakSet} [visited] - Visited objects (prevents circular refs)
127
+ * @returns {void}
128
+ * @public
129
+ *
130
+ * @description
131
+ * Registers entire API subtree structure with ownership manager.
132
+ * Used during load, reload, and api.add to establish ownership relationships.
133
+ *
134
+ * @example
135
+ * ownership.registerSubtree(api, "base_abc123", "");
136
+ */
137
+ public registerSubtree(api: object, moduleID: string, path: string, visited?: WeakSet<any>): void;
138
+ /**
139
+ * Clear all ownership data
140
+ * @public
141
+ */
142
+ public clear(): void;
143
+ /**
144
+ * Export ownership state for preservation during reload
145
+ * @returns {Object} Serializable ownership state
146
+ * @public
147
+ */
148
+ public exportState(): any;
149
+ /**
150
+ * Import ownership state from exported data
151
+ * @param {Object} state - Previously exported state
152
+ * @public
153
+ */
154
+ public importState(state: any): void;
155
+ }
156
+ /**
157
+ * Summary result of an unregister operation.
158
+ */
159
+ export type UnregisterResult = {
160
+ /**
161
+ * - API paths that were removed.
162
+ */
163
+ removed: string[];
164
+ /**
165
+ * - Entries that were rolled back to a previous owner.
166
+ */
167
+ rolledBack: any[];
168
+ };
169
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
170
+ //# sourceMappingURL=ownership.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ownership.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/ownership.mjs"],"names":[],"mappings":"AAqBA;;;;;GAKG;AAEH;;;;;GAKG;AACH;IACC,gCAAsC;IAEtC,2BAKC;IAHA,4BAA6B;IAC7B,4BAA6B;IAC7B,+BAAqC;IAGtC;;;;;;;;;;;;OAYG;IACH,uFAVG;QAAwB,QAAQ,EAAxB,MAAM;QACU,OAAO,EAAvB,MAAM;QACK,KAAK,EAAhB,GAAC;QACgB,MAAM,GAAvB,MAAM;QACW,aAAa,GAA9B,MAAM;QACW,MAAM;QACN,QAAQ,GAAzB,MAAM;KACd,GAAU,MAAO,IAAI,CAsFvB;IAED;;;;;;;;;;OAUG;IACH,4BAVW,MAAM,GACJ,gBAAgB,CAsC5B;IAED;;;;;;;;;;;;;OAaG;IACH,2BAbW,MAAM,aACN,MAAM,GAAC,IAAI,GACT;QAAE,MAAM,EAAE,QAAQ,GAAC,MAAM,GAAC,SAAS,CAAC;QAAC,eAAe,EAAE,MAAM,GAAC,IAAI,CAAC;QAC5E,eAAe,EAAE,MAAM,GAAC,IAAI,CAAA;KAAE,CA4ChC;IAED;;;;;OAKG;IACH,gCAJW,MAAM,GACJ,MAAO,IAAI,CAOvB;IAED;;;;;OAKG;IACH,gCAJW,MAAM,GACJ,GAAC,CAkBb;IAED;;;;;OAKG;IACH,gCAJW,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAKzB;IAED;;;;;OAKG;IACH,+BAJW,MAAM,GACJ,KAAK,KAAQ,CAKzB;IAED;;;;;;OAMG;IACH,0BALW,MAAM,WACN,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,6BAeC;IAED;;;;;OAKG;IACH,iCAJW,MAAM,GACJ,GAAG,CAAC,MAAM,CAAC,GAAC,IAAI,CAS5B;IAED;;;;;;;;;;;;;;;OAeG;IACH,4BAdW,MAAM,YACN,MAAM,QACN,MAAM,2BAEJ,IAAI,CAwDhB;IAED;;;OAGG;IACH,qBAIC;IAED;;;;OAIG;IACH,0BAKC;IAED;;;;OAIG;IACH,qCAaC;CACD;;;;;;;;aAlaa,MAAM,EAAE;;;;gBACR,KAAQ;;8BAPQ,0CAA0C"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Resolves a value to its backing UnifiedWrapper instance.
3
+ * Accepts a proxy registered via createProxy() or a raw UnifiedWrapper instance.
4
+ * Returns null for any other value.
5
+ *
6
+ * @param {unknown} value - Value to resolve
7
+ * @returns {UnifiedWrapper|null} The backing wrapper, or null
8
+ *
9
+ * @example
10
+ * const wrapper = resolveWrapper(someProxy);
11
+ * if (wrapper) wrapper.____slothletInternal.impl = newImpl;
12
+ */
13
+ export function resolveWrapper(value: unknown): UnifiedWrapper | null;
14
+ export namespace TYPE_STATES {
15
+ let UNMATERIALIZED: symbol;
16
+ let IN_FLIGHT: symbol;
17
+ }
18
+ /**
19
+ * Unified wrapper class that handles all proxy concerns in one place:
20
+ * - __impl pattern for reload support
21
+ * - Lazy/eager mode materialization
22
+ * - Recursive waiting proxy for deep lazy loading
23
+ * - Context binding through contextManager
24
+ *
25
+ * @class
26
+ * @extends ComponentBase
27
+ * @public
28
+ */
29
+ export class UnifiedWrapper extends ComponentBase {
30
+ /**
31
+ * Shallow-clone a non-Proxy object implementation to prevent ___adoptImplChildren
32
+ * from mutating shared module export references via its `delete this.____slothletInternal.impl[key]`
33
+ * operations. When concurrent materializations (e.g., old + new wrapper during reload)
34
+ * both load the same cached module, the first ___adoptImplChildren would destroy the
35
+ * shared export, causing subsequent wrappers to receive empty objects.
36
+ *
37
+ * Returns the value unchanged if it is not a plain object, or if it IS a Proxy
38
+ * (cloning a Proxy destroys its trap behavior - e.g., LG TV controllers using
39
+ * numeric-index access through custom get traps).
40
+ *
41
+ * @param {*} value - The implementation value to (maybe) clone.
42
+ * @returns {*} A shallow clone of `value` when it is a non-Proxy plain object,
43
+ * otherwise the original `value`.
44
+ * @static
45
+ * @private
46
+ */
47
+ private static _cloneImpl;
48
+ /**
49
+ * Reconstruct a full implementation object from a wrapper whose _impl may have
50
+ * been depleted by ___adoptImplChildren.
51
+ *
52
+ * @description
53
+ * After ___adoptImplChildren runs, children are moved from _impl onto the wrapper as
54
+ * own properties and deleted from _impl. This helper reconstructs the original
55
+ * impl by merging the remaining _impl keys with the adopted children extracted
56
+ * from the wrapper.
57
+ *
58
+ * Recursively walks the wrapper tree so nested objects whose _impl was also
59
+ * depleted are properly reconstructed. For callable (function) impls, returns
60
+ * the function directly since keepImplProperties prevents depletion.
61
+ *
62
+ * @param {Object} wrapper - The UnifiedWrapper instance to extract from
63
+ * @returns {*} The reconstructed implementation mirroring original module exports
64
+ * @static
65
+ * @private
66
+ */
67
+ private static _extractFullImpl;
68
+ /**
69
+ * @param {Object} slothlet - Slothlet instance (provides contextManager, instanceID, ownership)
70
+ * @param {Object} options - Configuration options
71
+ * @param {string} options.mode - "lazy" or "eager"
72
+ * @param {string} options.apiPath - API path for this wrapper (e.g., "math.advanced.calc")
73
+ * @param {Object} [options.initialImpl=null] - Initial implementation (null for lazy mode)
74
+ * @param {Function} [options.materializeFunc=null] - Async function to materialize lazy modules
75
+ * @param {boolean} [options.isCallable=false] - Whether the wrapper should be callable
76
+ * @param {boolean} [options.materializeOnCreate=false] - Whether to materialize on creation
77
+ * @param {string} [options.filePath=null] - File path of the module source
78
+ * @param {string} [options.moduleID=null] - Module identifier
79
+ * @param {string} [options.sourceFolder=null] - Source folder for metadata
80
+ *
81
+ * @description
82
+ * Creates a unified wrapper instance for a specific API path. Extends ComponentBase
83
+ * to access slothlet.contextManager, slothlet.instanceID, and slothlet.handlers.ownership.
84
+ *
85
+ * @example
86
+ * const wrapper = new UnifiedWrapper(this.slothlet, {
87
+ * mode: "lazy",
88
+ * apiPath: "math",
89
+ * initialImpl: null,
90
+ * materializeFunc: async () => import("./math.mjs")
91
+ * });
92
+ */
93
+ constructor(slothlet: any, { mode, apiPath, initialImpl, materializeFunc, isCallable, materializeOnCreate, filePath, moduleID, sourceFolder }: {
94
+ mode: string;
95
+ apiPath: string;
96
+ initialImpl?: any;
97
+ materializeFunc?: Function;
98
+ isCallable?: boolean;
99
+ materializeOnCreate?: boolean;
100
+ filePath?: string;
101
+ moduleID?: string;
102
+ sourceFolder?: string;
103
+ });
104
+ /**
105
+ * Internal state accessor used by framework-internal code only.
106
+ * Backed by the private `#internal` field - prototype property, not an own property,
107
+ * so proxy invariants never apply and getTrap can legally return undefined for it.
108
+ *
109
+ * Uses a private-field brand check (`#internal in this`) so the getter is safe to
110
+ * invoke with any receiver - including `UnifiedWrapper.prototype` itself during a
111
+ * prototype chain walk via `Object.getPrototypeOf` - without throwing a TypeError.
112
+ * Without the brand check, `Object.getPrototypeOf(proxy).____slothletInternal` would
113
+ * throw because the prototype object was never constructed and has no `#internal` field.
114
+ * @returns {Object|undefined} Internal state container, or undefined for non-instances
115
+ */
116
+ get ____slothletInternal(): any | undefined;
117
+ /**
118
+ * Get current implementation
119
+ * @returns {Object|null} Current __impl value
120
+ * @public
121
+ */
122
+ public get __impl(): any | null;
123
+ /**
124
+ * Core implementation-application logic shared by ___setImpl and lazy materialization.
125
+ * Clones the implementation (protecting the API cache from ___adoptImplChildren's
126
+ * delete operations), clears the invalid flag, upgrades __isCallable when a
127
+ * callable impl arrives on a configurable wrapper, updates __filePath for lazy
128
+ * folder wrappers, and adopts children.
129
+ *
130
+ * @param {*} newImpl - The new implementation value.
131
+ * @param {boolean} [forceReuseChildren=false] - When true, always reuse existing child
132
+ * wrappers regardless of mode (used by ___setImpl to preserve live references).
133
+ * @private
134
+ */
135
+ private _applyNewImpl;
136
+ /**
137
+ * Set new implementation and adopt children.
138
+ * Delegates core impl work to _applyNewImpl, then emits lifecycle events
139
+ * and updates materialization state.
140
+ *
141
+ * @param {*} newImpl - New implementation
142
+ * @param {string} [moduleID] - Optional moduleID for lifecycle event (for replacements)
143
+ * @param {boolean} [forceReuseChildren=false] - When true, always reuse existing child
144
+ * wrappers and bypass collision-merged key guards. Use this for direct/explicit
145
+ * ___setImpl calls where reference preservation is the intent. Do NOT set for
146
+ * hot-reload paths (syncWrapper) where lazy refs should intentionally break.
147
+ * @private
148
+ */
149
+ private ___setImpl;
150
+ /**
151
+ * Reset wrapper to un-materialized lazy state with a fresh materialization function.
152
+ * Used during reload to restore lazy wrappers to their shell state instead of
153
+ * eagerly loading all implementations. Preserves proxy identity so existing
154
+ * references continue to work - next property access triggers materialization
155
+ * from the fresh materializeFunc (which reads updated source files from disk).
156
+ * @param {Function} newMaterializeFunc - Fresh materialization function from rebuild
157
+ * @returns {void}
158
+ * @private
159
+ */
160
+ private ___resetLazy;
161
+ /**
162
+ * Trigger materialization (lazy mode only)
163
+ * @returns {Promise<void>}
164
+ * @private
165
+ */
166
+ private ___materialize;
167
+ /**
168
+ * @private
169
+ * @returns {Promise<void>}
170
+ *
171
+ * @description
172
+ * Exposes lazy materialization for waiting proxies and nested wrappers.
173
+ *
174
+ * @example
175
+ * await wrapper._materialize();
176
+ */
177
+ private _materialize;
178
+ /**
179
+ * @private
180
+ * @returns {void}
181
+ *
182
+ * @description
183
+ * Invalidates this wrapper when its parent removes the API path.
184
+ *
185
+ * @example
186
+ * wrapper.___invalidate();
187
+ */
188
+ private ___invalidate;
189
+ /**
190
+ * @private
191
+ * @returns {void}
192
+ *
193
+ * @description
194
+ * Moves child properties off the impl and attaches them to wrapper as properties
195
+ * so this wrapper only represents the current API path.
196
+ *
197
+ * @example
198
+ * wrapper.___adoptImplChildren();
199
+ */
200
+ private ___adoptImplChildren;
201
+ /**
202
+ * @private
203
+ * @param {string|symbol} key - Child property name
204
+ * @param {unknown} value - Child value
205
+ * @returns {Object|Function|undefined} Wrapped child proxy when applicable
206
+ *
207
+ * @description
208
+ * Creates a child wrapper for impl values, including primitives.
209
+ *
210
+ * @example
211
+ * const child = wrapper.___createChildWrapper("add", fn);
212
+ */
213
+ private ___createChildWrapper;
214
+ /**
215
+ * Create recursive waiting proxy for deep lazy loading
216
+ * Builds property chain (e.g., ["advanced", "calc", "power"]) and waits for all parent
217
+ * wrappers to materialize before accessing the final property.
218
+ *
219
+ * Waiting proxies are ONLY created when not materialized or in-flight.
220
+ * Once materialized, we return actual cached values, not waiting proxies.
221
+ * Therefore, waiting proxies always represent in-flight/unmaterialized state.
222
+ *
223
+ * CRITICAL: Caches waiting proxies by propChain key to ensure subsequent accesses
224
+ * return the SAME proxy object, which can then delegate once materialization completes.
225
+ * This matches v2's propertyProxyCache behavior.
226
+ *
227
+ * @private
228
+ * @param {Array<string|symbol>} [propChain=[]] - Property chain to resolve.
229
+ * @returns {Proxy} Proxy that waits for materialization before applying calls.
230
+ */
231
+ private ___createWaitingProxy;
232
+ /**
233
+ * Create main proxy for this wrapper
234
+ * Handles lazy/eager mode logic, property access, and context binding
235
+ *
236
+ * @returns {Proxy} Main proxy for API
237
+ * @public
238
+ */
239
+ public createProxy(): ProxyConstructor;
240
+ lastSyncError: any;
241
+ /**
242
+ * Custom inspect output for Node.js util.inspect.
243
+ * @returns {*} The actual implementation for inspection.
244
+ */
245
+ [util.inspect.custom](____depth: any, ____options: any, ____inspect: any): any;
246
+ #private;
247
+ }
248
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
249
+ import util from "node:util";
250
+ //# sourceMappingURL=unified-wrapper.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified-wrapper.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/unified-wrapper.mjs"],"names":[],"mappings":"AAquGA;;;;;;;;;;;GAWG;AACH,sCAPW,OAAO,GACL,cAAc,GAAC,IAAI,CAkB/B;;;;;AAjpGD;;;;;;;;;;GAUG;AACH;IAiQC;;;;;;;;;;;;;;;;OAgBG;IACH,0BA8BC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,gCA0DC;IApWD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,+IAtBG;QAAwB,IAAI,EAApB,MAAM;QACU,OAAO,EAAvB,MAAM;QACW,WAAW;QACT,eAAe;QAChB,UAAU,GAA5B,OAAO;QACW,mBAAmB,GAArC,OAAO;QACU,QAAQ,GAAzB,MAAM;QACW,QAAQ,GAAzB,MAAM;QACW,YAAY,GAA7B,MAAM;KAEd,EA4KF;IA1MD;;;;;;;;;;;OAWG;IACH,4BAFa,MAAO,SAAS,CAK5B;IA+ND;;;;OAIG;IACH,qBAHa,MAAO,IAAI,CAKvB;IAkID;;;;;;;;;;;OAWG;IACH,sBAiCC;IAED;;;;;;;;;;;;OAYG;IACH,mBAgDC;IAED;;;;;;;;;OASG;IACH,qBAmDC;IAED;;;;OAIG;IACH,uBA+FC;IAED;;;;;;;;;OASG;IACH,qBAEC;IAED;;;;;;;;;OASG;IACH,sBAiBC;IAED;;;;;;;;;;OAUG;IACH,6BAmbC;IAED;;;;;;;;;;;OAWG;IACH,8BAwIC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,8BA8oBC;IAED;;;;;;OAMG;IACH,uCA8qCC;IAjVE,mBAA0B;IApkF7B;;;OAGG;IACH,2EAFa,GAAC,CA8Bb;;CAs3FD;8BA7sG6B,0CAA0C;iBADvD,WAAW"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @function runtime_shouldWrapMethod
3
+ * @package
4
+ * @param {*} value - The value to check
5
+ * @param {string|symbol} prop - The property name
6
+ * @returns {boolean} True if the method should be wrapped
7
+ *
8
+ * @description
9
+ * Determines if a method should be wrapped with context preservation.
10
+ * Excludes constructors, Object.prototype methods, and internal methods.
11
+ *
12
+ * @example
13
+ * runtime_shouldWrapMethod(myInstance.method, "method"); // true
14
+ * runtime_shouldWrapMethod(myInstance.constructor, "constructor"); // false
15
+ */
16
+ export function runtime_shouldWrapMethod(value: any, prop: string | symbol): boolean;
17
+ /**
18
+ * @function runtime_isClassInstance
19
+ * @package
20
+ * @param {*} val - The value to check
21
+ * @returns {boolean} True if the value is a class instance that should be wrapped
22
+ *
23
+ * @description
24
+ * Determines if a value is a class instance (not a plain object, array, or primitive)
25
+ * that should have its methods wrapped to preserve AsyncLocalStorage context.
26
+ * Uses systematic exclusion lists for better maintainability.
27
+ *
28
+ * @example
29
+ * // Check if value is a class instance
30
+ * const isInstance = runtime_isClassInstance(new MyClass());
31
+ */
32
+ export function runtime_isClassInstance(val: any): boolean;
33
+ /**
34
+ * @function runtime_wrapClassInstance
35
+ * @package
36
+ * @param {object} instance - The class instance to wrap
37
+ * @param {object} contextManager - The context manager (async or live)
38
+ * @param {string} instanceID - The slothlet instance ID
39
+ * @param {WeakMap} instanceCache - The cache for wrapped instances
40
+ * @returns {Proxy} A proxied instance with context-aware method calls
41
+ *
42
+ * @description
43
+ * Wraps a class instance so that all method calls maintain the AsyncLocalStorage context.
44
+ * This ensures that calls to methods on returned class instances preserve the slothlet
45
+ * context for runtime imports like `self` and `context`.
46
+ *
47
+ * V3 Adaptation: Uses contextManager.runInContext() instead of V2's runWithCtx().
48
+ *
49
+ * @example
50
+ * // Wrap a class instance to preserve context
51
+ * const wrappedInstance = runtime_wrapClassInstance(instance, contextManager, instanceID, instanceCache);
52
+ */
53
+ export function runtime_wrapClassInstance(instance: object, contextManager: object, instanceID: string, instanceCache: WeakMap<any, any>): ProxyConstructor;
54
+ //# sourceMappingURL=class-instance-wrapper.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class-instance-wrapper.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/class-instance-wrapper.mjs"],"names":[],"mappings":"AA0CA;;;;;;;;;;;;;;GAcG;AACH,gDAZW,GAAC,QACD,MAAM,GAAC,MAAM,GACX,OAAO,CAkBnB;AAED;;;;;;;;;;;;;;GAcG;AACH,6CAZW,GAAC,GACC,OAAO,CA6BnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oDAjBW,MAAM,kBACN,MAAM,cACN,MAAM,sDA8EhB"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Configuration normalization utilities
3
+ * @class Config
4
+ * @extends ComponentBase
5
+ * @public
6
+ */
7
+ export class Config extends ComponentBase {
8
+ static slothletProperty: string;
9
+ /**
10
+ * Normalize collision configuration for handling property collisions
11
+ * @param {string|Object} collision - Collision mode or object with per-context modes
12
+ * @returns {Object} Normalized collision configuration with initial and api.slothlet.api.add modes
13
+ * @public
14
+ *
15
+ * @description
16
+ * Normalizes collision handling configuration for both initial load (buildAPI)
17
+ * and hot reload (api.add) contexts. Supports six collision modes:
18
+ * - "skip": Silently ignore collision, keep existing value
19
+ * - "warn": Warn about collision, keep existing value
20
+ * - "replace": Replace existing value completely
21
+ * - "merge": Merge properties (preserve original + add new)
22
+ * - "merge-replace": Merge properties (add new + overwrite existing with new values)
23
+ * - "error": Throw error on collision
24
+ *
25
+ * @example
26
+ * // String shorthand applies to both contexts
27
+ * normalizeCollision("merge")
28
+ * // => { initial: "merge", api: "merge" }
29
+ *
30
+ * @example
31
+ * // Object allows per-context control
32
+ * normalizeCollision({ initial: "warn", api: "error" })
33
+ * // => { initial: "warn", api: "error" }
34
+ */
35
+ public normalizeCollision(collision: string | any): any;
36
+ /**
37
+ * Normalize runtime input to internal standard format
38
+ * @param {string} runtime - Input runtime type (various formats accepted)
39
+ * @returns {string} Normalized runtime type ("async" or "live")
40
+ * @public
41
+ */
42
+ public normalizeRuntime(runtime: string): string;
43
+ /**
44
+ * Normalize mode input to internal standard format
45
+ * @param {string} mode - Input mode type (various formats accepted)
46
+ * @returns {string} Normalized mode type ("eager" or "lazy")
47
+ * @public
48
+ */
49
+ public normalizeMode(mode: string): string;
50
+ /**
51
+ * Normalize mutations configuration for API modification control
52
+ * @param {Object} mutations - Mutations config object with add/remove/reload properties
53
+ * @returns {Object} Normalized mutations configuration
54
+ * @public
55
+ *
56
+ * @description
57
+ * Normalizes mutation control configuration for API runtime modifications.
58
+ * Controls whether api.slothlet.api.add(), api.slothlet.api.remove(), and
59
+ * api.slothlet.reload() operations are allowed.
60
+ *
61
+ * @example
62
+ * // Allow all mutations (default)
63
+ * normalizeMutations({ add: true, remove: true, reload: true })
64
+ * // => { add: true, remove: true, reload: true }
65
+ *
66
+ * @example
67
+ * // Disable all mutations
68
+ * normalizeMutations({ add: false, remove: false, reload: false })
69
+ * // => { add: false, remove: false, reload: false }
70
+ */
71
+ public normalizeMutations(mutations: any): any;
72
+ /**
73
+ * Normalize debug configuration
74
+ * @param {boolean|Object} debug - Debug flag or object with targeted flags
75
+ * @returns {Object} Normalized debug object with all flags
76
+ * @public
77
+ */
78
+ public normalizeDebug(debug: boolean | any): any;
79
+ /**
80
+ * Transform and validate configuration
81
+ * @param {Object} config - Raw configuration options
82
+ * @returns {Object} Normalized configuration
83
+ * @throws {SlothletError} If configuration is invalid
84
+ * @public
85
+ */
86
+ public transformConfig(config?: any): any;
87
+ /**
88
+ * Normalize TypeScript configuration
89
+ * @param {boolean|string|Object} typescript - TypeScript config (true, "fast", or { mode: "fast"|"strict", ... })
90
+ * @returns {Object|null} Normalized TypeScript configuration or null if disabled
91
+ * @public
92
+ */
93
+ public normalizeTypeScript(typescript: boolean | string | any): any | null;
94
+ }
95
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
96
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/config.mjs"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH;IACC,gCAAmC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,qCAxBW,MAAM,MAAO,OAkDvB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;OAKG;IACH,2BAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,+CAcC;IAED;;;;;OAKG;IACH,6BAJW,OAAO,MAAO,OA6DxB;IAED;;;;;;OAMG;IACH,0CA+HC;IAED;;;;;OAKG;IACH,uCAJW,OAAO,GAAC,MAAM,MAAO,GACnB,MAAO,IAAI,CAsCvB;CACD;8BA/Y6B,0CAA0C"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Set the context checker callback
3
+ * Called by the runtime to register a way to detect API context
4
+ * @param {Function} checker - Function that returns true if in API context
5
+ * @public
6
+ */
7
+ export function setApiContextChecker(checker: Function): void;
8
+ /**
9
+ * Enable EventEmitter context propagation by patching EventEmitter.prototype.
10
+ * This should be called ONCE globally when the first slothlet instance is created.
11
+ * Subsequent calls will be ignored (patching is global).
12
+ *
13
+ * @public
14
+ */
15
+ export function enableEventEmitterPatching(): void;
16
+ /**
17
+ * Disable EventEmitter context propagation and restore original methods.
18
+ * This should only be called when ALL slothlet instances have been shut down.
19
+ *
20
+ * @public
21
+ */
22
+ export function disableEventEmitterPatching(): void;
23
+ /**
24
+ * Cleanup all tracked EventEmitters created within slothlet API context.
25
+ * This removes all listeners from tracked emitters and clears tracking structures.
26
+ * Should be called during shutdown to prevent memory leaks and hanging processes.
27
+ *
28
+ * @public
29
+ */
30
+ export function cleanupEventEmitterResources(): void;
31
+ //# sourceMappingURL=eventemitter-context.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventemitter-context.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/eventemitter-context.mjs"],"names":[],"mappings":"AAsCA;;;;;GAKG;AACH,8DAEC;AAyWD;;;;;;GAMG;AACH,mDAeC;AAED;;;;;GAKG;AACH,oDAmBC;AAED;;;;;;GAMG;AACH,qDAcC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Hint detection for providing helpful error hints
3
+ * @class HintDetector
4
+ * @extends ComponentBase
5
+ * @package
6
+ */
7
+ export class HintDetector extends ComponentBase {
8
+ static slothletProperty: string;
9
+ /**
10
+ * Detect appropriate hint key based on error
11
+ * @param {Error} error - The original error
12
+ * @param {string} errorCode - The SlothletError code
13
+ * @returns {string|undefined} Hint key for i18n translation, or undefined
14
+ * @public
15
+ */
16
+ public detectHint(error: Error, errorCode: string): string | undefined;
17
+ }
18
+ export const detectHint: any;
19
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
20
+ //# sourceMappingURL=hint-detector.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hint-detector.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/hint-detector.mjs"],"names":[],"mappings":"AAwCA;;;;;GAKG;AACH;IACC,gCAAyC;IAEzC;;;;;;OAMG;IACH,yBALW,KAAK,aACL,MAAM,GACJ,MAAM,GAAC,SAAS,CAiB5B;CACD;AAID,6BAA2G;8BAxD7E,0CAA0C"}