@cldmv/slothlet 1.0.1 → 2.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 (40) hide show
  1. package/README.md +862 -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 +78 -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 +1092 -0
  14. package/index.cjs +81 -0
  15. package/index.mjs +76 -0
  16. package/package.json +136 -14
  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/dist/lib/engine/slothlet_esm.d.mts +19 -0
  22. package/types/dist/lib/engine/slothlet_esm.d.mts.map +1 -0
  23. package/types/dist/lib/engine/slothlet_helpers.d.mts +24 -0
  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 +138 -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 +110 -0
  38. package/types/dist/slothlet.d.mts.map +1 -0
  39. package/types/index.d.mts +23 -0
  40. package/slothlet.mjs +0 -1218
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,28 +1,123 @@
1
1
  {
2
2
  "name": "@cldmv/slothlet",
3
- "version": "1.0.1",
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",
6
- "exports": {
7
- ".": "./slothlet.mjs"
3
+ "version": "2.0.1",
4
+ "moduleVersions": {
5
+ "lazy": "1.0.0",
6
+ "eager": "1.0.0"
8
7
  },
9
- "directories": {
10
- "test": "tests"
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",
11
+ "exports": {
12
+ ".": {
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"
52
+ }
11
53
  },
54
+ "types": "./types/index.d.mts",
12
55
  "scripts": {
13
- "test": "vitest run",
14
- "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"
15
86
  },
16
87
  "keywords": [
17
88
  "api",
89
+ "api-loader",
90
+ "api-management",
91
+ "module-loader",
18
92
  "lazy-loading",
93
+ "eager-loading",
94
+ "copy-left-materialization",
95
+ "proxy",
96
+ "asynclocalstorage",
97
+ "live-binding",
98
+ "context-isolation",
99
+ "dual-loading",
19
100
  "modular",
101
+ "performance",
102
+ "optimization",
103
+ "startup-performance",
20
104
  "nodejs",
21
- "esm"
105
+ "esm",
106
+ "cjs",
107
+ "mixed-modules",
108
+ "dynamic-import",
109
+ "deferred-loading",
110
+ "framework",
111
+ "typescript",
112
+ "zero-dependencies"
22
113
  ],
114
+ "engines": {
115
+ "node": ">=16.4.0"
116
+ },
23
117
  "author": {
24
118
  "name": "Shinrai",
25
- "email": "git@cldmv.net",
119
+ "company": "CLDMV",
120
+ "email": "git+npm@cldmv.net",
26
121
  "url": "https://cldmv.net"
27
122
  },
28
123
  "contributors": [
@@ -32,9 +127,28 @@
32
127
  }
33
128
  ],
34
129
  "license": "Apache-2.0",
130
+ "funding": {
131
+ "type": "github",
132
+ "url": "https://github.com/sponsors/shinrai"
133
+ },
35
134
  "type": "module",
36
135
  "devDependencies": {
37
- "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",
38
152
  "vest": "^5.4.6",
39
153
  "vitest": "^3.2.4"
40
154
  },
@@ -49,8 +163,16 @@
49
163
  "publishConfig": {
50
164
  "access": "public"
51
165
  },
166
+ "prepack": "npm run build:ci",
52
167
  "files": [
168
+ "index.mjs",
169
+ "index.cjs",
53
170
  "README.md",
54
- "LICENSE"
55
- ]
171
+ "LICENSE",
172
+ "types/dist/",
173
+ "types/index.d.mts",
174
+ "types/index.d.mts.map",
175
+ "dist/"
176
+ ],
177
+ "sideEffects": false
56
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"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Minimal custom ESM loader for VM context fallback when SourceTextModule is unavailable.
3
+ * Parses import/export statements, loads dependencies recursively, and evaluates code in context.
4
+ * Limitations: Only supports static imports/exports, no top-level await, no dynamic import, no advanced ESM features.
5
+ * @param {object} context - The VM context.
6
+ * @param {string} fileUrl - The file URL to load.
7
+ * @param {Set<string>} [visited] - Tracks loaded modules to prevent cycles.
8
+ * @returns {Promise<object>} Module namespace object.
9
+ * @example
10
+ * const ns = await loadEsmModuleFallback(context, 'file:///path/to/mod.mjs');
11
+ */
12
+ export function loadEsmModuleFallback(context: object, fileUrl: string, visited?: Set<string>): Promise<object>;
13
+ /**
14
+ * Detects if a file is ESM based on extension or code content.
15
+ * @param {string} fileUrl
16
+ * @returns {Promise<boolean>}
17
+ */
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"}
@@ -0,0 +1,24 @@
1
+ export function normalizeContext(ctx: any): any;
2
+ export function installGlobalsInCurrentRealm(contextMap: any): void;
3
+ export function extendSelfWithReference(self: any, reference: any): void;
4
+ export function installPortalForSelf(): void;
5
+ export function asUrl(p: any): any;
6
+ export function isPlainObject(o: any): boolean;
7
+ export function guessName(v: any): any;
8
+ export function makeNodeishContext(): any;
9
+ /**
10
+ * Loads a module into a VM context, supporting ESM (mjs), CJS (cjs), or auto-detection.
11
+ * @param {object} context - The VM context.
12
+ * @param {string} fileUrl - The file URL to load.
13
+ * @param {string} [mode='auto'] - 'auto', 'mjs', or 'cjs'.
14
+ * @returns {Promise<object>} Module namespace or SourceTextModule.
15
+ */
16
+ export function loadEsmInVm2(context: object, fileUrl: string, mode?: string, ...args: any[]): Promise<object>;
17
+ export function loadEsmInVm(context: any, fileUrl: any): Promise<any>;
18
+ export function installContextGlobalsVM(context: any, userContext: any): void;
19
+ export function bootSlothletVM(context: any, entryUrl: any, loadConfig: any, ctxRef: any): Promise<void>;
20
+ export function marshalArgsReplaceFunctions(value: any, registerCb: any): any;
21
+ export function reviveArgsReplaceTokens(value: any, invokeCb: any): any;
22
+ export function containsFunction(value: any): boolean;
23
+ export const HAS_STM: boolean;
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"}