@cldmv/slothlet 1.0.3 → 2.1.0

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 (48) hide show
  1. package/README.md +913 -73
  2. package/dist/lib/engine/README.md +21 -0
  3. package/dist/lib/engine/slothlet_child.mjs +58 -0
  4. package/dist/lib/engine/slothlet_engine.mjs +371 -0
  5. package/dist/lib/engine/slothlet_esm.mjs +229 -0
  6. package/dist/lib/engine/slothlet_helpers.mjs +454 -0
  7. package/dist/lib/engine/slothlet_worker.mjs +148 -0
  8. package/dist/lib/helpers/resolve-from-caller.mjs +141 -0
  9. package/dist/lib/helpers/sanitize.mjs +265 -0
  10. package/dist/lib/modes/slothlet_eager.mjs +80 -0
  11. package/dist/lib/modes/slothlet_lazy.mjs +342 -0
  12. package/dist/lib/runtime/runtime.mjs +249 -0
  13. package/dist/slothlet.mjs +1097 -0
  14. package/index.cjs +81 -0
  15. package/index.mjs +76 -0
  16. package/package.json +132 -20
  17. package/types/dist/lib/engine/slothlet_child.d.mts +2 -0
  18. package/types/dist/lib/engine/slothlet_child.d.mts.map +1 -0
  19. package/types/dist/lib/engine/slothlet_engine.d.mts +31 -0
  20. package/types/dist/lib/engine/slothlet_engine.d.mts.map +1 -0
  21. package/types/{src/lib → dist/lib/engine}/slothlet_esm.d.mts +1 -0
  22. package/types/dist/lib/engine/slothlet_esm.d.mts.map +1 -0
  23. package/types/{src/lib → dist/lib/engine}/slothlet_helpers.d.mts +2 -2
  24. package/types/dist/lib/engine/slothlet_helpers.d.mts.map +1 -0
  25. package/types/dist/lib/engine/slothlet_worker.d.mts +2 -0
  26. package/types/dist/lib/engine/slothlet_worker.d.mts.map +1 -0
  27. package/types/dist/lib/helpers/resolve-from-caller.d.mts +149 -0
  28. package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -0
  29. package/types/dist/lib/helpers/sanitize.d.mts +79 -0
  30. package/types/dist/lib/helpers/sanitize.d.mts.map +1 -0
  31. package/types/dist/lib/modes/slothlet_eager.d.mts +66 -0
  32. package/types/dist/lib/modes/slothlet_eager.d.mts.map +1 -0
  33. package/types/dist/lib/modes/slothlet_lazy.d.mts +32 -0
  34. package/types/dist/lib/modes/slothlet_lazy.d.mts.map +1 -0
  35. package/types/dist/lib/runtime/runtime.d.mts +49 -0
  36. package/types/dist/lib/runtime/runtime.d.mts.map +1 -0
  37. package/types/dist/slothlet.d.mts +124 -0
  38. package/types/dist/slothlet.d.mts.map +1 -0
  39. package/types/index.d.mts +23 -0
  40. package/slothlet.mjs +0 -1248
  41. package/types/debug-slothlet.d.mts +0 -1
  42. package/types/eslint.config.d.mts +0 -2
  43. package/types/jest.config.d.mts +0 -6
  44. package/types/slothlet.d.mts +0 -189
  45. package/types/src/lib/slothlet_child.d.mts +0 -1
  46. package/types/src/lib/slothlet_engine.d.mts +0 -6
  47. package/types/src/lib/slothlet_worker.d.mts +0 -1
  48. package/types/vitest.config.d.ts +0 -2
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,6 +0,0 @@
1
- declare namespace _default {
2
- let testMatch: string[];
3
- let testEnvironment: string;
4
- let testPathIgnorePatterns: string[];
5
- }
6
- export default _default;
@@ -1,189 +0,0 @@
1
- /**
2
- * Updates the live-binding references for self, context, and reference.
3
- * Call this whenever a new API instance is created.
4
- * Ensures submodules can import and use `self`, `context`, and `reference` directly.
5
- *
6
- * @param {object} newContext - The current context object to bind as `context`.
7
- * @param {object} newReference - The current reference object to bind as `reference`.
8
- * @param {object} newSelf - The current API object instance to bind as `self`.
9
- *
10
- * @example
11
- * // Update live bindings after creating a new API instance
12
- * updateBindings(api, { user: 'alice' }, { custom: 123 });
13
- * // Submodules can now use imported self, context, reference
14
- * self.math.add(1, 2);
15
- * context.user; // 'alice'
16
- * reference.custom; // 123
17
- */
18
- export function updateBindings(newContext: object, newReference: object, newSelf?: object): void;
19
- /**
20
- * Live-binding references for API object (self) and context.
21
- * These are updated whenever a new API instance is created.
22
- * Dynamically imported modules can access these at runtime.
23
- * @type {object}
24
- */
25
- export let self: object;
26
- /**
27
- * Live-binding reference for contextual data.
28
- * @type {object}
29
- */
30
- export let context: object;
31
- /**
32
- * Live-binding reference for ref data.
33
- * @type {object}
34
- */
35
- export let reference: object;
36
- export namespace slothlet {
37
- let api: any;
38
- let boundapi: any;
39
- let mode: string;
40
- let loaded: boolean;
41
- namespace config {
42
- export let lazy: boolean;
43
- export let lazyDepth: number;
44
- export { DEBUG as debug };
45
- export let dir: any;
46
- }
47
- let _dispose: any;
48
- let _boundAPIShutdown: any;
49
- function create(options?: {}): Promise<any>;
50
- /**
51
- * Returns the loaded API object (Proxy or plain).
52
- * @returns {object}
53
- */
54
- function getApi(): object;
55
- /**
56
- * Returns the loaded API object (Proxy or plain).
57
- * @returns {object}
58
- */
59
- function getBoundApi(): object;
60
- /**
61
- * Shuts down both the bound API and internal resources, with timeout and error handling.
62
- * Prevents infinite recursion if called from Proxy.
63
- * @returns {Promise<void>}
64
- */
65
- function shutdown(): Promise<void>;
66
- /**
67
- * Loads the bindleApi modules, either lazily or eagerly.
68
- *
69
- * @param {object} [config] - Loader configuration options.
70
- * @param {boolean} [config.lazy=true] - If true, enables lazy loading (API modules loaded on demand).
71
- * @param {number} [config.lazyDepth=Infinity] - How deep to lazy load (subdirectory depth; use Infinity for full lazy loading).
72
- * @param {string} [config.dir] - Directory to load API modules from. Defaults to the loader's directory (__dirname).
73
- * @returns {Promise<object>} The API object. If lazy loading is enabled, returns a Proxy that loads modules on access; otherwise, returns a fully loaded API object.
74
- *
75
- * @example
76
- * // Lazy load from default directory
77
- * await slothlet.load({ lazy: true });
78
- *
79
- * // Eager load from a custom directory
80
- * await slothlet.load({ lazy: false, dir: '/custom/path/to/api' });
81
- *
82
- * // Access API endpoints
83
- * const api = slothlet.createBoundApi(ctx);
84
- * const result = await api.fs.ensureDir('/some/path');
85
- */
86
- function load(config?: {
87
- lazy?: boolean;
88
- lazyDepth?: number;
89
- dir?: string;
90
- }, ctxRef?: {
91
- context: any;
92
- reference: any;
93
- }): Promise<object>;
94
- /**
95
- * Eagerly loads all API modules (same as original loader).
96
- * @param {string} dir - Directory to load
97
- * @returns {Promise<object>} API object
98
- * @private
99
- */
100
- function _eagerLoadApi(dir: string, rootLevel?: boolean): Promise<object>;
101
- /**
102
- * Converts a filename or folder name to camelCase for API property.
103
- * @param {string} name
104
- * @returns {string}
105
- * @example
106
- * toApiKey('root-math') // 'rootMath'
107
- */
108
- function _toApiKey(name: string): string;
109
- /**
110
- * Eagerly loads a category (same flattening logic as original).
111
- * @param {string} categoryPath
112
- * @returns {Promise<object>}
113
- * @private
114
- */
115
- function _eagerLoadCategory(categoryPath: string): Promise<object>;
116
- /**
117
- * Loads a single module file and returns its exports (flattened if needed).
118
- * @param {string} modulePath
119
- * @returns {Promise<object>}
120
- * @private
121
- */
122
- function _loadSingleModule(modulePath: string, rootLevel?: boolean): Promise<object>;
123
- /**
124
- * Creates a lazy API proxy for a directory.
125
- * @param {string} dir - Directory path.
126
- * @param {number} [depth=0] - Recursion depth.
127
- * @returns {Proxy} Proxy object for lazy API loading.
128
- * @private
129
- */
130
- function _createLazyApiProxy(dir: string, depth?: number, rootLevel?: boolean): ProxyConstructor;
131
- function _createLazyApiProxy2(dir: any, depth?: number, rootLevel?: boolean): Promise<any>;
132
- /**
133
- * Updates the live-binding references for self and context.
134
- * Call this whenever a new API instance is created.
135
- * @param {object} newContext - The current context object to bind as `context`.
136
- * @param {object} newReference - The current reference object to bind as `reference`.
137
- * @param {object} newSelf - The current API object instance to bind as `self`.
138
- */
139
- function updateBindings(newContext: object, newReference: object, newSelf?: object): void;
140
- /**
141
- * Creates a bound API object with live-bound self, context, and reference.
142
- * Ensures submodules can access `self`, `context`, and `reference` directly.
143
- * Works for both eager and lazy loading modes.
144
- *
145
- * @param {object} [ctx=null] - Context object to be spread into the API and live-bound.
146
- * @param {object|object[]} [ref=null] - Reference object(s) to extend the API/self with additional properties.
147
- * @returns {object} Bound API object (Proxy or plain) with live-bound self, context, and reference.
148
- *
149
- * @example
150
- * // Create API with context and reference
151
- * const api = slothlet.createBoundApi({ user: 'alice' }, { custom: 123 });
152
- *
153
- * // Access API endpoints
154
- * api.math.add(2, 3); // 5
155
- *
156
- * // Access live-bound self and context
157
- * api.self.math.add(1, 2); // 3
158
- * api.context.user; // 'alice'
159
- * api.reference.custom; // 123
160
- *
161
- * // Submodules can import { self, context, reference } from the loader
162
- * // and use them directly: self.math.add(...)
163
- */
164
- function createBoundApi(ctx?: object, ref?: object | object[]): object;
165
- /**
166
- * Recursively builds a bound API from an eagerly loaded API object.
167
- * @param {object} apiModules
168
- * @returns {object}
169
- * @private
170
- */
171
- function _buildCompleteApi(apiModules: object): object;
172
- /**
173
- * Wraps the lazy API proxy so that modules are loaded and built with context on access.
174
- * @param {Proxy} proxyApi
175
- * @returns {Proxy}
176
- * @private
177
- */
178
- function _createBoundLazyApi(proxyApi: ProxyConstructor): ProxyConstructor;
179
- /**
180
- * Checks if the API has been loaded.
181
- * @returns {boolean}
182
- */
183
- function isLoaded(): boolean;
184
- }
185
- export default slothlet;
186
- /**
187
- * DEBUG mode: configurable via command line (--slothletdebug), environment variable (SLOTHLET_DEBUG), or defaults to false.
188
- */
189
- declare let DEBUG: boolean;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export function setShutdown(fn: any): any;
2
- export function createEngine(allOptions: any): Promise<{
3
- api: () => void;
4
- dispose: () => Promise<void>;
5
- }>;
6
- export function makeFacade2(portal: any): () => void;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;