@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
@@ -1,152 +1,225 @@
1
1
  /**
2
- * Live-binding reference to the current API instance.
3
- * This is updated whenever a new API instance is created.
4
- * Dynamically imported modules can access this at runtime.
5
- * @type {object}
6
- * @private
7
- * @internal
8
- */
9
- export const self: object;
10
- /**
11
- * Live-binding reference for contextual data.
12
- * @type {object}
13
- * @private
14
- * @internal
2
+ * Create a new Slothlet instance and load an API from a directory.
3
+ * This is the sole public entry point for slothlet. Each call produces an independent
4
+ * API instance with its own component graph, context store, and lifecycle.
5
+ * @alias module:@cldmv/slothlet
6
+ * @async
7
+ * @param {SlothletOptions} config - Configuration options
8
+ * @returns {Promise<SlothletAPI>} Fully loaded, proxy-based API object
9
+ * @public
10
+ * @example
11
+ * // Minimal usage
12
+ * const api = await slothlet({ dir: "./api" });
13
+ * const result = await api.math.add(2, 3);
14
+ * await api.slothlet.shutdown();
15
+ *
16
+ * @example
17
+ * // Lazy mode with background materialization
18
+ * const api = await slothlet({
19
+ * dir: "./api",
20
+ * mode: "lazy",
21
+ * backgroundMaterialize: true
22
+ * });
23
+ *
24
+ * @example
25
+ * // With hooks
26
+ * const api = await slothlet({ dir: "./api", hook: true });
27
+ * api.slothlet.hook.on("before", "**", (endpoint, args) => { /* ... *\/ });
28
+ *
29
+ * @example
30
+ * // Hot-reload a module at runtime
31
+ * await api.slothlet.api.reload("./api/math.mjs");
32
+ *
33
+ * @example
34
+ * // Strict collision control
35
+ * const api = await slothlet({
36
+ * dir: "./api",
37
+ * api: { collision: { initial: "merge", api: "error" } }
38
+ * });
15
39
  */
16
- export const context: object;
40
+ export function slothlet(config: SlothletOptions): Promise<SlothletAPI>;
41
+ export default slothlet;
17
42
  /**
18
- * Live-binding reference for reference data.
19
- * @type {object}
20
- * @private
21
- * @internal
43
+ * Configuration options passed to `slothlet()`.
22
44
  */
23
- export const reference: object;
24
- export default slothlet;
25
45
  export type SlothletOptions = {
26
46
  /**
27
- * - Directory to load API modules from.
28
- * - Can be absolute or relative path.
29
- * - If relative, resolved from the calling file's location.
30
- * - Defaults to "api" directory relative to caller.
47
+ * - Directory to scan for API modules. Relative paths are resolved from the calling file.
31
48
  */
32
- dir?: string;
49
+ dir: string;
33
50
  /**
34
- * - Loading strategy (legacy option):
35
- * - `true`: Lazy loading - modules loaded on-demand when accessed (lower initial load, proxy overhead)
36
- * - `false`: Eager loading - all modules loaded immediately (default, higher initial load, direct access)
51
+ * - Loading strategy.
52
+ * - `"eager"` all modules are loaded immediately at startup (default).
53
+ * - `"lazy"` modules are loaded on first access via a Proxy.
54
+ * Also accepted: `"immediate"` / `"preload"` (eager aliases); `"deferred"` / `"proxy"` (lazy aliases).
37
55
  */
38
- lazy?: boolean;
56
+ mode?: "eager" | "lazy";
39
57
  /**
40
- * - Loading mode (alternative to lazy option):
41
- * - `"lazy"`: Lazy loading - modules loaded on-demand when accessed (same as lazy: true)
42
- * - `"eager"`: Eager loading - all modules loaded immediately (same as lazy: false)
43
- * - `"singleton"`, `"vm"`, `"worker"`, `"fork"`: Execution engine mode (legacy, use engine option instead)
44
- * - Takes precedence over lazy option when both are provided
58
+ * - Context propagation runtime.
59
+ * - `"async"` AsyncLocalStorage (Node.js built-in, recommended for production).
60
+ * - `"live"` Experimental live bindings.
61
+ * Also accepted: `"asynclocalstorage"` / `"als"` / `"node"` as aliases for `"async"`.
45
62
  */
46
- mode?: string;
63
+ runtime?: "async" | "live";
47
64
  /**
48
- * - Execution environment mode:
49
- * - `"singleton"`: Single shared instance within current process (default, fastest)
50
- * - `"vm"`: Isolated VM context for security/isolation
51
- * - `"worker"`: Web Worker or Worker Thread execution
52
- * - `"fork"`: Child process execution for complete isolation
65
+ * - Directory traversal depth. `Infinity` scans all subdirectories (default). `0` scans only the root.
53
66
  */
54
- engine?: string;
67
+ apiDepth?: number;
55
68
  /**
56
- * - Runtime binding system:
57
- * - `"async"` or `"asynclocalstorage"`: Use AsyncLocalStorage for context isolation (default, recommended)
58
- * - `"live"` or `"livebindings"`: Use live binding system for dynamic context updates
59
- * - Controls how `self`, `context`, and `reference` bindings are managed across function calls
69
+ * - Object merged into the per-request context accessible inside API functions via `import { context } from "@cldmv/slothlet/runtime"`.
60
70
  */
61
- runtime?: string;
71
+ context?: object | null;
62
72
  /**
63
- * - Directory traversal depth control:
64
- * - `Infinity`: Traverse all subdirectories recursively (default)
65
- * - `0`: Only load files in root directory, no subdirectories
66
- * - `1`, `2`, etc.: Limit traversal to specified depth levels
73
+ * - Object whose properties are merged directly onto the root API and also available as `api.slothlet.reference`.
67
74
  */
68
- apiDepth?: number;
75
+ reference?: object | null;
69
76
  /**
70
- * - Debug output control:
71
- * - `true`: Enable verbose logging for module loading, API construction, and binding operations
72
- * - `false`: Silent operation (default)
73
- * - Can be set via command line flag `--slothletdebug`, environment variable `SLOTHLET_DEBUG=true`, or options parameter
74
- * - Command line and environment settings become the default for all instances unless overridden
77
+ * - Controls how per-request scope data is merged. `"shallow"` merges top-level keys; `"deep"` recurses into nested objects.
75
78
  */
76
- debug?: boolean;
79
+ scope?: {
80
+ merge: "shallow" | "deep";
81
+ };
77
82
  /**
78
- * - API structure and calling convention:
79
- * - `"auto"`: Auto-detect based on root module exports (function vs object) - recommended (default)
80
- * - `"function"`: Force API to be callable as function with properties attached
81
- * - `"object"`: Force API to be plain object with method properties
83
+ * - API build and mutation settings.
82
84
  */
83
- api_mode?: string;
85
+ api?: {
86
+ collision?: string | {
87
+ initial: string;
88
+ api: string;
89
+ };
90
+ mutations?: object;
91
+ };
84
92
  /**
85
- * - Controls whether addApi can overwrite existing API endpoints:
86
- * - `true`: Allow overwrites (default, backwards compatible)
87
- * - `false`: Prevent overwrites, log warning and skip when attempting to overwrite existing endpoints
88
- * - Applies to both function and object overwrites at the final key of the API path
93
+ * - Hook system configuration.
94
+ * - `false` disabled (default).
95
+ * - `true` enabled, all endpoints.
96
+ * - `string` enabled with a default glob pattern.
97
+ * - `object` — full control: `{ enabled: boolean, pattern?: string, suppressErrors?: boolean }`.
89
98
  */
90
- allowApiOverwrite?: boolean;
99
+ hook?: boolean | string | object;
91
100
  /**
92
- * - Enable module-based API ownership tracking for selective overwrites:
93
- * - `true`: Track which modules register APIs, enable forceOverwrite with moduleId validation
94
- * - `false`: Disable ownership tracking (default, no performance overhead)
95
- * - When enabled, supports hot-reloading scenarios where modules can selectively overwrite only their own APIs
96
- * - Requires moduleId parameter in addApi options when using forceOverwrite capability
101
+ * - Enable verbose internal logging. `true` enables all categories.
102
+ * Pass an object with sub-keys `builder`, `api`, `index`, `modes`, `wrapper`, `ownership`, `context` to target specific subsystems.
97
103
  */
98
- enableModuleOwnership?: boolean;
104
+ debug?: boolean | object;
99
105
  /**
100
- * - Context data object injected into live-binding `context` reference.
101
- * - Available to all loaded modules via `import { context } from "@cldmv/slothlet/runtime"`. Useful for request data,
102
- * - user sessions, environment configs, etc.
106
+ * - Suppress all console output from slothlet (warnings, deprecations). Does not affect `debug`.
103
107
  */
104
- context?: object;
108
+ silent?: boolean;
105
109
  /**
106
- * - Reference object merged into the API root level.
107
- * - Properties not conflicting with loaded modules are added directly to the API.
108
- * - Useful for utility functions, constants, or external service connections.
110
+ * - Enable the `api.slothlet.diag.*` introspection namespace. Intended for testing; do not enable in production.
109
111
  */
110
- reference?: object;
112
+ diagnostics?: boolean;
111
113
  /**
112
- * - Filename sanitization options for API property names.
113
- * - Controls how file names are converted to valid JavaScript identifiers.
114
- * - Default behavior: camelCase conversion with lowerFirst=true.
114
+ * - Enable internal tracking. Pass `true` or `{ materialization: true }` to track lazy-mode materialization progress.
115
115
  */
116
- sanitize?: {
117
- lowerFirst?: boolean;
118
- preserveAllUpper?: boolean;
119
- preserveAllLower?: boolean;
120
- rules?: {
121
- leave?: string[];
122
- leaveInsensitive?: string[];
123
- upper?: string[];
124
- lower?: string[];
125
- };
126
- };
127
- };
128
- export type SlothletAPI = {
116
+ tracking?: boolean | object;
129
117
  /**
130
- * - Shuts down the API instance and cleans up all resources
118
+ * - When `mode: "lazy"`, immediately begins materializing all paths in the background after init.
131
119
  */
132
- shutdown: () => Promise<void>;
120
+ backgroundMaterialize?: boolean;
133
121
  /**
134
- * - Dynamically adds API modules from a folder to a specified API path
122
+ * - Internationalization settings (dev-facing, process-global).
123
+ * `{ language: string }` — selects the locale for framework messages (e.g. `"en-us"`, `"fr-fr"`, `"ja-jp"`).
135
124
  */
136
- addApi: (apiPath: string, folderPath: string) => Promise<void>;
125
+ i18n?: object;
137
126
  /**
138
- * - Returns metadata about the current API instance configuration. In lazy mode with showAll=false, returns an array of property keys. In lazy mode with showAll=true, returns a Promise resolving to an object. In eager mode, returns a plain object.
127
+ * - TypeScript support.
128
+ * - `false` — disabled (default).
129
+ * - `true` or `"fast"` — esbuild transpilation, no type checking.
130
+ * - `"strict"` — tsc compilation with type checking and `.d.ts` generation.
131
+ * See [TYPESCRIPT.md](docs/TYPESCRIPT.md) for the full configuration reference.
139
132
  */
140
- describe: (showAll?: boolean) => ((string | symbol)[] | object | Promise<object>);
133
+ typescript?: boolean | "fast" | "strict" | object;
141
134
  };
142
135
  /**
143
- * Creates a slothlet API instance with the specified configuration.
144
- * This is the main entry point that can be called directly as a function.
145
- * @async
146
- * @alias module:@cldmv/slothlet
147
- * @param {SlothletOptions} [options={}] - Configuration options for creating the API
148
- * @returns {Promise<SlothletAPI>} The bound API object or function with management methods
149
- * @public
136
+ * Bound API object returned by `slothlet()`.
137
+ * The root contains all loaded module exports plus the reserved `slothlet` namespace.
150
138
  */
151
- export function slothlet(options?: SlothletOptions): Promise<SlothletAPI>;
139
+ export type SlothletAPI = {
140
+ /**
141
+ * - Like `shutdown()` but additionally invokes registered destroy hooks before teardown. %%sig: (): void%% %%example: // ESM usage via slothlet API|import slothlet from "@cldmv/slothlet";|const api = await slothlet({ dir: './api' });|await api.destroy();%% %%example: // ESM usage via slothlet API (inside async function)|async function example() {| const { default: slothlet } = await import("@cldmv/slothlet");| const api = await slothlet({ dir: './api' });| await api.destroy();|}%% %%example: // CJS usage via slothlet API (top-level)|let slothlet;|(async () => {| ({ slothlet } = await import("@cldmv/slothlet"));| const api = await slothlet({ dir: './api' });| await api.destroy();|})();%% %%example: // CJS usage via slothlet API (inside async function)|const slothlet = require("@cldmv/slothlet");|const api = await slothlet({ dir: './api' });|await api.destroy();%%
142
+ */
143
+ destroy: () => void;
144
+ /**
145
+ * - Convenience alias for `slothlet.shutdown()`. Shuts down the instance and invokes any user-provided shutdown hook first. %%sig: (): void%% %%example: // ESM usage via slothlet API|import slothlet from "@cldmv/slothlet";|const api = await slothlet({ dir: './api' });|await api.shutdown();%% %%example: // ESM usage via slothlet API (inside async function)|async function example() {| const { default: slothlet } = await import("@cldmv/slothlet");| const api = await slothlet({ dir: './api' });| await api.shutdown();|}%% %%example: // CJS usage via slothlet API (top-level)|let slothlet;|(async () => {| ({ slothlet } = await import("@cldmv/slothlet"));| const api = await slothlet({ dir: './api' });| await api.shutdown();|})();%% %%example: // CJS usage via slothlet API (inside async function)|const slothlet = require("@cldmv/slothlet");|const api = await slothlet({ dir: './api' });|await api.shutdown();%%
146
+ */
147
+ shutdown: () => void;
148
+ /**
149
+ * - Built-in control namespace. All framework internals live here to avoid collisions with loaded modules.
150
+ */
151
+ slothlet: {
152
+ api: {
153
+ add: Function;
154
+ reload: Function;
155
+ remove: Function;
156
+ };
157
+ context: {
158
+ get: Function;
159
+ inspect: () => any;
160
+ run: Function;
161
+ scope: Function;
162
+ set: Function;
163
+ };
164
+ diag?: {
165
+ caches?: {
166
+ get?: () => any;
167
+ getAllModuleIDs?: () => string[];
168
+ has?: Function;
169
+ };
170
+ context?: object;
171
+ describe?: Function;
172
+ getAPI?: () => any;
173
+ getOwnership?: () => any;
174
+ hook?: object;
175
+ inspect?: () => any;
176
+ owner?: {
177
+ get?: Function;
178
+ };
179
+ reference?: object;
180
+ SlothletWarning?: () => SlothletWarning;
181
+ };
182
+ hook: {
183
+ clear: Function;
184
+ disable: Function;
185
+ enable: Function;
186
+ list: Function;
187
+ off: Function;
188
+ on: Function;
189
+ remove: Function;
190
+ };
191
+ lifecycle: {
192
+ off: Function;
193
+ on: Function;
194
+ };
195
+ materialize: {
196
+ get: () => any;
197
+ materialized: boolean;
198
+ wait: () => Promise<void>;
199
+ };
200
+ metadata: {
201
+ caller: () => any | null;
202
+ get: Function;
203
+ remove: Function;
204
+ removeFor: Function;
205
+ self: () => any | null;
206
+ set: Function;
207
+ setFor: Function;
208
+ setGlobal: Function;
209
+ };
210
+ owner: {
211
+ get: Function;
212
+ };
213
+ ownership: {
214
+ get: Function;
215
+ unregister: Function;
216
+ };
217
+ reference?: object;
218
+ reload: Function;
219
+ run: Function;
220
+ scope: Function;
221
+ shutdown: () => Promise<void>;
222
+ };
223
+ };
224
+ import { SlothletWarning } from "@cldmv/slothlet/errors";
152
225
  //# sourceMappingURL=slothlet.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"AA+LA;;;;;;;GAOG;AACH,mBAJU,MAAM,CAIO;AAEvB;;;;;GAKG;AACH,sBAJU,MAAM,CAIU;AAE1B;;;;;GAKG;AACH,wBAJU,MAAM,CAIY;;;;;;;;;UAqtCd,MAAM;;;;;;WAIN,OAAO;;;;;;;;WAGP,MAAM;;;;;;;;aAKN,MAAM;;;;;;;cAKN,MAAM;;;;;;;eAIN,MAAM;;;;;;;;YAIN,OAAO;;;;;;;eAKP,MAAM;;;;;;;wBAIN,OAAO;;;;;;;;4BAIP,OAAO;;;;;;cAKP,MAAM;;;;;;gBAGN,MAAM;;;;;;eAMjB;QAA8B,UAAU,GAA7B,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACW,KAAK,GAClC;YAAqC,KAAK,GAA/B,MAAM,EAAE;YACkB,gBAAgB,GAA1C,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;SACrB;KAAA;;;;;;cAIa,MAAM,OAAO,CAAC,IAAI,CAAC;;;;YACnB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;;;;cACtD,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,GAAC,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC,CAAC;;AArxC/E;;;;;;;;GAQG;AACH,mCAJW,eAAe,GACb,OAAO,CAAC,WAAW,CAAC,CAiChC"}
1
+ {"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"AAk2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,iCAjCW,eAAe,GACb,OAAO,CAAC,WAAW,CAAC,CAsChC;;;;;;;;;SAWa,MAAM;;;;;;;WACN,OAAO,GAAC,MAAM;;;;;;;cAId,OAAO,GAAC,MAAM;;;;eAId,MAAM;;;;cACN,MAAM,GAAC,IAAI;;;;gBACX,MAAM,GAAC,IAAI;;;;YACX;QAAC,KAAK,EAAE,SAAS,GAAC,MAAM,CAAA;KAAC;;;;UAEpC;QAAuD,SAAS,GAArD,MAAM,GAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC;QAGxB,SAAS,GAAtB,MAAM;KAEjB;;;;;;;;WAAW,OAAO,GAAC,MAAM,GAAC,MAAM;;;;;YAKrB,OAAO,GAAC,MAAM;;;;aAEd,OAAO;;;;kBACP,OAAO;;;;eACP,OAAO,GAAC,MAAM;;;;4BACd,OAAO;;;;;WACP,MAAM;;;;;;;;iBAEN,OAAO,GAAC,MAAM,GAAC,QAAQ,GAAC,MAAM;;;;;;;;;;aAW9B,MAAY,IAAI;;;;cAChB,MAAY,IAAI;;;;cAE3B;QAA4B,GAAG,EAC/B;YAAkC,GAAG;YACH,MAAM;YACN,MAAM;SACxC;QAA4B,OAAO,EACnC;YAAsC,GAAG;YACO,OAAO,EAA5C,SAAkB;YACS,GAAG;YACH,KAAK;YACL,GAAG;SACzC;QAA6B,IAAI,GACjC;YAAkC,MAAM,GACxC;gBAAqD,GAAG,GAA7C,SAAkB;gBAC0B,eAAe,GAA3D,MAAY,MAAM,EAAE;gBACY,GAAG;aAC9C;YAAkC,OAAO,GAA9B,MAAM;YACmB,QAAQ;YACE,MAAM,GAAzC,SAAkB;YACiB,YAAY,GAA/C,SAAkB;YACK,IAAI,GAA3B,MAAM;YAC6B,OAAO,GAA1C,SAAkB;YACK,KAAK,GACvC;gBAA0C,GAAG;aAC7C;YAAkC,SAAS,GAAhC,MAAM;YACsC,eAAe,GAA3D,MAAY,eAAe;SACtC;QAA4B,IAAI,EAChC;YAAmC,KAAK;YACL,OAAO;YACP,MAAM;YACN,IAAI;YACJ,GAAG;YACH,EAAE;YACF,MAAM;SACzC;QAA4B,SAAS,EACrC;YAAwC,GAAG;YACH,EAAE;SAC1C;QAA4B,WAAW,EACvC;YAAoD,GAAG,EAA5C,SAAkB;YACY,YAAY,EAA1C,OAAO;YAC0C,IAAI,EAArD,MAAY,OAAO,CAAE,IAAI,CAAC;SACrC;QAA4B,QAAQ,EACpC;YAAsD,MAAM,EAAjD,MAAY,MAAO,IAAI;YACK,GAAG;YACH,MAAM;YACN,SAAS;YACM,IAAI,EAA/C,MAAY,MAAO,IAAI;YACK,GAAG;YACH,MAAM;YACN,SAAS;SAChD;QAA4B,KAAK,EACjC;YAAoC,GAAG;SACvC;QAA4B,SAAS,EACrC;YAAwC,GAAG;YACH,UAAU;SAClD;QAA6B,SAAS,GAA3B,MAAM;QACa,MAAM;QACN,GAAG;QACH,KAAK;QACa,QAAQ,EAA7C,MAAY,OAAO,CAAE,IAAI,CAAC;KACvC;;gCA56B6D,wBAAwB"}
package/types/index.d.mts CHANGED
@@ -11,9 +11,7 @@ export type * from "./dist/slothlet.d.mts";
11
11
  export * from "./dist/slothlet.mts";
12
12
 
13
13
  // Auto-generated named export declarations (these override the re-export above)
14
- export const context: any;
15
- export const reference: any;
16
- export const self: any;
14
+ export const async: any;
17
15
 
18
16
  // Main slothlet export
19
17
  declare const slothlet: any;
@@ -1,21 +0,0 @@
1
- # src/lib Experimental Code
2
-
3
- This folder contains experimental modules for the slothlet API loader. The code here is either not working, partially working, or not fully tested. Use at your own risk.
4
-
5
- ## Purpose
6
-
7
- The files in this folder are prototypes and work-in-progress implementations for advanced features in slothlet, such as:
8
-
9
- - **slothlet_child.mjs**: Experiments with child process or worker-based API loading and isolation.
10
- - **slothlet_engine.mjs**: Attempts to provide a modular engine for API loading, context binding, and shutdown management.
11
- - **slothlet_esm.mjs**: Explores ES module dynamic loading and compatibility.
12
- - **slothlet_helpers.mjs**: Utility functions for API flattening, key conversion, and module handling.
13
- - **slothlet_worker.mjs**: Prototypes for worker thread-based API execution and communication.
14
-
15
- ## Status
16
-
17
- These modules are not guaranteed to work and may be incomplete, buggy, or subject to breaking changes. They are intended for experimentation and future development, not for production use.
18
-
19
- ## Contribution
20
-
21
- If you wish to contribute, please review the code and leave comments or suggestions. Any improvements or bug fixes are welcome, but stability is not guaranteed.
@@ -1,59 +0,0 @@
1
- /*
2
- Copyright 2026 CLDMV/Shinrai
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
-
18
-
19
- import { installGlobalsInCurrentRealm, extendSelfWithReference, installPortalForSelf } from "./slothlet_helpers.mjs";
20
-
21
- let initialized = false;
22
-
23
- process.on("message", async (msg) => {
24
- try {
25
- if (msg.t === "init") {
26
- if (initialized) return;
27
- initialized = true;
28
-
29
- const { entry, loadConfig, contextMap, reference } = msg;
30
-
31
-
32
- installGlobalsInCurrentRealm(contextMap);
33
-
34
-
35
- const { slothlet } = await import(entry);
36
- if (!slothlet) throw new Error("Entry did not export `slothlet`");
37
-
38
- const api = await slothlet.load(loadConfig, { context: contextMap, reference });
39
- globalThis.self = api;
40
-
41
-
42
- extendSelfWithReference(globalThis.self, reference);
43
- installPortalForSelf();
44
-
45
- process.send({ id: msg.id, ok: 1, result: true });
46
- } else if (msg.t === "call") {
47
- const result = await globalThis._portal.call(msg.path, msg.args || []);
48
- process.send({ id: msg.id, ok: 1, result });
49
- } else if (msg.t === "batch") {
50
- const result = await globalThis._portal.batch(msg.ops || []);
51
- process.send({ id: msg.id, ok: 1, result });
52
- } else if (msg.t === "dispose") {
53
- process.send({ id: msg.id, ok: 1, result: true });
54
- process.exit(0);
55
- }
56
- } catch (e) {
57
- process.send({ id: msg.id, ok: 0, error: String(e?.stack || e) });
58
- }
59
- });