@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
package/index.cjs ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview CommonJS entry point for @cldmv/slothlet with automatic source/dist detection and live-binding context.
3
+ * @module @cldmv/slothlet
4
+ */
5
+
6
+ const runtimePromise = import("@cldmv/slothlet/runtime");
7
+ const modPromise = import("@cldmv/slothlet/slothlet");
8
+
9
+ // Development environment check (must happen before slothlet imports)
10
+ (async () => {
11
+ try {
12
+ await import("@cldmv/slothlet/devcheck");
13
+ } catch {
14
+ // ignore
15
+ }
16
+ })();
17
+
18
+ /**
19
+ * Creates a slothlet API instance with live-binding context and AsyncLocalStorage support.
20
+ * Automatically wraps all API functions with context isolation for multi-instance support.
21
+ * @public
22
+ * @async
23
+ *
24
+ * @param {object} [options={}] - Configuration options for the slothlet instance
25
+ * @param {string} [options.dir="api"] - Directory to load API modules from
26
+ * @param {boolean} [options.lazy=false] - Use lazy loading (true) or eager loading (false)
27
+ * @param {number} [options.apiDepth=Infinity] - Maximum directory depth to scan
28
+ * @param {boolean} [options.debug=false] - Enable debug logging
29
+ * @param {string} [options.mode="singleton"] - Execution mode (singleton, vm, worker, fork)
30
+ * @param {string} [options.api_mode="auto"] - API structure mode (auto, function, object)
31
+ * @param {object} [options.context={}] - Context data for live bindings
32
+ * @param {object} [options.reference={}] - Reference objects to merge into API root
33
+ * @returns {Promise<function|object>} The bound API object with live-binding context
34
+ *
35
+ * @example // CJS
36
+ * const slothlet = require('@cldmv/slothlet');
37
+ * const api = await slothlet({ dir: './api', context: { user: 'alice' } });
38
+ * console.log(api.config.username); // Access configuration
39
+ */
40
+ async function slothlet(options = {}) {
41
+ const [runtime, mod] = await Promise.all([runtimePromise, modPromise]);
42
+ const { makeWrapper } = runtime;
43
+ const build = mod.slothlet ?? mod.default;
44
+
45
+ const api = await build(options);
46
+
47
+ // Prefer an explicit instance context the internal attached to the API (api.__ctx),
48
+ // else fall back to module-level pieces if you expose them.
49
+ const ctx = api?.__ctx ?? { self: mod.self, context: mod.context, reference: mod.reference };
50
+
51
+ // console.log("[DEBUG index.cjs] Context setup:", {
52
+ // hasApiCtx: !!api?.__ctx,
53
+ // ctxSelfType: typeof ctx.self,
54
+ // ctxSelfKeys: Object.keys(ctx.self || {}),
55
+ // ctxContextType: typeof ctx.context,
56
+ // ctxContextKeys: Object.keys(ctx.context || {}),
57
+ // ctxReferenceType: typeof ctx.reference,
58
+ // ctxReferenceKeys: Object.keys(ctx.reference || {}),
59
+ // fallbackToMod: !api?.__ctx
60
+ // });
61
+
62
+ return makeWrapper(ctx)(api);
63
+ }
64
+
65
+ /**
66
+ * CommonJS default export of the slothlet function.
67
+ * @public
68
+ */
69
+ module.exports = slothlet;
70
+
71
+ /**
72
+ * Named export alias for the slothlet function.
73
+ * Provides the same functionality as the default export.
74
+ * @public
75
+ * @type {Function}
76
+ *
77
+ * @example // CJS named destructuring
78
+ * const { slothlet } = require('@cldmv/slothlet');
79
+ * const api = await slothlet({ dir: './api' });
80
+ */
81
+ module.exports.slothlet = slothlet; // optional named alias
package/index.mjs ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @fileoverview ESM entry point for @cldmv/slothlet with automatic source/dist detection and live-binding context.
3
+ * @module @cldmv/slothlet
4
+ */
5
+
6
+ // Development environment check (must happen before slothlet imports)
7
+ (async () => {
8
+ try {
9
+ await import("@cldmv/slothlet/devcheck");
10
+ } catch {
11
+ // ignore
12
+ }
13
+ })();
14
+
15
+ /**
16
+ * Creates a slothlet API instance with live-binding context and AsyncLocalStorage support.
17
+ * Automatically wraps all API functions with context isolation for multi-instance support.
18
+ * @public
19
+ * @async
20
+ *
21
+ * @param {object} [options={}] - Configuration options for the slothlet instance
22
+ * @param {string} [options.dir="api"] - Directory to load API modules from
23
+ * @param {boolean} [options.lazy=false] - Use lazy loading (true) or eager loading (false)
24
+ * @param {number} [options.apiDepth=Infinity] - Maximum directory depth to scan
25
+ * @param {boolean} [options.debug=false] - Enable debug logging
26
+ * @param {string} [options.mode="singleton"] - Execution mode (singleton, vm, worker, fork)
27
+ * @param {string} [options.api_mode="auto"] - API structure mode (auto, function, object)
28
+ * @param {object} [options.context={}] - Context data for live bindings
29
+ * @param {object} [options.reference={}] - Reference objects to merge into API root
30
+ * @returns {Promise<function|object>} The bound API object with live-binding context
31
+ *
32
+ * @example // ESM
33
+ * import slothlet from '@cldmv/slothlet';
34
+ * const api = await slothlet({ dir: './api', lazy: true });
35
+ * const result = await api.math.add(2, 3); // 5
36
+ *
37
+ */
38
+ export default async function slothlet(options = {}) {
39
+ // Dynamic imports after environment check
40
+ const [runtime, mod] = await Promise.all([import("@cldmv/slothlet/runtime"), import("@cldmv/slothlet/slothlet")]);
41
+
42
+ const { makeWrapper } = runtime;
43
+ const build = mod.slothlet ?? mod.default;
44
+
45
+ const api = await build(options);
46
+
47
+ // Prefer an explicit instance context the internal attached to the API (api.__ctx),
48
+ // else fall back to module-level pieces if you expose them.
49
+ const ctx = api?.__ctx ?? { self: mod.self, context: mod.context, reference: mod.reference };
50
+
51
+ // console.log("[DEBUG index.mjs] Context setup:", {
52
+ // hasApiCtx: !!api?.__ctx,
53
+ // ctxSelfType: typeof ctx.self,
54
+ // ctxSelfKeys: Object.keys(ctx.self || {}),
55
+ // ctxContextType: typeof ctx.context,
56
+ // ctxContextKeys: Object.keys(ctx.context || {}),
57
+ // ctxReferenceType: typeof ctx.reference,
58
+ // ctxReferenceKeys: Object.keys(ctx.reference || {}),
59
+ // fallbackToMod: !api?.__ctx
60
+ // });
61
+ // return api;
62
+ return makeWrapper(ctx)(api);
63
+ }
64
+
65
+ /**
66
+ * Named export alias for the default slothlet function.
67
+ * Provides the same functionality as the default export.
68
+ * @public
69
+ * @type {Function}
70
+ *
71
+ * @example // ESM named import
72
+ * import { slothlet } from '@cldmv/slothlet';
73
+ * const api = await slothlet({ dir: './api' });
74
+ */
75
+ // Optional named alias
76
+ export { slothlet };
package/package.json CHANGED
@@ -1,34 +1,123 @@
1
1
  {
2
2
  "name": "@cldmv/slothlet",
3
- "version": "1.0.3",
4
- "description": "Slothlet: Lazy Modular API Loader for Node.js. Dynamically loads API modules and submodules only when accessed, supporting both lazy and eager loading.",
5
- "main": "slothlet.mjs",
3
+ "version": "2.1.0",
4
+ "moduleVersions": {
5
+ "lazy": "1.0.0",
6
+ "eager": "1.0.0"
7
+ },
8
+ "description": "Slothlet: Modular API Loader for Node.js. Lazy mode dynamically loads API modules and submodules only when accessed, supporting both lazy and eager loading.",
9
+ "main": "./index.cjs",
10
+ "module": "./index.mjs",
6
11
  "exports": {
7
12
  ".": {
8
- "types": "./types/slothlet.d.ts",
9
- "import": "./slothlet.mjs",
10
- "default": "./slothlet.mjs"
13
+ "types": "./types/index.d.mts",
14
+ "import": "./index.mjs",
15
+ "require": "./index.cjs"
16
+ },
17
+ "./devcheck": {
18
+ "types": "./types/devcheck.d.mts",
19
+ "import": "./devcheck.mjs"
20
+ },
21
+ "./slothlet": {
22
+ "development": {
23
+ "types": "./types/src/slothlet.d.mts",
24
+ "import": "./src/slothlet.mjs"
25
+ },
26
+ "types": "./types/dist/slothlet.d.mts",
27
+ "import": "./dist/slothlet.mjs"
28
+ },
29
+ "./runtime": {
30
+ "development": {
31
+ "types": "./types/src/lib/runtime/runtime.d.mts",
32
+ "import": "./src/lib/runtime/runtime.mjs"
33
+ },
34
+ "types": "./types/dist/lib/runtime/runtime.d.mts",
35
+ "import": "./dist/lib/runtime/runtime.mjs"
36
+ },
37
+ "./helpers/*": {
38
+ "development": {
39
+ "types": "./types/src/lib/helpers/*.d.mts",
40
+ "import": "./src/lib/helpers/*.mjs"
41
+ },
42
+ "types": "./types/dist/lib/helpers/*.d.mts",
43
+ "import": "./dist/lib/helpers/*.mjs"
44
+ },
45
+ "./modes/*": {
46
+ "development": {
47
+ "types": "./types/src/lib/modes/*.d.mts",
48
+ "import": "./src/lib/modes/*.mjs"
49
+ },
50
+ "types": "./types/dist/lib/modes/*.d.mts",
51
+ "import": "./dist/lib/modes/*.mjs"
11
52
  }
12
53
  },
13
- "types": "./types/slothlet.d.ts",
14
- "directories": {
15
- "test": "tests"
16
- },
54
+ "types": "./types/index.d.mts",
17
55
  "scripts": {
18
- "publish": "npm publish --access public",
19
- "test": "vitest run",
20
- "testjest": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js"
56
+ "publish:manual": "npm publish --access public",
57
+ "test": "node tests/test-conditional.mjs",
58
+ "test:pre-build": "node tests/test-conditional.mjs",
59
+ "test:post-build": "npm run test:types",
60
+ "test:complete": "node tests/test-conditional.mjs && npm run test:post-build",
61
+ "test:unit": "vitest --config .configs/vitest.config.mjs run",
62
+ "test:node": "node tests/run-all-tests.mjs",
63
+ "test:all": "node tests/test-conditional.mjs && npm run test:node",
64
+ "test:types": "node tests/validate-typescript.mjs",
65
+ "debug": "node tests/debug-slothlet.mjs",
66
+ "test:entry": "node tests/test-entry-points.mjs",
67
+ "test:performance": "node tests/performance-benchmark.mjs",
68
+ "test:performance-aggregated": "node tests/performance-benchmark-aggregated.mjs",
69
+ "lint": "eslint --config .configs/eslint.config.mjs .",
70
+ "build": "node tools/build-with-tests.mjs",
71
+ "build:ci": "npm run build:cleanup && npm run build:dist && npm run build:types && npm run build:exports && npm run test:types && npm run build:prepend-license",
72
+ "build:unsafe": "npm run build:cleanup && npm run build:dist && npm run build:types && npm run build:exports && npm run test:types && npm run build:prepend-license",
73
+ "build:cleanup": "shx rm -rf types && shx rm -rf dist",
74
+ "build:dist": "shx mkdir -p dist && shx cp -r src/* dist/ && shx rm -rf dist/**/*.backup",
75
+ "build:types": "npx tsc -p .configs/tsconfig.dts.jsonc",
76
+ "build:docs": "npm run build:docs:slothlet && npm run build:docs:api-tests",
77
+ "build:docs:slothlet": "jsdoc2md -g grouped -m dl --no-cache --separators -c \".configs/jsdoc.config.json\" --helper \"docs/helpers.cjs\" --template \"docs/template.hbs\" \"src/{slothlet.mjs,lib/{modes,helpers,runtime}/**/*.mjs}\" > docs/API.md",
78
+ "build:docs:api-tests": "npm run build:docs:api-test && npm run build:docs:api-test-cjs && npm run build:docs:api-test-mixed",
79
+ "build:docs:api-test": "shx mkdir -p docs/api_tests && jsdoc2md -g grouped -m dl --no-cache --separators -c \".configs/jsdoc.config.json\" --helper \"docs/helpers.cjs\" --template \"docs/template.hbs\" \"api_tests/api_test/**/*.mjs\" > docs/api_tests/api_test.md",
80
+ "build:docs:api-test-cjs": "shx mkdir -p docs/api_tests && jsdoc2md -g grouped -m dl --no-cache --separators -c \".configs/jsdoc.config.json\" --helper \"docs/helpers.cjs\" --template \"docs/template.hbs\" \"api_tests/api_test_cjs/**/*.{mjs,cjs}\" > docs/api_tests/api_test_cjs.md",
81
+ "build:docs:api-test-mixed": "shx mkdir -p docs/api_tests && jsdoc2md -g grouped -m dl --no-cache --separators -c \".configs/jsdoc.config.json\" --helper \"docs/helpers.cjs\" --template \"docs/template.hbs\" \"api_tests/api_test_mixed/**/*.{mjs,cjs}\" > docs/api_tests/api_test_mixed.md",
82
+ "build:docs:tools": "shx mkdir -p docs/tools && jsdoc2md -g grouped -m dl --no-cache --separators -c \".configs/jsdoc.config.json\" --helper \"docs/helpers.cjs\" --template \"docs/template.hbs\" \"tools/**/*.mjs\" > docs/tools/build-tools.md",
83
+ "build:exports": "node tools/build-exports.mjs",
84
+ "build:prepend-license": "node tools/prepend-license.mjs dist",
85
+ "prepublish-check": "npm run build && npm pack && node tools/prepublish-check.mjs"
21
86
  },
22
87
  "keywords": [
23
88
  "api",
89
+ "api-loader",
90
+ "api-management",
91
+ "module-loader",
24
92
  "lazy-loading",
93
+ "eager-loading",
94
+ "copy-left-materialization",
95
+ "proxy",
96
+ "asynclocalstorage",
97
+ "live-binding",
98
+ "context-isolation",
99
+ "dual-loading",
25
100
  "modular",
101
+ "performance",
102
+ "optimization",
103
+ "startup-performance",
26
104
  "nodejs",
27
- "esm"
105
+ "esm",
106
+ "cjs",
107
+ "mixed-modules",
108
+ "dynamic-import",
109
+ "deferred-loading",
110
+ "framework",
111
+ "typescript",
112
+ "zero-dependencies"
28
113
  ],
114
+ "engines": {
115
+ "node": ">=16.4.0"
116
+ },
29
117
  "author": {
30
118
  "name": "Shinrai",
31
- "email": "git@cldmv.net",
119
+ "company": "CLDMV",
120
+ "email": "git+npm@cldmv.net",
32
121
  "url": "https://cldmv.net"
33
122
  },
34
123
  "contributors": [
@@ -38,9 +127,28 @@
38
127
  }
39
128
  ],
40
129
  "license": "Apache-2.0",
130
+ "funding": {
131
+ "type": "github",
132
+ "url": "https://github.com/sponsors/shinrai"
133
+ },
41
134
  "type": "module",
42
135
  "devDependencies": {
43
- "jest": "^30.0.5",
136
+ "@eslint/css": "^0.10.0",
137
+ "@eslint/js": "^9.33.0",
138
+ "@eslint/json": "^0.13.1",
139
+ "@eslint/markdown": "^7.2.0",
140
+ "@html-eslint/eslint-plugin": "^0.45.0",
141
+ "@html-eslint/parser": "^0.45.0",
142
+ "chalk": "^5.6.0",
143
+ "dmd": "^7.1.1",
144
+ "eslint": "^9.33.0",
145
+ "jsdoc": "^4.0.4",
146
+ "jsdoc-to-markdown": "^9.1.2",
147
+ "jsdoc2md": "^1.0.0",
148
+ "jsonc-parser": "^3.3.1",
149
+ "prettier": "^3.3.3",
150
+ "shx": "^0.4.0",
151
+ "typescript": "^5.9.2",
44
152
  "vest": "^5.4.6",
45
153
  "vitest": "^3.2.4"
46
154
  },
@@ -55,12 +163,16 @@
55
163
  "publishConfig": {
56
164
  "access": "public"
57
165
  },
166
+ "prepack": "npm run build:ci",
58
167
  "files": [
168
+ "index.mjs",
169
+ "index.cjs",
59
170
  "README.md",
60
171
  "LICENSE",
61
- "types/"
172
+ "types/dist/",
173
+ "types/index.d.mts",
174
+ "types/index.d.mts.map",
175
+ "dist/"
62
176
  ],
63
- "dependencies": {
64
- "typescript": "^5.9.2"
65
- }
177
+ "sideEffects": false
66
178
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=slothlet_child.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slothlet_child.d.mts","sourceRoot":"","sources":["../../../../dist/lib/engine/slothlet_child.mjs"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Sets the shutdown function for the engine.
3
+ * @param {Function} fn - Shutdown function to set
4
+ * @returns {Function} Previously set shutdown function
5
+ * @example
6
+ * const prev = setShutdown(() => console.log('Shutting down'));
7
+ */
8
+ export function setShutdown(fn: Function): Function;
9
+ /**
10
+ * Creates a slothlet engine with the specified mode and options.
11
+ * @param {object} allOptions - Engine configuration options
12
+ * @param {string} allOptions.entry - Entry point for the slothlet module
13
+ * @param {string} [allOptions.mode="vm"] - Engine mode: "vm", "worker", "fork", or "child"
14
+ * @param {object} [allOptions.context] - Context object for modules
15
+ * @param {object} [allOptions.reference] - Reference object for modules
16
+ * @returns {Promise<object>} Engine instance with API and shutdown capabilities
17
+ * @example
18
+ * const engine = await createEngine({
19
+ * entry: './api/index.mjs',
20
+ * mode: 'vm',
21
+ * context: { user: 'alice' }
22
+ * });
23
+ */
24
+ export function createEngine(allOptions: {
25
+ entry: string;
26
+ mode?: string;
27
+ context?: object;
28
+ reference?: object;
29
+ }): Promise<object>;
30
+ export function makeFacade2(portal: any): () => void;
31
+ //# sourceMappingURL=slothlet_engine.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slothlet_engine.d.mts","sourceRoot":"","sources":["../../../../dist/lib/engine/slothlet_engine.mjs"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,oDAIC;AAED;;;;;;;;;;;;;;GAcG;AACH,yCAZG;IAA2B,KAAK,EAAxB,MAAM;IACc,IAAI,GAAxB,MAAM;IACc,OAAO,GAA3B,MAAM;IACc,SAAS,GAA7B,MAAM;CACd,GAAU,OAAO,CAAC,MAAM,CAAC,CAgC3B;AAyRD,qDA4BC"}
@@ -16,3 +16,4 @@ export function loadEsmModuleFallback(context: object, fileUrl: string, visited?
16
16
  * @returns {Promise<boolean>}
17
17
  */
18
18
  export function isEsmFile(fileUrl: string): Promise<boolean>;
19
+ //# sourceMappingURL=slothlet_esm.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slothlet_esm.d.mts","sourceRoot":"","sources":["../../../../dist/lib/engine/slothlet_esm.mjs"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,+CAPW,MAAM,WACN,MAAM,YACN,GAAG,CAAC,MAAM,CAAC,GACT,OAAO,CAAC,MAAM,CAAC,CAkM3B;AAED;;;;GAIG;AACH,mCAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAW5B"}
@@ -5,7 +5,7 @@ export function installPortalForSelf(): void;
5
5
  export function asUrl(p: any): any;
6
6
  export function isPlainObject(o: any): boolean;
7
7
  export function guessName(v: any): any;
8
- export function makeNodeishContext(): vm.Context;
8
+ export function makeNodeishContext(): any;
9
9
  /**
10
10
  * Loads a module into a VM context, supporting ESM (mjs), CJS (cjs), or auto-detection.
11
11
  * @param {object} context - The VM context.
@@ -21,4 +21,4 @@ export function marshalArgsReplaceFunctions(value: any, registerCb: any): any;
21
21
  export function reviveArgsReplaceTokens(value: any, invokeCb: any): any;
22
22
  export function containsFunction(value: any): boolean;
23
23
  export const HAS_STM: boolean;
24
- import vm from "node:vm";
24
+ //# sourceMappingURL=slothlet_helpers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slothlet_helpers.d.mts","sourceRoot":"","sources":["../../../../dist/lib/engine/slothlet_helpers.mjs"],"names":[],"mappings":"AAWA,gDAwBC;AAED,oEAGC;AAED,yEAYC;AAED,6CA6BC;AAED,mCAEC;AAED,+CAEC;AAED,uCAOC;AAQD,0CAyBC;AAED;;;;;;GAMG;AACH,sCALW,MAAM,WACN,MAAM,SACN,MAAM,mBACJ,OAAO,CAAC,MAAM,CAAC,CA2L3B;AAGD,sEAsDC;AAED,8EAYC;AAED,yGAmDC;AAID,8EAaC;AAED,wEAaC;AAED,sDAKC;AAhYD,8BAAiE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=slothlet_worker.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slothlet_worker.d.mts","sourceRoot":"","sources":["../../../../dist/lib/engine/slothlet_worker.mjs"],"names":[],"mappings":""}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @function getStack
3
+ * @package
4
+ * @internal
5
+ * @param {Function} [skipFn] - Function to skip in stack trace via Error.captureStackTrace
6
+ * @returns {Array<CallSite>} Array of V8 CallSite objects with methods like getFileName(), getLineNumber(), etc.
7
+ *
8
+ * @description
9
+ * Get V8 stack trace as CallSite array for debugging and caller detection.
10
+ * Temporarily overrides Error.prepareStackTrace to access raw V8 CallSite objects
11
+ * instead of formatted string stack traces. Provides safe restoration of original handler.
12
+ *
13
+ * @example
14
+ * // Get current call stack for debugging
15
+ * const stack = getStack();
16
+ * console.log(stack[0]?.getFileName?.()); // Current file path
17
+ * console.log(stack[0]?.getLineNumber?.()); // Current line number
18
+ *
19
+ * @example
20
+ * // Skip current function from stack trace
21
+ * function myFunction() {
22
+ * return getStack(myFunction); // Stack starts from caller of myFunction
23
+ * }
24
+ * const callerStack = myFunction();
25
+ *
26
+ * @example
27
+ * // Stack analysis for caller detection
28
+ * function findCaller() {
29
+ * const stack = getStack(findCaller);
30
+ * for (const frame of stack) {
31
+ * const filename = frame?.getFileName?.();
32
+ * if (filename && !filename.includes('node_modules')) {
33
+ * return filename; // First non-dependency file
34
+ * }
35
+ * }
36
+ * }
37
+ */
38
+ export function getStack(skipFn?: Function): Array<CallSite>;
39
+ /**
40
+ * @function resolvePathFromCaller
41
+ * @package
42
+ * @internal
43
+ * @param {string} rel - Relative path to resolve (e.g., '../config.json', './data/file.txt')
44
+ * @returns {string} Absolute filesystem path with platform-specific separators
45
+ * @throws {TypeError} When rel parameter is not a string
46
+ *
47
+ * @description
48
+ * Resolve a relative path from the caller's context to an absolute filesystem path.
49
+ * Primary public API for filesystem path resolution with intelligent caller detection.
50
+ * Uses sophisticated stack trace analysis to determine the appropriate base directory.
51
+ *
52
+ * Resolution behavior:
53
+ * - file:// URLs: Converted to filesystem paths via fileURLToPath()
54
+ * - Absolute paths: Returned unchanged (already absolute)
55
+ * - Relative paths: Resolved using caller detection algorithm
56
+ *
57
+ * Caller detection process:
58
+ * 1. Primary: Use sophisticated slothlet.mjs-aware stack analysis
59
+ * 2. Fallback: Use first non-helper frame if primary fails
60
+ * 3. Existence check: Prefer primary if target exists, otherwise use fallback
61
+ *
62
+ * @example
63
+ * // From a file at /project/src/modules/math.mjs
64
+ * const configPath = resolvePathFromCaller('../config.json');
65
+ * // Returns: /project/config.json (absolute filesystem path)
66
+ *
67
+ * @example
68
+ * // Short-circuit cases
69
+ * resolvePathFromCaller('file:///absolute/path.txt');
70
+ * // Returns: /absolute/path.txt (converted from URL)
71
+ *
72
+ * resolvePathFromCaller('/already/absolute/path.txt');
73
+ * // Returns: /already/absolute/path.txt (unchanged)
74
+ *
75
+ * @example
76
+ * // Relative resolution from different contexts
77
+ * // If called from /project/src/lib/utils.mjs:
78
+ * resolvePathFromCaller('./helpers/format.js');
79
+ * // Returns: /project/src/lib/helpers/format.js
80
+ *
81
+ * resolvePathFromCaller('../../config/settings.json');
82
+ * // Returns: /project/config/settings.json
83
+ */
84
+ export function resolvePathFromCaller(rel: string): string;
85
+ /**
86
+ * @function resolveUrlFromCaller
87
+ * @package
88
+ * @internal
89
+ * @param {string} rel - Relative path to resolve (e.g., '../config.json', './data/file.txt')
90
+ * @returns {string} Absolute file:// URL suitable for dynamic imports and URL operations
91
+ * @throws {TypeError} When rel parameter is not a string
92
+ *
93
+ * @description
94
+ * Resolve a relative path from the caller's context to a file:// URL.
95
+ * Companion API to resolvePathFromCaller that returns file:// URLs instead of filesystem paths.
96
+ * Uses identical caller detection algorithm but outputs URL format for ESM imports.
97
+ *
98
+ * Resolution behavior:
99
+ * - file:// URLs: Returned unchanged (already in URL format)
100
+ * - Absolute paths: Converted to file:// URLs via pathToFileURL()
101
+ * - Relative paths: Resolved using caller detection, then converted to URL
102
+ *
103
+ * Caller detection uses the same sophisticated algorithm as resolvePathFromCaller,
104
+ * but the final result is converted to a file:// URL for compatibility with
105
+ * ESM dynamic imports and other URL-based operations.
106
+ *
107
+ * @example
108
+ * // From a file at /project/src/modules/math.mjs
109
+ * const configUrl = resolveUrlFromCaller('../config.json');
110
+ * // Returns: file:///project/config.json (absolute file:// URL)
111
+ *
112
+ * @example
113
+ * // Short-circuit cases
114
+ * resolveUrlFromCaller('file:///absolute/path.txt');
115
+ * // Returns: file:///absolute/path.txt (unchanged)
116
+ *
117
+ * resolveUrlFromCaller('/already/absolute/path.txt');
118
+ * // Returns: file:///already/absolute/path.txt (converted to URL)
119
+ *
120
+ * @example
121
+ * // Dynamic ESM import usage
122
+ * const modulePath = resolveUrlFromCaller('./dynamic-module.mjs');
123
+ * const dynamicModule = await import(modulePath);
124
+ * // Works seamlessly with ESM import() which expects URLs
125
+ *
126
+ * @example
127
+ * // Cross-platform URL handling
128
+ * // Unix: resolveUrlFromCaller('../config.json') → file:///project/config.json
129
+ * // Windows: resolveUrlFromCaller('../config.json') → file:///C:/project/config.json
130
+ */
131
+ export function resolveUrlFromCaller(rel: string): string;
132
+ export function toFsPath(v: any): string | null;
133
+ export type CallSite = {
134
+ getFileName: () => string | undefined;
135
+ getLineNumber: () => number | undefined;
136
+ getFunctionName: () => string | undefined;
137
+ getTypeName: () => string | undefined;
138
+ getMethodName: () => string | undefined;
139
+ getScriptNameOrSourceURL: () => string | undefined;
140
+ getColumnNumber: () => number | undefined;
141
+ isNative: () => boolean | undefined;
142
+ isEval: () => boolean | undefined;
143
+ isConstructor: () => boolean | undefined;
144
+ isToplevel: () => boolean | undefined;
145
+ isAsync: () => boolean | undefined;
146
+ isPromiseAll: () => boolean | undefined;
147
+ getPromiseIndex: () => number | undefined;
148
+ };
149
+ //# sourceMappingURL=resolve-from-caller.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-from-caller.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/resolve-from-caller.mjs"],"names":[],"mappings":"AAyEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6CAhCa,KAAK,CAAC,QAAQ,CAAC,CA0C3B;AAqKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,2CAzCW,MAAM,GACJ,MAAM,CAsDlB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,0CA1CW,MAAM,GACJ,MAAM,CAuDlB;AA/UM,4BAvBI,GAAG,GACD,MAAM,GAAC,IAAI,CAsB+F;;iBAmVzG,MAAY,MAAM,GAAC,SAAS;mBAC5B,MAAY,MAAM,GAAC,SAAS;qBAC5B,MAAY,MAAM,GAAC,SAAS;iBAC5B,MAAY,MAAM,GAAC,SAAS;mBAC5B,MAAY,MAAM,GAAC,SAAS;8BAC5B,MAAY,MAAM,GAAC,SAAS;qBAC5B,MAAY,MAAM,GAAC,SAAS;cAC5B,MAAY,OAAO,GAAC,SAAS;YAC7B,MAAY,OAAO,GAAC,SAAS;mBAC7B,MAAY,OAAO,GAAC,SAAS;gBAC7B,MAAY,OAAO,GAAC,SAAS;aAC7B,MAAY,OAAO,GAAC,SAAS;kBAC7B,MAAY,OAAO,GAAC,SAAS;qBAC7B,MAAY,MAAM,GAAC,SAAS"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @function sanitizePathName
3
+ * @package
4
+ * @internal
5
+ * @param {string} input - The input string to sanitize (e.g., file name, path segment)
6
+ * @param {Object} [opts={}] - Sanitization configuration options
7
+ * @param {boolean} [opts.lowerFirst=true] - Lowercase the first character of the first segment for camelCase convention
8
+ * @param {Object} [opts.rules={}] - Advanced segment transformation rules (supports glob patterns: *, ?, **STRING**)
9
+ * @param {string[]} [opts.rules.leave=[]] - Segments to preserve exactly as-is (case-sensitive, supports globs)
10
+ * @param {string[]} [opts.rules.leaveInsensitive=[]] - Segments to preserve exactly as-is (case-insensitive, supports globs)
11
+ * @param {string[]} [opts.rules.upper=[]] - Segments to force to UPPERCASE (supports globs and **STRING** boundary patterns)
12
+ * @param {string[]} [opts.rules.lower=[]] - Segments to force to lowercase (supports globs and **STRING** boundary patterns)
13
+ * @returns {string} Valid JavaScript identifier safe for dot-notation property access
14
+ * @throws {TypeError} When input parameter is not a string
15
+ *
16
+ * @description
17
+ * Sanitize a string into a JS identifier suitable for dot-path usage.
18
+ * Advanced sanitization function that applies rules intelligently before splitting while
19
+ * maintaining proper camelCase transformation. Uses sophisticated tracking to ensure
20
+ * rule-matched segments are preserved correctly through the transformation process.
21
+ *
22
+ * @example
23
+ * // Basic sanitization (already valid identifiers unchanged)
24
+ * sanitizePathName("autoIP"); // "autoIP" (no change needed)
25
+ * sanitizePathName("validIdentifier"); // "validIdentifier" (no change needed)
26
+ * sanitizePathName("auto_ip"); // "auto_ip" (valid identifier preserved)
27
+ *
28
+ * @example
29
+ * // Standard camelCase conversion
30
+ * sanitizePathName("auto-ip"); // "autoIp" (dash becomes camelCase)
31
+ * sanitizePathName("my file!.mjs"); // "myFileMjs" (spaces and special chars removed)
32
+ * sanitizePathName("foo-bar-baz"); // "fooBarBaz" (multi-segment camelCase)
33
+ *
34
+ * @example
35
+ * // Pre-split pattern matching (matches original filename patterns)
36
+ * sanitizePathName("auto-ip", {
37
+ * rules: {
38
+ * upper: ["*-ip"] // Matches before splitting
39
+ * }
40
+ * }); // Result: "autoIP" (ip becomes IP due to *-ip pattern)
41
+ *
42
+ * @example
43
+ * // Complex pattern matching with intelligent tracking
44
+ * sanitizePathName("get-api-status", {
45
+ * rules: {
46
+ * upper: ["*-api-*"] // Matches api in middle of filename
47
+ * }
48
+ * }); // Result: "getAPIStatus" (api becomes API due to pattern)
49
+ *
50
+ * @example
51
+ * // Boundary-requiring patterns with **STRING** syntax
52
+ * sanitizePathName("buildUrlWithParams", {
53
+ * rules: {
54
+ * upper: ["**url**"] // Only matches "url" when surrounded by other characters
55
+ * }
56
+ * }); // Result: "buildURLWithParams" (url becomes URL, surrounded by other chars)
57
+ *
58
+ * sanitizePathName("url", {
59
+ * rules: {
60
+ * upper: ["**url**"] // Does NOT match standalone "url" (no surrounding chars)
61
+ * }
62
+ * }); // Result: "url" (unchanged - no surrounding characters)
63
+ *
64
+ * sanitizePathName("parseJsonData", {
65
+ * rules: {
66
+ * upper: ["**json**"] // Matches "json" surrounded by other characters
67
+ * }
68
+ * }); // Result: "parseJSONData" (json becomes JSON)
69
+ */
70
+ export function sanitizePathName(input: string, opts?: {
71
+ lowerFirst?: boolean;
72
+ rules?: {
73
+ leave?: string[];
74
+ leaveInsensitive?: string[];
75
+ upper?: string[];
76
+ lower?: string[];
77
+ };
78
+ }): string;
79
+ //# sourceMappingURL=sanitize.d.mts.map