@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,199 @@
1
+ /**
2
+ * Manages hooks for API function interception.
3
+ * Supports before/after/always/error hooks with pattern matching and priority ordering.
4
+ *
5
+ * @class HookManager
6
+ * @extends ComponentBase
7
+ */
8
+ export class HookManager extends ComponentBase {
9
+ /**
10
+ * Property name for auto-discovery
11
+ * @type {string}
12
+ * @static
13
+ */
14
+ static slothletProperty: string;
15
+ enabled: any;
16
+ defaultPattern: any;
17
+ suppressErrors: any;
18
+ enabledPatterns: Set<any>;
19
+ patternFilterActive: boolean;
20
+ hooks: Map<any, any>;
21
+ registrationOrder: number;
22
+ reportedErrors: WeakSet<object>;
23
+ /**
24
+ * Register a hook for API functions.
25
+ *
26
+ * @param {string} typePattern - Combined type and pattern (e.g., "before:math.*")
27
+ * @param {function} handler - Hook handler function
28
+ * @param {object} [options={}] - Hook options
29
+ * @param {string} [options.id] - Unique identifier (auto-generated if not provided)
30
+ * @param {number} [options.priority=0] - Higher = earlier execution
31
+ * @param {string} [options.subset="primary"] - Phase: "before", "primary", or "after"
32
+ * @returns {string} Hook ID
33
+ * @public
34
+ *
35
+ * @example
36
+ * hookManager.on("before:math.*", ({ args }) => {
37
+ * console.log("Args:", args);
38
+ * return args;
39
+ * }, { priority: 100 });
40
+ */
41
+ public on(typePattern: string, handler: Function, options?: {
42
+ id?: string;
43
+ priority?: number;
44
+ subset?: string;
45
+ }): string;
46
+ /**
47
+ * Remove hooks matching filter criteria.
48
+ *
49
+ * @param {object} [filter={}] - Filter criteria
50
+ * @param {string} [filter.id] - Remove hook by ID
51
+ * @param {string} [filter.type] - Remove hooks by type
52
+ * @param {string} [filter.pattern] - Remove hooks matching pattern
53
+ * @returns {number} Number of hooks removed
54
+ * @public
55
+ */
56
+ public remove(filter?: {
57
+ id?: string;
58
+ type?: string;
59
+ pattern?: string;
60
+ }): number;
61
+ /**
62
+ * Enable hooks matching filter criteria.
63
+ *
64
+ * @param {object|string} [filter={}] - Filter criteria (empty = enable all, string = pattern)
65
+ * @param {string} [filter.id] - Enable hook by ID
66
+ * @param {string} [filter.type] - Enable hooks by type
67
+ * @param {string} [filter.pattern] - Enable hooks matching pattern
68
+ * @returns {number} Number of hooks enabled
69
+ * @public
70
+ */
71
+ public enable(filter?: object | string): number;
72
+ /**
73
+ * Disable hooks matching filter criteria.
74
+ *
75
+ * @param {object|string} [filter={}] - Filter criteria (empty = disable all, string = pattern)
76
+ * @param {string} [filter.id] - Disable hook by ID
77
+ * @param {string} [filter.type] - Disable hooks by type
78
+ * @param {string} [filter.pattern] - Disable hooks matching pattern
79
+ * @returns {number} Number of hooks disabled
80
+ * @public
81
+ */
82
+ public disable(filter?: object | string): number;
83
+ /**
84
+ * List registered hooks matching filter criteria.
85
+ *
86
+ * @param {object|string} [filter={}] - Filter criteria (empty = list all), type string, or pattern string
87
+ * @param {string} [filter.id] - List hook by ID
88
+ * @param {string} [filter.type] - List hooks by type
89
+ * @param {string} [filter.pattern] - List hooks matching pattern
90
+ * @param {boolean} [filter.enabled] - Filter by enabled state
91
+ * @returns {object} Object with registeredHooks array property
92
+ * @public
93
+ */
94
+ public list(filter?: object | string): object;
95
+ /**
96
+ * Get hooks for a specific API path and type.
97
+ * Used internally by UnifiedWrapper.
98
+ *
99
+ * @param {string} type - Hook type (before/after/always/error)
100
+ * @param {string} apiPath - API path (e.g., "math.add")
101
+ * @returns {Array<object>} Sorted array of matching hooks
102
+ * @public
103
+ */
104
+ public getHooksForPath(type: string, apiPath: string): Array<object>;
105
+ /**
106
+ * Execute before hooks for an API path.
107
+ *
108
+ * @param {string} path - API path being called
109
+ * @param {Array} args - Function arguments
110
+ * @param {object} api - Bound API object
111
+ * @param {object} ctx - User context object
112
+ * @returns {object} Result object: { args, shortCircuit, value }
113
+ * @public
114
+ */
115
+ public executeBeforeHooks(path: string, args: any[], api: object, ctx: object): object;
116
+ /**
117
+ * Execute after hooks for an API path.
118
+ *
119
+ * @param {string} path - API path being called
120
+ * @param {*} result - Function return value
121
+ * @param {Array} args - Original function arguments
122
+ * @param {object} api - Bound API object
123
+ * @param {object} ctx - User context object
124
+ * @returns {HookExecutionResult} Object indicating if result was modified and the final result
125
+ * @public
126
+ */
127
+ public executeAfterHooks(path: string, result: any, args: any[], api: object, ctx: object): HookExecutionResult;
128
+ /**
129
+ * Execute always hooks for an API path.
130
+ *
131
+ * @param {string} path - API path being called
132
+ * @param {Array} args - Function arguments
133
+ * @param {*} resultOrError - Function result or error
134
+ * @param {boolean} hasError - Whether an error occurred
135
+ * @param {Array<Error>} errors - Array of errors that occurred
136
+ * @param {object} api - Bound API object
137
+ * @param {object} ctx - User context object
138
+ * @public
139
+ */
140
+ public executeAlwaysHooks(path: string, args: any[], resultOrError: any, hasError: boolean, errors: Array<Error>, api: object, ctx: object): void;
141
+ /**
142
+ * Execute error hooks for an API path.
143
+ *
144
+ * @param {string} path - API path being called
145
+ * @param {Error} error - The error that occurred
146
+ * @param {object} source - Error source info with type, hookTag, hookId, timestamp, stack
147
+ * @param {Array} args - Function arguments
148
+ * @param {object} api - Bound API object
149
+ * @param {object} ctx - User context object
150
+ * @public
151
+ */
152
+ public executeErrorHooks(path: string, error: Error, source: object, args: any[], api: object, ctx: object): void;
153
+ /**
154
+ * Get the pattern compilation function for diagnostic purposes.
155
+ * Only exposed when diagnostics mode is enabled.
156
+ *
157
+ * @returns {function} The pattern compilation function
158
+ * @internal
159
+ */
160
+ getCompilePatternForDiagnostics(): Function;
161
+ /**
162
+ * Export all registered hooks (including handler closures) so they can be
163
+ * re-registered on a fresh HookManager instance after a full reload.
164
+ *
165
+ * @returns {Array<object>} Snapshot of all current hook registrations.
166
+ * @public
167
+ */
168
+ public exportHooks(): Array<object>;
169
+ /**
170
+ * Re-register hooks exported by {@link exportHooks} into this (new) instance.
171
+ * Called after a full `api.slothlet.reload()` to restore user-registered hooks.
172
+ *
173
+ * @param {Array<object>} registrations - Snapshot returned by exportHooks().
174
+ * @returns {void}
175
+ * @public
176
+ */
177
+ public importHooks(registrations: Array<object>): void;
178
+ /**
179
+ * Cleanup hook manager on shutdown.
180
+ * @public
181
+ */
182
+ public shutdown(): Promise<void>;
183
+ #private;
184
+ }
185
+ /**
186
+ * Result returned by hook execution methods.
187
+ */
188
+ export type HookExecutionResult = {
189
+ /**
190
+ * - Whether any hook modified the result value.
191
+ */
192
+ modified: boolean;
193
+ /**
194
+ * - The final (possibly hook-modified) return value.
195
+ */
196
+ result?: any;
197
+ };
198
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
199
+ //# sourceMappingURL=hook-manager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-manager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/hook-manager.mjs"],"names":[],"mappings":"AAkCA;;;;;;GAMG;AACH;IACC;;;;OAIG;IACH,yBAHU,MAAM,CAGwB;IAoDvC,aAAiC;IACjC,oBAAgD;IAChD,oBAAwD;IACxD,0BAAgC;IAChC,6BAAgC;IAEhC,qBAAsB;IACtB,0BAA0B;IAC1B,gCAAmC;IAGpC;;;;;;;;;;;;;;;;;OAiBG;IACH,uBAfW,MAAM,+BAGd;QAAyB,EAAE,GAAnB,MAAM;QACW,QAAQ,GAAzB,MAAM;QACW,MAAM,GAAvB,MAAM;KACd,GAAU,MAAM,CA+ElB;IAED;;;;;;;;;OASG;IACH,uBANG;QAAwB,EAAE,GAAlB,MAAM;QACU,IAAI,GAApB,MAAM;QACU,OAAO,GAAvB,MAAM;KACd,GAAU,MAAM,CA8ClB;IAED;;;;;;;;;OASG;IACH,uBAPW,MAAM,GAAC,MAAM,GAIX,MAAM,CAalB;IAED;;;;;;;;;OASG;IACH,wBAPW,MAAM,GAAC,MAAM,GAIX,MAAM,CAclB;IAED;;;;;;;;;;OAUG;IACH,qBARW,MAAM,GAAC,MAAM,GAKX,MAAM,CA8DlB;IAED;;;;;;;;OAQG;IACH,6BALW,MAAM,WACN,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAqDzB;IAED;;;;;;;;;OASG;IACH,gCAPW,MAAM,oBAEN,MAAM,OACN,MAAM,GACJ,MAAM,CA6ClB;IAED;;;;;;;;;;OAUG;IACH,+BARW,MAAM,UACN,GAAC,oBAED,MAAM,OACN,MAAM,GACJ,mBAAmB,CA+C/B;IAED;;;;;;;;;;;OAWG;IACH,gCATW,MAAM,8BAEN,GAAC,YACD,OAAO,UACP,KAAK,CAAC,KAAK,CAAC,OACZ,MAAM,OACN,MAAM,QA8BhB;IAED;;;;;;;;;;OAUG;IACH,+BARW,MAAM,SACN,KAAK,UACL,MAAM,oBAEN,MAAM,OACN,MAAM,QA4BhB;IAkLD;;;;;;OAMG;IACH,4CAEC;IA6ID;;;;;;OAMG;IACH,sBAHa,KAAK,CAAC,MAAM,CAAC,CAkBzB;IAED;;;;;;;OAOG;IACH,kCAJW,KAAK,CAAC,MAAM,CAAC,GACX,IAAI,CAWhB;IAED;;;OAGG;IACH,iCAUC;;CACD;;;;;;;;cAt9Ba,OAAO;;;;aACP,GAAC;;8BANe,0CAA0C"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Registers a Slothlet instance and creates its per-instance lifecycle capability token.
3
+ *
4
+ * Safe to call multiple times on the same instance (idempotent) — subsequent calls are
5
+ * silently ignored, preserving the original token. This handles the reload code path where
6
+ * `load()` is called again on the same Slothlet object.
7
+ *
8
+ * @param {object} slothlet - The Slothlet instance to register.
9
+ * @returns {void}
10
+ * @package
11
+ *
12
+ * @example
13
+ * // Called once (or on reload) in Slothlet.load():
14
+ * registerInstance(this);
15
+ */
16
+ export function registerInstance(slothlet: object): void;
17
+ /**
18
+ * Returns the per-instance capability token for the given Slothlet instance.
19
+ *
20
+ * Used internally by `lifecycle.mjs` (emit dispatch) and `modes-processor.mjs`
21
+ * (direct tagSystemMetadata call for folder wrappers). Requires a live registered
22
+ * Slothlet instance — cannot be exploited without one.
23
+ *
24
+ * @param {object} slothlet - A registered Slothlet instance.
25
+ * @returns {symbol|undefined} The instance token, or undefined if not registered.
26
+ * @package
27
+ *
28
+ * @example
29
+ * handler(data, getInstanceToken(this.slothlet));
30
+ */
31
+ export function getInstanceToken(slothlet: object): symbol | undefined;
32
+ /**
33
+ * Verifies that `token` is the registered capability token for the given Slothlet instance.
34
+ *
35
+ * Used by `metadata.mjs` inside `tagSystemMetadata()` to reject calls that did not
36
+ * originate from the internal lifecycle dispatch path.
37
+ *
38
+ * @param {object} slothlet - A registered Slothlet instance.
39
+ * @param {*} token - The token value to verify.
40
+ * @returns {boolean} `true` only if `token` is the exact Symbol registered for `slothlet`.
41
+ * @package
42
+ *
43
+ * @example
44
+ * if (!verifyToken(this.slothlet, token)) {
45
+ * throw new this.SlothletError("METADATA_LIFECYCLE_BYPASS", ...);
46
+ * }
47
+ */
48
+ export function verifyToken(slothlet: object, token: any): boolean;
49
+ //# sourceMappingURL=lifecycle-token.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-token.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/lifecycle-token.mjs"],"names":[],"mappings":"AA8CA;;;;;;;;;;;;;;GAcG;AACH,2CARW,MAAM,GACJ,IAAI,CAchB;AAED;;;;;;;;;;;;;GAaG;AACH,2CAPW,MAAM,GACJ,MAAM,GAAC,SAAS,CAQ5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,sCAVW,MAAM,SACN,GAAC,GACC,OAAO,CAUnB"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Lifecycle event manager for impl changes
3
+ * @extends ComponentBase
4
+ * @public
5
+ */
6
+ export class Lifecycle extends ComponentBase {
7
+ /**
8
+ * Where this component should be mounted on the Slothlet instance
9
+ * @type {string}
10
+ */
11
+ static slothletProperty: string;
12
+ subscribers: Map<any, any>;
13
+ eventLog: any[];
14
+ maxLogSize: number;
15
+ /**
16
+ * Subscribe to lifecycle event
17
+ * @param {string} event - Event name (impl:created, impl:changed, impl:removed, materialized:complete, path:collision)
18
+ * @param {Function} handler - Event handler function(eventData)
19
+ * @returns {Function} Unsubscribe function
20
+ * @public
21
+ *
22
+ * @description
23
+ * Subscribe to lifecycle events to react to impl changes.
24
+ *
25
+ * @example
26
+ * const unsubscribe = lifecycle.subscribe("impl:changed", (data) => {
27
+ * console.log("Impl changed:", data.apiPath, data.source);
28
+ * });
29
+ */
30
+ public subscribe(event: string, handler: Function): Function;
31
+ /**
32
+ * Alias for subscribe() - standard EventEmitter pattern
33
+ * @param {string} event - Event name
34
+ * @param {Function} handler - Event handler function
35
+ * @returns {Function} Unsubscribe function
36
+ * @public
37
+ *
38
+ * @example
39
+ * lifecycle.on('materialized:complete', (data) => {
40
+ * console.log(`${data.total} modules materialized`);
41
+ * });
42
+ */
43
+ public on(event: string, handler: Function): Function;
44
+ /**
45
+ * Unsubscribe from lifecycle event - standard EventEmitter pattern
46
+ * @param {string} event - Event name
47
+ * @param {Function} handler - Event handler function to remove
48
+ * @public
49
+ *
50
+ * @example
51
+ * const handler = (data) => console.log(data);
52
+ * lifecycle.on('impl:changed', handler);
53
+ * lifecycle.off('impl:changed', handler);
54
+ */
55
+ public off(event: string, handler: Function): void;
56
+ /**
57
+ * Alias for off() - standard EventEmitter pattern
58
+ * @param {string} event - Event name
59
+ * @param {Function} handler - Event handler function to remove
60
+ * @public
61
+ */
62
+ public unsubscribe(event: string, handler: Function): void;
63
+ /**
64
+ * Emit lifecycle event
65
+ * @param {string} event - Event name
66
+ * @param {object} data - Event data
67
+ * @private
68
+ *
69
+ * @description
70
+ * Emit event to all subscribers. Event data should include:
71
+ * - apiPath: API path where impl exists
72
+ * - impl: The implementation object
73
+ * - source: Source of event (initial, hot-reload, materialization, etc)
74
+ * - moduleID: Module identifier (if applicable)
75
+ * - filePath: File path (if applicable)
76
+ * - metadata: Additional metadata
77
+ *
78
+ * @example
79
+ * lifecycle.emit("impl:created", {
80
+ * apiPath: "math.add",
81
+ * impl: addFunction,
82
+ * source: "initial",
83
+ * moduleID: "base_abc123",
84
+ * filePath: "/path/to/math.mjs"
85
+ * });
86
+ */
87
+ private emit;
88
+ }
89
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
90
+ //# sourceMappingURL=lifecycle.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/lifecycle.mjs"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH;IACC;;;OAGG;IACH,yBAFU,MAAM,CAEsB;IAOrC,2BAA4B;IAC5B,gBAAkB;IAClB,mBAAsB;IAGvB;;;;;;;;;;;;;;OAcG;IACH,wBAbW,MAAM,+BA0BhB;IAED;;;;;;;;;;;OAWG;IACH,iBAVW,MAAM,+BAYhB;IAED;;;;;;;;;;OAUG;IACH,kBATW,MAAM,2BAchB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,2BAMhB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,aAyDC;CAED;8BAtL6B,0CAA0C"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Manager for tracking lazy folder materialization state
3
+ * @class MaterializeManager
4
+ * @extends ComponentBase
5
+ * @package
6
+ *
7
+ * @description
8
+ * Provides access to lazy materialization state via `api.slothlet.materialize`.
9
+ * Tracks count of unmaterialized lazy folders and provides boolean state, statistics,
10
+ * and wait functionality for synchronization.
11
+ *
12
+ * @example
13
+ * const api = await slothlet({ dir: "./api", mode: "lazy" });
14
+ *
15
+ * // Check if fully materialized
16
+ * if (api.slothlet.materialize.materialized) {
17
+ * console.log("All lazy folders loaded!");
18
+ * }
19
+ *
20
+ * // Get statistics
21
+ * const stats = api.slothlet.materialize.get();
22
+ * console.log(`${stats.percentage}% loaded (${stats.remaining}/${stats.total} remaining)`);
23
+ *
24
+ * // Wait for full materialization
25
+ * await api.slothlet.materialize.wait();
26
+ */
27
+ export class MaterializeManager extends ComponentBase {
28
+ static slothletProperty: string;
29
+ /**
30
+ * Get materialization state as a boolean
31
+ * Returns true when all lazy wrappers have been materialized
32
+ * @returns {boolean} True if fully materialized, false if any lazy folders remain
33
+ * @public
34
+ *
35
+ * @example
36
+ * if (api.slothlet.materialize.materialized) {
37
+ * console.log("API is fully loaded");
38
+ * }
39
+ */
40
+ public get materialized(): boolean;
41
+ /**
42
+ * Get detailed materialization statistics
43
+ * @returns {Object} Statistics object with total, materialized, remaining, percentage
44
+ * @public
45
+ *
46
+ * @example
47
+ * const stats = api.slothlet.materialize.get();
48
+ * // { total: 5, materialized: 3, remaining: 2, percentage: 60 }
49
+ */
50
+ public get(): any;
51
+ /**
52
+ * Wait for full materialization (all lazy folders loaded)
53
+ * Returns immediately if already fully materialized
54
+ * @returns {Promise<void>} Resolves when all lazy wrappers have materialized
55
+ * @public
56
+ *
57
+ * @example
58
+ * // Wait for API to fully load
59
+ * await api.slothlet.materialize.wait();
60
+ * console.log("All modules loaded!");
61
+ *
62
+ * @example
63
+ * // Wait with timeout
64
+ * const timeoutPromise = new Promise((_, reject) =>
65
+ * setTimeout(() => reject(new Error("Timeout")), 5000)
66
+ * );
67
+ * await Promise.race([
68
+ * api.slothlet.materialize.wait(),
69
+ * timeoutPromise
70
+ * ]);
71
+ */
72
+ public wait(): Promise<void>;
73
+ }
74
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
75
+ //# sourceMappingURL=materialize-manager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"materialize-manager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/materialize-manager.mjs"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH;IACC,gCAAwC;IAWxC;;;;;;;;;;OAUG;IACH,2BARa,OAAO,CAUnB;IAED;;;;;;;;OAQG;IACH,kBAYC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,eAlBa,OAAO,CAAC,IAAI,CAAC,CA4BzB;CACD;8BA9G6B,0CAA0C"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Metadata handler for introspection of function metadata
3
+ * @class Metadata
4
+ * @extends ComponentBase
5
+ * @package
6
+ */
7
+ export class Metadata extends ComponentBase {
8
+ static slothletProperty: string;
9
+ _instanceId: any;
10
+ /**
11
+ * Tag system metadata (SECURE, IMMUTABLE)
12
+ * Called internally during wrapper/function creation
13
+ *
14
+ * The `token` parameter must be the module-private `LIFECYCLE_TOKEN` Symbol exported
15
+ * from `@cldmv/slothlet/handlers/lifecycle-token`. Because a Symbol is a unique,
16
+ * non-forgeable value within a Node.js process, and because the token module is not
17
+ * listed in the package's public `exports` map, user-land code cannot construct a
18
+ * value that satisfies the `token === LIFECYCLE_TOKEN` check without modifying the
19
+ * source or importing an undocumented internal path.
20
+ *
21
+ * @param {Function|Object} target - Wrapper or function to tag
22
+ * @param {Object} systemData - System metadata (filePath, apiPath, moduleID, sourceFolder)
23
+ * @param {symbol} token - Must be `LIFECYCLE_TOKEN` — the unforgeable module-private Symbol
24
+ * @private
25
+ */
26
+ private tagSystemMetadata;
27
+ /**
28
+ * Get system metadata only (without user metadata)
29
+ * @param {Function|Object} target - Wrapper or function
30
+ * @returns {Object|null} System metadata or null
31
+ * @package
32
+ */
33
+ getSystemMetadata(target: Function | any): any | null;
34
+ /**
35
+ * Get metadata for a target (combines system + user)
36
+ * For wrappers: checks current impl to ensure metadata is current
37
+ * @param {Function|Object} target - Wrapper or function
38
+ * @returns {Object} Combined metadata (deeply frozen)
39
+ * @public
40
+ */
41
+ public getMetadata(target: Function | any): any;
42
+ /**
43
+ * Set global user metadata (applies to all functions)
44
+ * @param {string} key - Metadata key
45
+ * @param {unknown} value - Metadata value
46
+ * @public
47
+ */
48
+ public setGlobalMetadata(key: string, value: unknown): void;
49
+ /**
50
+ * Add/update user metadata for specific function
51
+ * @param {Function} target - Function to tag with metadata
52
+ * @param {string} key - Metadata key
53
+ * @param {unknown} value - Metadata value
54
+ * @public
55
+ */
56
+ public setUserMetadata(target: Function, key: string, value: unknown): void;
57
+ /**
58
+ * Remove user metadata from specific function
59
+ * @param {Function} target - Function to remove metadata from
60
+ * @param {string|string[]|Object<string, string[]>} [key] - Optional key(s) to remove (removes all if omitted). Can be:
61
+ * - string: Remove single key
62
+ * - string[]: Remove multiple keys (each element must be a string)
63
+ * - {key: string[]}: Remove nested keys from object values
64
+ * @public
65
+ */
66
+ public removeUserMetadata(target: Function, key?: string | string[] | {
67
+ [x: string]: string[];
68
+ }): void;
69
+ /**
70
+ * Register user metadata keyed by an identifier (moduleID or API path)
71
+ *
72
+ * @description
73
+ * Stores user-provided metadata in `#userMetadataStore` under the given
74
+ * `identifier`. The identifier is treated opaquely — callers pass either a
75
+ * generated moduleID (e.g. `base_slothlet`) or a dot-notation API path
76
+ * (e.g. `math`). `getMetadata()` retrieves entries using the same key via
77
+ * both the moduleID lookup and `collectMetadataFromParents`, so storing
78
+ * under a single key is sufficient for both cases.
79
+ *
80
+ * Multiple calls to the same identifier are merged; later calls override
81
+ * earlier ones for conflicting keys.
82
+ *
83
+ * @param {string} identifier - Module ID or dot-notation API path
84
+ * @param {Object} metadata - User metadata object to merge
85
+ * @package
86
+ */
87
+ registerUserMetadata(identifier: string, metadata: any): void;
88
+ /**
89
+ * Remove all user metadata for an apiPath
90
+ *
91
+ * @description
92
+ * Cleanup method to remove all user metadata associated with an apiPath.
93
+ * Used during api.remove() or cleanup operations.
94
+ *
95
+ * @param {string} apiPath - API path to remove
96
+ * @package
97
+ */
98
+ removeUserMetadataByApiPath(apiPath: string): void;
99
+ /**
100
+ * Set metadata for all functions reachable at an API path.
101
+ *
102
+ * @description
103
+ * Stores metadata keyed by `apiPath` so that every function whose system
104
+ * `apiPath` starts with (or equals) the given path inherits the values via
105
+ * `collectMetadataFromParents()` in `getMetadata()`.
106
+ *
107
+ * Accepts either a single key/value pair or a plain object to merge.
108
+ * Multiple calls to the same path are merged; later calls override earlier
109
+ * ones for conflicting keys.
110
+ *
111
+ * Priority (lowest → highest): global → setForPath → set() → system.
112
+ *
113
+ * @param {string} apiPath - Dot-notation path (e.g. `"math"`, `"math.add"`)
114
+ * @param {string|Object} keyOrObj - Key string (with `value`) OR metadata object to merge
115
+ * @param {unknown} [value] - Value when `keyOrObj` is a string key
116
+ * @public
117
+ */
118
+ public setPathMetadata(apiPath: string, keyOrObj: string | any, value?: unknown): void;
119
+ /**
120
+ * Remove metadata keys (or all metadata) for an API path.
121
+ *
122
+ * @description
123
+ * Removes one specific key, multiple keys, or ALL user metadata stored under
124
+ * the given `apiPath` key in the path store.
125
+ * Only affects metadata set via `setForPath()` / `registerUserMetadata()` for
126
+ * this exact path segment - it does not walk descendant paths.
127
+ *
128
+ * @param {string} apiPath - Dot-notation path (e.g. `"math"`, `"math.add"`)
129
+ * @param {string|string[]} [key] - Key(s) to remove. Omit to remove all metadata for the path.
130
+ * @public
131
+ */
132
+ public removePathMetadata(apiPath: string, key?: string | string[]): void;
133
+ /**
134
+ * Export user-managed metadata state for preservation across reload.
135
+ *
136
+ * @description
137
+ * Captures `#globalUserMetadata` and all entries in `#userMetadataStore`
138
+ * so they can be restored to a fresh Metadata instance after reload.
139
+ * Called by `slothlet.reload()` BEFORE `load()` destroys this instance.
140
+ *
141
+ * @returns {{ globalMetadata: Object, userMetadataStore: Map }} Snapshot of user state
142
+ * @package
143
+ */
144
+ exportUserState(): {
145
+ globalMetadata: any;
146
+ userMetadataStore: Map<any, any>;
147
+ };
148
+ /**
149
+ * Restore user-managed metadata state after a fresh load.
150
+ *
151
+ * @description
152
+ * Merges previously exported state into the new (empty) Metadata instance.
153
+ * Called by `slothlet.reload()` AFTER `load()` creates the new instance and
154
+ * BEFORE operation-history replay so that `registerUserMetadata()` from replay
155
+ * can properly merge over the restored base state.
156
+ *
157
+ * Merge priority: existing (from load) > saved state.
158
+ * This means replay-registered api.add metadata overrides restored values
159
+ * for the same key, which is the desired behaviour.
160
+ *
161
+ * @param {{ globalMetadata: Object, userMetadataStore: Map }} state - Previously exported state
162
+ * @package
163
+ */
164
+ importUserState(state: {
165
+ globalMetadata: any;
166
+ userMetadataStore: Map<any, any>;
167
+ }): void;
168
+ /**
169
+ * Get metadata of any function by API path.
170
+ *
171
+ * Traverses `this.slothlet.api` using the dot-notation path, materializes
172
+ * lazy wrappers as needed, then returns the combined metadata for the
173
+ * resolved target via `getMetadata()`.
174
+ *
175
+ * Called by the `api.slothlet.metadata.get()` closure injected in
176
+ * `slothlet.injectRuntimeMetadataFunctions()`.
177
+ *
178
+ * @param {string} path - Dot-notation API path (e.g. `"math.add"`)
179
+ * @returns {Promise<object|null>} Combined metadata or null
180
+ * @public
181
+ */
182
+ public get(path: string): Promise<object | null>;
183
+ /**
184
+ * Get metadata for the currently-executing API function.
185
+ *
186
+ * Reads `currentWrapper` from the active context-manager store — the same
187
+ * fast synchronous path used by the unified wrapper's `apply` trap.
188
+ * Throws `RUNTIME_NO_ACTIVE_CONTEXT` when called outside of a slothlet
189
+ * execution context.
190
+ *
191
+ * Called by the `api.slothlet.metadata.self()` closure injected in
192
+ * `slothlet.injectRuntimeMetadataFunctions()`.
193
+ *
194
+ * @returns {object} Combined metadata for the current function
195
+ * @public
196
+ */
197
+ public self(): object;
198
+ /**
199
+ * Get metadata for the API function that called the current function.
200
+ *
201
+ * Reads `callerWrapper` from the active context-manager store.
202
+ * Returns `null` when there is no caller in context (e.g. the function
203
+ * was invoked directly from outside the API).
204
+ *
205
+ * Called by the `api.slothlet.metadata.caller()` closure injected in
206
+ * `slothlet.injectRuntimeMetadataFunctions()`.
207
+ *
208
+ * @returns {object|null} Combined metadata for the calling function, or null
209
+ * @public
210
+ */
211
+ public caller(): object | null;
212
+ #private;
213
+ }
214
+ import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
215
+ //# sourceMappingURL=metadata.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/metadata.mjs"],"names":[],"mappings":"AAwBA;;;;;GAKG;AACH;IACC,gCAAqC;IASrC,iBAAmB;IAkCnB;;;;;;;;;;;;;;;OAeG;IACH,0BAyCC;IAED;;;;;OAKG;IACH,0BAJW,cAAe,GACb,MAAO,IAAI,CAYvB;IAED;;;;;;OAMG;IACH,2BAJW,cAAe,OAoEzB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,SACN,OAAO,QAKjB;IAED;;;;;;OAMG;IACH,8CAJW,MAAM,SACN,OAAO,QA+CjB;IAED;;;;;;;;OAQG;IACH,kDANW,MAAM,GAAC,MAAM,EAAE,GAAC;YAAO,MAAM,GAAE,MAAM,EAAE;KAAC,QAkFlD;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,iCAJW,MAAM,uBA2BhB;IAED;;;;;;;;;OASG;IACH,qCAHW,MAAM,QAMhB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,gCALW,MAAM,YACN,MAAM,MAAO,UACb,OAAO,QAyBjB;IAED;;;;;;;;;;;;OAYG;IACH,mCAJW,MAAM,QACN,MAAM,GAAC,MAAM,EAAE,QA+BzB;IAED;;;;;;;;;;OAUG;IACH,mBAHa;QAAE,cAAc,MAAS;QAAC,iBAAiB,gBAAK;KAAE,CAe9D;IAED;;;;;;;;;;;;;;;OAeG;IACH,uBAHW;QAAE,cAAc,MAAS;QAAC,iBAAiB,gBAAK;KAAE,QAgC5D;IAED;;;;;;;;;;;;;OAaG;IACH,iBAJW,MAAM,GACJ,OAAO,CAAC,MAAM,GAAC,IAAI,CAAC,CAkChC;IAED;;;;;;;;;;;;;OAaG;IACH,eAHa,MAAM,CASlB;IAED;;;;;;;;;;;;OAYG;IACH,iBAHa,MAAM,GAAC,IAAI,CAOvB;;CACD;8BAhpB6B,0CAA0C"}