@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.
- package/README.md +862 -73
- package/dist/lib/engine/README.md +21 -0
- package/dist/lib/engine/slothlet_child.mjs +58 -0
- package/dist/lib/engine/slothlet_engine.mjs +371 -0
- package/dist/lib/engine/slothlet_esm.mjs +229 -0
- package/dist/lib/engine/slothlet_helpers.mjs +454 -0
- package/dist/lib/engine/slothlet_worker.mjs +148 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +141 -0
- package/dist/lib/helpers/sanitize.mjs +78 -0
- package/dist/lib/modes/slothlet_eager.mjs +80 -0
- package/dist/lib/modes/slothlet_lazy.mjs +342 -0
- package/dist/lib/runtime/runtime.mjs +249 -0
- package/dist/slothlet.mjs +1092 -0
- package/index.cjs +81 -0
- package/index.mjs +76 -0
- package/package.json +136 -14
- package/types/dist/lib/engine/slothlet_child.d.mts +2 -0
- package/types/dist/lib/engine/slothlet_child.d.mts.map +1 -0
- package/types/dist/lib/engine/slothlet_engine.d.mts +31 -0
- package/types/dist/lib/engine/slothlet_engine.d.mts.map +1 -0
- package/types/dist/lib/engine/slothlet_esm.d.mts +19 -0
- package/types/dist/lib/engine/slothlet_esm.d.mts.map +1 -0
- package/types/dist/lib/engine/slothlet_helpers.d.mts +24 -0
- package/types/dist/lib/engine/slothlet_helpers.d.mts.map +1 -0
- package/types/dist/lib/engine/slothlet_worker.d.mts +2 -0
- package/types/dist/lib/engine/slothlet_worker.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +149 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -0
- package/types/dist/lib/helpers/sanitize.d.mts +138 -0
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -0
- package/types/dist/lib/modes/slothlet_eager.d.mts +66 -0
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +1 -0
- package/types/dist/lib/modes/slothlet_lazy.d.mts +32 -0
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime.d.mts +49 -0
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -0
- package/types/dist/slothlet.d.mts +110 -0
- package/types/dist/slothlet.d.mts.map +1 -0
- package/types/index.d.mts +23 -0
- package/slothlet.mjs +0 -1218
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview String sanitization utilities for slothlet API property names. Internal file (not exported in package.json).
|
|
3
|
+
* @module @cldmv/slothlet.helpers.sanitize
|
|
4
|
+
* @memberof module:@cldmv/slothlet.helpers
|
|
5
|
+
* @internal
|
|
6
|
+
* @package
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Advanced string sanitization system for converting arbitrary file names into valid JavaScript
|
|
10
|
+
* property names suitable for slothlet's dot-notation API access. Implements sophisticated
|
|
11
|
+
* identifier validation, segment-based transformation rules, and configurable casing policies.
|
|
12
|
+
*
|
|
13
|
+
* Key features:
|
|
14
|
+
* - Valid identifier detection with fast-path optimization
|
|
15
|
+
* - Configurable first-segment casing (lowerFirst option)
|
|
16
|
+
* - Advanced rule-based transformation (leave, upper, lower arrays)
|
|
17
|
+
* - Cross-platform filename compatibility
|
|
18
|
+
* - Edge case handling for special characters and numeric prefixes
|
|
19
|
+
* - Camel-case conversion for multi-segment identifiers
|
|
20
|
+
*
|
|
21
|
+
* Technical implementation:
|
|
22
|
+
* - Uses regex-based validation for JavaScript identifier compliance
|
|
23
|
+
* - Segment splitting on non-identifier characters [^A-Za-z0-9_$]
|
|
24
|
+
* - Rule precedence: leave → upper → lower → default casing
|
|
25
|
+
* - Safety fallbacks for empty results and invalid identifier starts
|
|
26
|
+
* - Performance-optimized with early returns for valid identifiers
|
|
27
|
+
*
|
|
28
|
+
* Usage context:
|
|
29
|
+
* - File-to-API mapping in slothlet module loading
|
|
30
|
+
* - Dynamic property name generation for module namespaces
|
|
31
|
+
* - Sanitization of user-provided file names into safe property accessors
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // ESM (internal)
|
|
36
|
+
* import { sanitizePathName } from '@cldmv/slothlet/helpers/sanitize';
|
|
37
|
+
* // Internal example using package.json exports
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Relative import (internal)
|
|
41
|
+
* import { sanitizePathName } from './sanitize.mjs';
|
|
42
|
+
* const apiKey = sanitizePathName('auto-ip.mjs');
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* @function sanitizePathName
|
|
46
|
+
* @package
|
|
47
|
+
* @internal
|
|
48
|
+
* @param {string} input - The input string to sanitize (e.g., file name, path segment)
|
|
49
|
+
* @param {Object} [opts={}] - Sanitization configuration options
|
|
50
|
+
* @param {boolean} [opts.lowerFirst=true] - Lowercase the first character of the first segment for camelCase convention
|
|
51
|
+
* @param {Object} [opts.rules={}] - Advanced segment transformation rules
|
|
52
|
+
* @param {string[]} [opts.rules.leave=[]] - Segments to preserve exactly as-is (case-sensitive)
|
|
53
|
+
* @param {string[]} [opts.rules.upper=[]] - Segments to force to UPPERCASE
|
|
54
|
+
* @param {string[]} [opts.rules.lower=[]] - Segments to force to lowercase
|
|
55
|
+
* @returns {string} Valid JavaScript identifier safe for dot-notation property access
|
|
56
|
+
* @throws {TypeError} When input parameter is not a string
|
|
57
|
+
*
|
|
58
|
+
* @description
|
|
59
|
+
* Sanitize a string into a JS identifier suitable for dot-path usage.
|
|
60
|
+
* Core sanitization function that converts arbitrary strings (typically file names) into
|
|
61
|
+
* valid JavaScript identifiers following slothlet's API naming conventions.
|
|
62
|
+
*
|
|
63
|
+
* Sanitization algorithm:
|
|
64
|
+
* 1. **Fast path**: If input is already a valid JS identifier, return unchanged
|
|
65
|
+
* 2. **Segmentation**: Split on non-identifier characters [^A-Za-z0-9_$]
|
|
66
|
+
* 3. **Prefix cleanup**: Remove leading digits/invalid chars from first segment
|
|
67
|
+
* 4. **Rule application**: Apply leave/upper/lower rules with precedence
|
|
68
|
+
* 5. **Default casing**: First segment respects lowerFirst, others get title case
|
|
69
|
+
* 6. **Safety checks**: Ensure result starts with valid identifier character
|
|
70
|
+
*
|
|
71
|
+
* Rule precedence (applied in order):
|
|
72
|
+
* - `leave` rules: Preserve segment exactly as provided
|
|
73
|
+
* - `upper` rules: Force segment to UPPERCASE
|
|
74
|
+
* - `lower` rules: Force segment to lowercase
|
|
75
|
+
* - Default behavior: Apply standard camelCase conversion
|
|
76
|
+
*
|
|
77
|
+
* Edge case handling:
|
|
78
|
+
* - Empty input → "_" (safe fallback identifier)
|
|
79
|
+
* - Numeric prefixes → Stripped from first segment
|
|
80
|
+
* - All invalid chars → Returns "_" + cleaned content
|
|
81
|
+
* - No valid segments → Returns "_"
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* // Basic sanitization (already valid identifiers unchanged)
|
|
85
|
+
* sanitizePathName("autoIP"); // "autoIP" (no change needed)
|
|
86
|
+
* sanitizePathName("validIdentifier"); // "validIdentifier" (no change needed)
|
|
87
|
+
* sanitizePathName("auto_ip"); // "auto_ip" (valid identifier preserved)
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Standard camelCase conversion
|
|
91
|
+
* sanitizePathName("auto-ip"); // "autoIp" (dash becomes camelCase)
|
|
92
|
+
* sanitizePathName("my file!.mjs"); // "myFileMjs" (spaces and special chars removed)
|
|
93
|
+
* sanitizePathName("foo-bar-baz"); // "fooBarBaz" (multi-segment camelCase)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Numeric prefix handling
|
|
97
|
+
* sanitizePathName("2autoIP"); // "autoIP" (leading digits stripped)
|
|
98
|
+
* sanitizePathName("123-test-file"); // "testFile" (digits stripped, camelCase applied)
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* // First character casing control
|
|
102
|
+
* sanitizePathName("My-File"); // "myFile" (lowerFirst=true default)
|
|
103
|
+
* sanitizePathName("My-File", { lowerFirst: false }); // "MyFile" (preserve capital first)
|
|
104
|
+
* sanitizePathName("API-util", { lowerFirst: false }); // "APIUtil" (preserve capital first)
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Advanced rule-based transformation
|
|
108
|
+
* sanitizePathName("foo-api-json", {
|
|
109
|
+
* rules: {
|
|
110
|
+
* leave: ["foo"], // Keep "foo" exactly as-is
|
|
111
|
+
* upper: ["api"], // Force "api" to "API"
|
|
112
|
+
* lower: ["JSON"] // Force "JSON" to "json"
|
|
113
|
+
* }
|
|
114
|
+
* }); // Result: "fooAPIjson"
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Real-world slothlet file mapping scenarios
|
|
118
|
+
* sanitizePathName("auto-ip.mjs"); // "autoIp" (common filename pattern)
|
|
119
|
+
* sanitizePathName("parseJSON.mjs"); // "parseJSON" (preserve common acronym)
|
|
120
|
+
* sanitizePathName("get-HTTP-status.js"); // "getHTTPStatus" (multi-acronym handling)
|
|
121
|
+
* sanitizePathName("root-math.mjs"); // "rootMath" (typical slothlet module name)
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Edge cases and safety handling
|
|
125
|
+
* sanitizePathName(""); // "_" (empty string fallback)
|
|
126
|
+
* sanitizePathName("123"); // "_" (all numeric becomes fallback)
|
|
127
|
+
* sanitizePathName("!@#$%"); // "_" (all special chars becomes fallback)
|
|
128
|
+
* sanitizePathName("valid@#$invalid"); // "validInvalid" (special chars removed)
|
|
129
|
+
*/
|
|
130
|
+
export function sanitizePathName(input: string, opts?: {
|
|
131
|
+
lowerFirst?: boolean;
|
|
132
|
+
rules?: {
|
|
133
|
+
leave?: string[];
|
|
134
|
+
upper?: string[];
|
|
135
|
+
lower?: string[];
|
|
136
|
+
};
|
|
137
|
+
}): string;
|
|
138
|
+
//# sourceMappingURL=sanitize.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/sanitize.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AACH,wCAlFW,MAAM,SAEd;IAAuB,UAAU,GAAzB,OAAO;IACO,KAAK,GAC3B;QAA8B,KAAK,GAA3B,MAAM,EAAE;QACc,KAAK,GAA3B,MAAM,EAAE;QACc,KAAK,GAA3B,MAAM,EAAE;KAChB;CAAA,GAAU,MAAM,CAkIlB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function eager_wrapWithRunCtx
|
|
3
|
+
* @internal
|
|
4
|
+
* @package
|
|
5
|
+
* @alias module:@cldmv/slothlet.modes.eager.eager_wrapWithRunCtx
|
|
6
|
+
* @memberof module:@cldmv/slothlet.modes.eager
|
|
7
|
+
* @param {*} obj - The object/function to wrap
|
|
8
|
+
* @param {object} instance - The slothlet instance that will have boundapi.__ctx attached
|
|
9
|
+
* @returns {*} The wrapped object/function
|
|
10
|
+
*
|
|
11
|
+
* @description
|
|
12
|
+
* Recursively wraps all functions in an object with runWithCtx for eager mode.
|
|
13
|
+
* This makes eager mode use the same call stack optimization as lazy mode.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Wrapping a function
|
|
17
|
+
* const wrappedFn = eager_wrapWithRunCtx(originalFunction, instance);
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Wrapping an object with nested functions
|
|
21
|
+
* const wrappedObj = eager_wrapWithRunCtx({ method: fn }, instance);
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Wrapping a function
|
|
25
|
+
* const wrappedFn = eager_wrapWithRunCtx(originalFunction, instance);
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Wrapping an object with nested functions
|
|
29
|
+
* const wrappedObj = eager_wrapWithRunCtx({ method: fn }, instance);
|
|
30
|
+
* const wrappedFn = eager_wrapWithRunCtx(originalFunction, instance);
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Wrapping an object with nested functions
|
|
34
|
+
* const wrappedObj = eager_wrapWithRunCtx({ method: fn }, instance);
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* @function create
|
|
38
|
+
* @internal
|
|
39
|
+
* @package
|
|
40
|
+
* @async
|
|
41
|
+
* @alias module:@cldmv/slothlet.modes.eager.create
|
|
42
|
+
* @memberof module:@cldmv/slothlet.modes.eager
|
|
43
|
+
* @param {string} dir - Directory to load
|
|
44
|
+
* @param {boolean} [rootLevel=true] - Is this the root level?
|
|
45
|
+
* @param {number} [maxDepth=Infinity] - Maximum depth to traverse
|
|
46
|
+
* @param {number} [currentDepth=0] - Current traversal depth
|
|
47
|
+
* @returns {Promise<object>} Complete API object with all modules loaded
|
|
48
|
+
* @throws {Error} When module loading or directory traversal fails
|
|
49
|
+
*
|
|
50
|
+
* @description
|
|
51
|
+
* Creates the eager API for slothlet (mode: eager).
|
|
52
|
+
* Immediately loads all modules and constructs the complete API structure.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Internal usage - called by slothlet core
|
|
56
|
+
* const api = await create('./api_test', true, 3, 0);
|
|
57
|
+
* // Returns: { math: { add: [Function], multiply: [Function] }, ... }
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Root-level processing with function exports
|
|
61
|
+
* const api = await create('./api_test', true);
|
|
62
|
+
* // If root has default function: api becomes that function with properties
|
|
63
|
+
* // Otherwise: api is object with module properties
|
|
64
|
+
*/
|
|
65
|
+
export function create(dir: string, rootLevel?: boolean, maxDepth?: number, currentDepth?: number): Promise<object>;
|
|
66
|
+
//# sourceMappingURL=slothlet_eager.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slothlet_eager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_eager.mjs"],"names":[],"mappings":"AA8HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAsDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,4BAtBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAqE3B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function create
|
|
3
|
+
* @internal
|
|
4
|
+
* @package
|
|
5
|
+
* @async
|
|
6
|
+
* @alias module:@cldmv/slothlet.modes.lazy.create
|
|
7
|
+
* @memberof module:@cldmv/slothlet.modes.lazy
|
|
8
|
+
* @param {string} dir - Root directory
|
|
9
|
+
* @param {boolean} [rootLevel=true] - Root level flag
|
|
10
|
+
* @param {number} [maxDepth=Infinity] - Maximum depth to traverse
|
|
11
|
+
* @param {number} [currentDepth=0] - Current depth (for internal recursion only)
|
|
12
|
+
* @returns {Promise<function|object>} Root API object or function (if default export)
|
|
13
|
+
* @throws {Error} When module loading or directory traversal fails
|
|
14
|
+
*
|
|
15
|
+
* @description
|
|
16
|
+
* Creates a lazy API structure. Root-level files are loaded immediately (mirrors eager).
|
|
17
|
+
* Directories become lazy proxies. Nested directories remain lazy after materialization
|
|
18
|
+
* via _buildCategory recursion with subdirHandler.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Internal usage - called by slothlet core
|
|
22
|
+
* const api = await create('./api_test', true, 3, 0);
|
|
23
|
+
* // Returns: { math: [Function: lazyFolder_math], ... } (lazy proxies)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Root-level processing with function exports
|
|
27
|
+
* const api = await create('./api_test', true);
|
|
28
|
+
* // If root has default function: api becomes that function with properties
|
|
29
|
+
* // Otherwise: api is object with lazy proxy properties
|
|
30
|
+
*/
|
|
31
|
+
export function create(dir: string, rootLevel?: boolean, maxDepth?: number, currentDepth?: number): Promise<Function | object>;
|
|
32
|
+
//# sourceMappingURL=slothlet_lazy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slothlet_lazy.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_lazy.mjs"],"names":[],"mappings":"AAgJA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,4BAvBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,WAAS,MAAM,CAAC,CAwEpC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function runWithCtx(ctx: object, fn: Function, thisArg: any, args: any[]): any;
|
|
2
|
+
export function getCtx(): object | null;
|
|
3
|
+
export function makeWrapper(ctx: object): Function;
|
|
4
|
+
/**
|
|
5
|
+
* @constant self
|
|
6
|
+
* @memberof module:@cldmv/slothlet/runtime
|
|
7
|
+
* @export module:@cldmv/slothlet/runtime
|
|
8
|
+
* @public
|
|
9
|
+
* @type {function|object}
|
|
10
|
+
*
|
|
11
|
+
* @description
|
|
12
|
+
* Live binding to the current instance's 'self' reference from AsyncLocalStorage context.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Access current instance self
|
|
16
|
+
* console.log(self); // Current slothlet instance
|
|
17
|
+
*/
|
|
18
|
+
export const self: Function | object;
|
|
19
|
+
/**
|
|
20
|
+
* @constant context
|
|
21
|
+
* @memberof module:@cldmv/slothlet/runtime
|
|
22
|
+
* @export module:@cldmv/slothlet/runtime
|
|
23
|
+
* @public
|
|
24
|
+
* @type {object}
|
|
25
|
+
*
|
|
26
|
+
* @description
|
|
27
|
+
* Live binding to the current instance's 'context' data from AsyncLocalStorage context.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Access current context data
|
|
31
|
+
* console.log(context); // Current context object
|
|
32
|
+
*/
|
|
33
|
+
export const context: object;
|
|
34
|
+
/**
|
|
35
|
+
* @constant reference
|
|
36
|
+
* @memberof module:@cldmv/slothlet/runtime
|
|
37
|
+
* @export module:@cldmv/slothlet/runtime
|
|
38
|
+
* @public
|
|
39
|
+
* @type {object}
|
|
40
|
+
*
|
|
41
|
+
* @description
|
|
42
|
+
* Live binding to the current instance's 'reference' object from AsyncLocalStorage context.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Access current reference object
|
|
46
|
+
* console.log(reference); // Current reference data
|
|
47
|
+
*/
|
|
48
|
+
export const reference: object;
|
|
49
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime.mjs"],"names":[],"mappings":"AA0CO,gCAdI,MAAM,yBAEN,GAAG,gBAED,GAAG,CA6Bf;AAiBM,0BAZM,MAAM,GAAC,IAAI,CAY0B;AAsB3C,iCAjBI,MAAM,YAwDhB;AA4RD;;;;;;;;;;;;;GAaG;AACH,mBATU,WAAS,MAAM,CAS6B;AAEtD;;;;;;;;;;;;;GAaG;AACH,sBATU,MAAM,CAS4C;AAE5D;;;;;;;;;;;;;GAaG;AACH,wBATU,MAAM,CASgD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutates a live-binding variable (object or function) to match a new value, preserving reference.
|
|
3
|
+
* @param {function|object} target - The variable to mutate (object or function).
|
|
4
|
+
* @param {function|object} source - The new value to copy from (object or function).
|
|
5
|
+
* @private
|
|
6
|
+
* @internal
|
|
7
|
+
* @example
|
|
8
|
+
* mutateLiveBindingFunction(self, newSelf);
|
|
9
|
+
* mutateLiveBindingFunction(boundapi, newApi);
|
|
10
|
+
*/
|
|
11
|
+
export function mutateLiveBindingFunction(target: Function | object, source: Function | object): void;
|
|
12
|
+
/**
|
|
13
|
+
* The shared _slothlet parameter for live binding coordination.
|
|
14
|
+
* @type {string}
|
|
15
|
+
* @private
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export let _slothlet: string;
|
|
19
|
+
/**
|
|
20
|
+
* Live-binding reference to the current API instance.
|
|
21
|
+
* This is updated whenever a new API instance is created.
|
|
22
|
+
* Dynamically imported modules can access this at runtime.
|
|
23
|
+
* @type {object}
|
|
24
|
+
* @private
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const self: object;
|
|
28
|
+
/**
|
|
29
|
+
* Live-binding reference for contextual data.
|
|
30
|
+
* @type {object}
|
|
31
|
+
* @private
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export const context: object;
|
|
35
|
+
/**
|
|
36
|
+
* Live-binding reference for reference data.
|
|
37
|
+
* @type {object}
|
|
38
|
+
* @private
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export const reference: object;
|
|
42
|
+
export default slothlet;
|
|
43
|
+
export type SlothletOptions = {
|
|
44
|
+
/**
|
|
45
|
+
* - Directory to load API modules from.
|
|
46
|
+
* - Can be absolute or relative path.
|
|
47
|
+
* - If relative, resolved from the calling file's location.
|
|
48
|
+
* - Defaults to "api" directory relative to caller.
|
|
49
|
+
*/
|
|
50
|
+
dir?: string;
|
|
51
|
+
/**
|
|
52
|
+
* - Loading strategy:
|
|
53
|
+
* - `true`: Lazy loading - modules loaded on-demand when accessed (lower initial load, proxy overhead)
|
|
54
|
+
* - `false`: Eager loading - all modules loaded immediately (default, higher initial load, direct access)
|
|
55
|
+
*/
|
|
56
|
+
lazy?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* - Directory traversal depth control:
|
|
59
|
+
* - `Infinity`: Traverse all subdirectories recursively (default)
|
|
60
|
+
* - `0`: Only load files in root directory, no subdirectories
|
|
61
|
+
* - `1`, `2`, etc.: Limit traversal to specified depth levels
|
|
62
|
+
*/
|
|
63
|
+
apiDepth?: number;
|
|
64
|
+
/**
|
|
65
|
+
* - Debug output control:
|
|
66
|
+
* - `true`: Enable verbose logging for module loading, API construction, and binding operations
|
|
67
|
+
* - `false`: Silent operation (default)
|
|
68
|
+
* - Can be set via command line flag `--slothletdebug`, environment variable `SLOTHLET_DEBUG=true`, or options parameter
|
|
69
|
+
* - Command line and environment settings become the default for all instances unless overridden
|
|
70
|
+
*/
|
|
71
|
+
debug?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* - Execution environment mode:
|
|
74
|
+
* - `"singleton"`: Single shared instance within current process (default, fastest)
|
|
75
|
+
* - `"vm"`: Isolated VM context for security/isolation
|
|
76
|
+
* - `"worker"`: Web Worker or Worker Thread execution
|
|
77
|
+
* - `"fork"`: Child process execution for complete isolation
|
|
78
|
+
*/
|
|
79
|
+
mode?: string;
|
|
80
|
+
/**
|
|
81
|
+
* - API structure and calling convention:
|
|
82
|
+
* - `"auto"`: Auto-detect based on root module exports (function vs object) - recommended (default)
|
|
83
|
+
* - `"function"`: Force API to be callable as function with properties attached
|
|
84
|
+
* - `"object"`: Force API to be plain object with method properties
|
|
85
|
+
*/
|
|
86
|
+
api_mode?: string;
|
|
87
|
+
/**
|
|
88
|
+
* - Context data object injected into live-binding `context` reference.
|
|
89
|
+
* - Available to all loaded modules via `import { context } from '@cldmv/slothlet/runtime'`. Useful for request data,
|
|
90
|
+
* - user sessions, environment configs, etc.
|
|
91
|
+
*/
|
|
92
|
+
context?: object;
|
|
93
|
+
/**
|
|
94
|
+
* - Reference object merged into the API root level.
|
|
95
|
+
* - Properties not conflicting with loaded modules are added directly to the API.
|
|
96
|
+
* - Useful for utility functions, constants, or external service connections.
|
|
97
|
+
*/
|
|
98
|
+
reference?: object;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Creates a slothlet API instance with the specified configuration.
|
|
102
|
+
* This is the main entry point that can be called directly as a function.
|
|
103
|
+
* @async
|
|
104
|
+
* @alias module:@cldmv/slothlet
|
|
105
|
+
* @param {SlothletOptions} [options={}] - Configuration options for creating the API
|
|
106
|
+
* @returns {Promise<function|object>} The bound API object or function
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export function slothlet(options?: SlothletOptions): Promise<Function | object>;
|
|
110
|
+
//# sourceMappingURL=slothlet.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"AA44CA;;;;;;;;;GASG;AACH,kDARW,WAAS,MAAM,UACf,WAAS,MAAM,QAwCzB;AApzCD;;;;;GAKG;AACH,sBAJU,MAAM,CAIoE;AAKpF;;;;;;;GAOG;AACH,mBAJU,MAAM,CAIO;AAEvB;;;;;GAKG;AACH,sBAJU,MAAM,CAIU;AAE1B;;;;;GAKG;AACH,wBAJU,MAAM,CAIY;;;;;;;;;UA4xCd,MAAM;;;;;;WAIN,OAAO;;;;;;;eAGP,MAAM;;;;;;;;YAIN,OAAO;;;;;;;;WAKP,MAAM;;;;;;;eAKN,MAAM;;;;;;cAIN,MAAM;;;;;;gBAGN,MAAM;;AAtzCpB;;;;;;;;GAQG;AACH,mCAJW,eAAe,GACb,OAAO,CAAC,WAAS,MAAM,CAAC,CAiCpC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript declarations for @cldmv/slothlet index
|
|
3
|
+
*
|
|
4
|
+
* This file is auto-generated by tools/build-exports.mjs
|
|
5
|
+
* Run: npm run build:exports to regenerate
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Re-export all types from the main slothlet module
|
|
9
|
+
export type * from "./dist/slothlet.d.mts";
|
|
10
|
+
// If you want runtime exports, use the implementation file instead:
|
|
11
|
+
export * from "./dist/slothlet.mts";
|
|
12
|
+
|
|
13
|
+
// Auto-generated named export declarations (these override the re-export above)
|
|
14
|
+
export const _slothlet: any;
|
|
15
|
+
export const context: any;
|
|
16
|
+
export const mutateLiveBindingFunction: any;
|
|
17
|
+
export const reference: any;
|
|
18
|
+
export const self: any;
|
|
19
|
+
|
|
20
|
+
// Main slothlet export
|
|
21
|
+
declare const slothlet: any;
|
|
22
|
+
export default slothlet;
|
|
23
|
+
export { slothlet };
|