@cldmv/slothlet 3.15.2 → 3.16.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.
- package/README.md +8 -6
- package/dist/lib/builders/api-assignment.mjs +1 -1
- package/dist/lib/builders/api_builder.mjs +1 -1
- package/dist/lib/builders/builder.mjs +1 -1
- package/dist/lib/builders/modes-processor.mjs +1 -1
- package/dist/lib/handlers/api-cache-manager.mjs +1 -1
- package/dist/lib/handlers/api-manager.mjs +1 -1
- package/dist/lib/handlers/hook-manager.mjs +1 -1
- package/dist/lib/handlers/module-manager.mjs +1 -1
- package/dist/lib/handlers/ownership.mjs +1 -1
- package/dist/lib/handlers/routine-manager.mjs +17 -0
- package/dist/lib/handlers/unified-wrapper.mjs +1 -1
- package/dist/lib/helpers/config.mjs +1 -1
- package/dist/lib/helpers/defaults.mjs +17 -0
- package/dist/lib/helpers/eventtarget-property-context.mjs +17 -0
- package/dist/lib/helpers/observer-context.mjs +17 -0
- package/dist/lib/helpers/scheduler-context.mjs +1 -1
- package/dist/lib/i18n/languages/en-us.json +2 -0
- package/dist/lib/modes/eager.mjs +1 -1
- package/dist/lib/modes/lazy.mjs +1 -1
- package/dist/lib/processors/flatten.mjs +1 -1
- package/dist/lib/processors/loader.mjs +1 -1
- package/dist/slothlet.mjs +1 -1
- package/index.cjs +20 -0
- package/index.mjs +14 -0
- package/package.json +8 -7
- package/types/stub/devcheck.d.mts +1 -1
- package/types/stub/lib/builders/api-assignment.d.mts +130 -2
- package/types/stub/lib/builders/api_builder.d.mts +109 -2
- package/types/stub/lib/builders/builder.d.mts +87 -2
- package/types/stub/lib/builders/modes-processor.d.mts +71 -2
- package/types/stub/lib/factories/component-base.d.mts +177 -0
- package/types/stub/lib/helpers/caller-pinning.d.mts +22 -2
- package/types/stub/lib/helpers/class-instance-wrapper.d.mts +58 -2
- package/types/stub/lib/helpers/config.d.mts +321 -2
- package/types/stub/lib/helpers/defaults.d.mts +42 -0
- package/types/stub/lib/helpers/eventemitter-context.d.mts +31 -2
- package/types/stub/lib/helpers/eventtarget-context.d.mts +21 -2
- package/types/stub/lib/helpers/eventtarget-property-context.d.mts +23 -0
- package/types/stub/lib/helpers/generate-manifest.d.mts +180 -2
- package/types/stub/lib/helpers/hint-detector.d.mts +27 -2
- package/types/stub/lib/helpers/manifest-resolver.d.mts +101 -2
- package/types/stub/lib/helpers/modes-utils.d.mts +35 -2
- package/types/stub/lib/helpers/module-discovery.d.mts +81 -2
- package/types/stub/lib/helpers/module-manifest-validator.d.mts +37 -2
- package/types/stub/lib/helpers/module-sort.d.mts +65 -2
- package/types/stub/lib/helpers/observer-context.d.mts +23 -0
- package/types/stub/lib/helpers/pattern-matcher.d.mts +44 -2
- package/types/stub/lib/helpers/platform.d.mts +111 -2
- package/types/stub/lib/helpers/resolve-from-caller.d.mts +33 -2
- package/types/stub/lib/helpers/scheduler-context.d.mts +23 -2
- package/types/stub/lib/helpers/utilities.d.mts +57 -2
- package/types/stub/lib/i18n/translations.d.mts +52 -2
- package/types/stub/lib/modes/eager.d.mts +56 -2
- package/types/stub/lib/modes/lazy.d.mts +67 -2
- package/types/stub/lib/processors/flatten.d.mts +123 -2
- package/types/stub/lib/processors/loader.d.mts +83 -2
- package/types/stub/lib/processors/type-generator.d.mts +19 -2
- package/types/stub/lib/processors/typescript.d.mts +174 -2
- package/types/stub/lib/runtime/runtime-asynclocalstorage.d.mts +72 -2
- package/types/stub/lib/runtime/runtime-livebindings.d.mts +38 -2
|
@@ -1,3 +1,58 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* General utility functions
|
|
5
|
+
* @class Utilities
|
|
6
|
+
* @extends ComponentBase
|
|
7
|
+
* @package
|
|
8
|
+
*/
|
|
9
|
+
export class Utilities extends ComponentBase {
|
|
10
|
+
static slothletProperty: string;
|
|
11
|
+
/**
|
|
12
|
+
* Check if value is a plain object
|
|
13
|
+
* @param {*} obj - Value to check
|
|
14
|
+
* @returns {boolean} True if plain object
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
public isPlainObject(obj: any): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Deep merge two plain objects recursively.
|
|
20
|
+
*
|
|
21
|
+
* Differences from a simple spread:
|
|
22
|
+
* - Recursively merges nested plain objects rather than replacing them.
|
|
23
|
+
* - Uses `hasOwnProperty` to skip prototype-chain keys (no prototype pollution).
|
|
24
|
+
* - Non-plain values (arrays, class instances, primitives) are always copied by
|
|
25
|
+
* value from `source`, never merged.
|
|
26
|
+
* - When `source[key]` is a plain object but `target[key]` is not (or absent),
|
|
27
|
+
* the merge starts from `{}` so the returned sub-tree is always a fresh copy.
|
|
28
|
+
* - If either top-level argument is not a plain object, returns `source` as-is.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} target - Base object (not mutated).
|
|
31
|
+
* @param {unknown} source - Source object whose keys are merged in.
|
|
32
|
+
* @returns {unknown} New merged object, or `source` as-is if either argument is not a plain object.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
public deepMerge(target: unknown, source: unknown): unknown;
|
|
36
|
+
/**
|
|
37
|
+
* Deep clone a value, handling Proxy objects and functions that `structuredClone`
|
|
38
|
+
* cannot serialise.
|
|
39
|
+
*
|
|
40
|
+
* Strategy:
|
|
41
|
+
* 1. Try `structuredClone` — fast and spec-correct for plain data.
|
|
42
|
+
* 2. Fall back to a manual recursive copy for Proxies, callables, and other
|
|
43
|
+
* non-serialisable objects; errors on individual property clones are swallowed
|
|
44
|
+
* and the original reference is retained for that key.
|
|
45
|
+
*
|
|
46
|
+
* @param {unknown} obj - Value to clone.
|
|
47
|
+
* @returns {unknown} Deep clone of `obj`.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
public deepClone(obj: unknown): unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Generate unique ID
|
|
53
|
+
* @returns {string} Unique identifier
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
public generateId(): string;
|
|
57
|
+
}
|
|
58
|
+
import { ComponentBase } from "#factories/component-base";
|
|
@@ -1,3 +1,53 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Set current language (synchronous)
|
|
5
|
+
* Merges requested language translations over default English translations
|
|
6
|
+
* @param {string} lang - Language code
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export function setLanguage(lang: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Set the current language asynchronously — the browser-capable path.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Mirrors {@link setLanguage}, but awaits the locale load so it works in a browser, where locales
|
|
15
|
+
* arrive via dynamic `import(…, { with: { type: "json" } })` rather than the filesystem. In Node it
|
|
16
|
+
* awaits the same synchronous read (the await is a no-op). A failed load warns and keeps the bundled
|
|
17
|
+
* English default. Use this when you need to *await* a locale switch (e.g. in an Electron renderer).
|
|
18
|
+
* @param {string} lang - Language code (e.g. "es-mx").
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export function setLanguageAsync(lang: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get current language
|
|
25
|
+
* @returns {string} Language code
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export function getLanguage(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Translate error message with interpolation
|
|
31
|
+
* @param {string} errorCode - Error code
|
|
32
|
+
* @param {Object} params - Parameters for interpolation
|
|
33
|
+
* @returns {string} Translated message
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export function translate(errorCode: string, params?: Object): string;
|
|
37
|
+
/**
|
|
38
|
+
* Initialize i18n system (synchronous)
|
|
39
|
+
* @param {Object} options - Options
|
|
40
|
+
* @param {string} [options.language] - Language code (auto-detect if not provided)
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export function initI18n(options?: {
|
|
44
|
+
language?: string | undefined;
|
|
45
|
+
}): void;
|
|
46
|
+
/**
|
|
47
|
+
* Translate error message with interpolation
|
|
48
|
+
* @param {string} errorCode - Error code
|
|
49
|
+
* @param {Object} params - Parameters for interpolation
|
|
50
|
+
* @returns {string} Translated message
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export function t(errorCode: string, params?: Object): string;
|
|
@@ -1,3 +1,57 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Eager mode component - builds APIs by loading all modules immediately.
|
|
5
|
+
* @class EagerMode
|
|
6
|
+
* @extends ComponentBase
|
|
7
|
+
* @package
|
|
8
|
+
*/
|
|
9
|
+
export class EagerMode extends ComponentBase {
|
|
10
|
+
static slothletProperty: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create EagerMode instance.
|
|
13
|
+
* @param {object} slothlet - Slothlet orchestrator instance.
|
|
14
|
+
* @package
|
|
15
|
+
*/
|
|
16
|
+
constructor(slothlet: object);
|
|
17
|
+
/**
|
|
18
|
+
* Build API in eager mode (load all modules immediately).
|
|
19
|
+
* @param {Object} options - Build options
|
|
20
|
+
* @param {string} options.dir - Directory path to load from
|
|
21
|
+
* @param {string} [options.apiPathPrefix=""] - Prefix for API paths
|
|
22
|
+
* @param {string} [options.collisionContext="initial"] - Collision context
|
|
23
|
+
* @param {string|null} [options.collisionMode=null] - Per-call collision mode override (e.g. from `api.add()`'s `forceOverwrite`) — see `lazy.mjs`'s identical parameter
|
|
24
|
+
* @param {string} [options.moduleID] - Module ID
|
|
25
|
+
* @param {number} [options.apiDepth=DEFAULT_API_DEPTH] - Maximum directory depth ({@link DEFAULT_API_DEPTH})
|
|
26
|
+
* @param {string|null} [options.cacheBust=null] - Cache-busting value
|
|
27
|
+
* @param {Function|null} [options.fileFilter=null] - Optional filter (fileName) => boolean
|
|
28
|
+
* @param {string|string[]|null} [options.hidden=null] - Glob(s) hiding files/folders, matched against each entry's path relative to the API root
|
|
29
|
+
* @param {boolean} [options.scanHiddenFolders=false] - Deprecated: restore the pre-v3.11 scanning of `.`/`__`-prefixed folders
|
|
30
|
+
* @param {Object|null} [options.preloadedStructure=null] - Pre-built `{ files, directories }` structure
|
|
31
|
+
* to use instead of scanning `dir` (synthetic / in-memory build, #117). Each synthetic file entry
|
|
32
|
+
* carries its exports directly so no module is loaded from disk.
|
|
33
|
+
* @param {boolean} [options.rootUnwrap=false] - The mount exposes the single root entry's exports
|
|
34
|
+
* directly at the mount path (a single-file or synthetic `api.add()`), so that entry creates no api
|
|
35
|
+
* level and must contribute no path segment either.
|
|
36
|
+
* @returns {Promise<Object>} Built API object
|
|
37
|
+
* @public
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const api = await slothlet.modes.eager.buildAPI({ dir: "./api", moduleID: "base" });
|
|
41
|
+
*/
|
|
42
|
+
public buildAPI({ dir, apiPathPrefix, collisionContext, collisionMode, moduleID, apiDepth, cacheBust, fileFilter, hidden, scanHiddenFolders, preloadedStructure, rootUnwrap }: {
|
|
43
|
+
dir: string;
|
|
44
|
+
apiPathPrefix?: string | undefined;
|
|
45
|
+
collisionContext?: string | undefined;
|
|
46
|
+
collisionMode?: string | null | undefined;
|
|
47
|
+
moduleID?: string | undefined;
|
|
48
|
+
apiDepth?: number | undefined;
|
|
49
|
+
cacheBust?: string | null | undefined;
|
|
50
|
+
fileFilter?: Function | null | undefined;
|
|
51
|
+
hidden?: string | string[] | null | undefined;
|
|
52
|
+
scanHiddenFolders?: boolean | undefined;
|
|
53
|
+
preloadedStructure?: Object | null | undefined;
|
|
54
|
+
rootUnwrap?: boolean | undefined;
|
|
55
|
+
}): Promise<Object>;
|
|
56
|
+
}
|
|
57
|
+
import { ComponentBase } from "#factories/component-base";
|
|
@@ -1,3 +1,68 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Lazy mode component - builds APIs with deferred (on-demand) loading.
|
|
5
|
+
* @class LazyMode
|
|
6
|
+
* @extends ComponentBase
|
|
7
|
+
* @package
|
|
8
|
+
*/
|
|
9
|
+
export class LazyMode extends ComponentBase {
|
|
10
|
+
static slothletProperty: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create LazyMode instance.
|
|
13
|
+
* @param {object} slothlet - Slothlet orchestrator instance.
|
|
14
|
+
* @package
|
|
15
|
+
*/
|
|
16
|
+
constructor(slothlet: object);
|
|
17
|
+
/**
|
|
18
|
+
* Create a named async materialization function for lazy subdirectories.
|
|
19
|
+
* @param {string} apiPath - API path to derive the function name from.
|
|
20
|
+
* @param {Function} handler - Async handler that performs materialization.
|
|
21
|
+
* @returns {Function} Named async materialization function.
|
|
22
|
+
* @public
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const fn = lazyMode.createNamedMaterializeFunc('api.math', async () => ({ add: (a,b) => a+b }));
|
|
26
|
+
*/
|
|
27
|
+
public createNamedMaterializeFunc(apiPath: string, handler: Function): Function;
|
|
28
|
+
/**
|
|
29
|
+
* Build API in lazy mode (proxy-based deferred loading).
|
|
30
|
+
* @param {Object} options - Build options
|
|
31
|
+
* @param {string} options.dir - Directory to build from
|
|
32
|
+
* @param {string} [options.apiPathPrefix=""] - Prefix for API paths
|
|
33
|
+
* @param {string} [options.collisionContext="initial"] - Collision context
|
|
34
|
+
* @param {string|null} [options.collisionMode=null] - Collision mode override from api.add()
|
|
35
|
+
* @param {string} [options.moduleID] - Module ID
|
|
36
|
+
* @param {number} [options.apiDepth=DEFAULT_API_DEPTH] - Maximum directory depth ({@link DEFAULT_API_DEPTH})
|
|
37
|
+
* @param {string|null} [options.cacheBust=null] - Cache-busting value
|
|
38
|
+
* @param {Function|null} [options.fileFilter=null] - Optional filter (fileName) => boolean
|
|
39
|
+
* @param {string|string[]|null} [options.hidden=null] - Glob(s) hiding files/folders, matched against each entry's path relative to the API root
|
|
40
|
+
* @param {boolean} [options.scanHiddenFolders=false] - Deprecated: restore the pre-v3.11 scanning of `.`/`__`-prefixed folders
|
|
41
|
+
* @param {Object|null} [options.preloadedStructure=null] - Pre-built `{ files, directories }` structure
|
|
42
|
+
* to use instead of scanning `dir` (synthetic / in-memory build, #117). Each synthetic file entry
|
|
43
|
+
* carries its exports directly so no module is loaded from disk.
|
|
44
|
+
* @param {boolean} [options.rootUnwrap=false] - The mount exposes the single root entry's exports
|
|
45
|
+
* directly at the mount path (a single-file or synthetic `api.add()`), so that entry creates no api
|
|
46
|
+
* level and must contribute no path segment either.
|
|
47
|
+
* @returns {Promise<Object>} Built API object with lazy proxies
|
|
48
|
+
* @public
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const api = await slothlet.modes.lazy.buildAPI({ dir: "./api", moduleID: "base" });
|
|
52
|
+
*/
|
|
53
|
+
public buildAPI({ dir, apiPathPrefix, collisionContext, collisionMode, moduleID, apiDepth, cacheBust, fileFilter, hidden, scanHiddenFolders, preloadedStructure, rootUnwrap }: {
|
|
54
|
+
dir: string;
|
|
55
|
+
apiPathPrefix?: string | undefined;
|
|
56
|
+
collisionContext?: string | undefined;
|
|
57
|
+
collisionMode?: string | null | undefined;
|
|
58
|
+
moduleID?: string | undefined;
|
|
59
|
+
apiDepth?: number | undefined;
|
|
60
|
+
cacheBust?: string | null | undefined;
|
|
61
|
+
fileFilter?: Function | null | undefined;
|
|
62
|
+
hidden?: string | string[] | null | undefined;
|
|
63
|
+
scanHiddenFolders?: boolean | undefined;
|
|
64
|
+
preloadedStructure?: Object | null | undefined;
|
|
65
|
+
rootUnwrap?: boolean | undefined;
|
|
66
|
+
}): Promise<Object>;
|
|
67
|
+
}
|
|
68
|
+
import { ComponentBase } from "#factories/component-base";
|
|
@@ -1,3 +1,124 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Flattening decision processor
|
|
5
|
+
* @class Flatten
|
|
6
|
+
* @extends ComponentBase
|
|
7
|
+
* @package
|
|
8
|
+
*/
|
|
9
|
+
export class Flatten extends ComponentBase {
|
|
10
|
+
static slothletProperty: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a Flatten instance
|
|
13
|
+
* @param {Object} slothlet - Slothlet instance
|
|
14
|
+
*/
|
|
15
|
+
constructor(slothlet: Object);
|
|
16
|
+
/**
|
|
17
|
+
* Core flattening decision function.
|
|
18
|
+
* Implements conditions C01-C07 from getFlatteningDecision().
|
|
19
|
+
* @param {object} options - Decision options
|
|
20
|
+
* @param {object} options.mod - Module exports
|
|
21
|
+
* @param {string} options.moduleName - Sanitized module name
|
|
22
|
+
* @param {string} options.categoryName - Category/folder name
|
|
23
|
+
* @param {object} options.analysis - Export analysis
|
|
24
|
+
* @param {boolean} options.hasMultipleDefaults - Multiple defaults in folder
|
|
25
|
+
* @param {string[]} options.moduleKeys - Keys from module
|
|
26
|
+
* @param {function} options.t - Translation function
|
|
27
|
+
* @returns {Promise<object>} Flattening decision
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
public getFlatteningDecision(options: {
|
|
31
|
+
mod: object;
|
|
32
|
+
moduleName: string;
|
|
33
|
+
categoryName: string;
|
|
34
|
+
analysis: object;
|
|
35
|
+
hasMultipleDefaults: boolean;
|
|
36
|
+
moduleKeys: string[];
|
|
37
|
+
t: Function;
|
|
38
|
+
}): Promise<object>;
|
|
39
|
+
/**
|
|
40
|
+
* Build module content for API assignment.
|
|
41
|
+
*
|
|
42
|
+
* Canonical implementation of the C08-C09b content-building rules, including
|
|
43
|
+
* AddApi detection and collision handling. Previously this logic was inlined
|
|
44
|
+
* inside modes-processor.mjs; it now lives here so the processor stays focused
|
|
45
|
+
* on wrapping and assignment concerns only.
|
|
46
|
+
*
|
|
47
|
+
* Collision config, modesUtils helpers, and SlothletWarning are accessed
|
|
48
|
+
* directly through {@link this.slothlet} / {@link this.slothlet.config} — no caller
|
|
49
|
+
* plumbing required.
|
|
50
|
+
*
|
|
51
|
+
* @param {object} options - Processing options.
|
|
52
|
+
* @param {object} options.mod - Module exports.
|
|
53
|
+
* @param {object} options.decision - Flattening decision from getFlatteningDecision.
|
|
54
|
+
* @param {string} options.moduleName - Sanitized module name (used for C08 auto-flatten key lookup).
|
|
55
|
+
* @param {string} options.propertyName - Resolved preferred name (decision.preferredName || moduleName).
|
|
56
|
+
* @param {string[]} options.moduleKeys - Named export keys (excluding "default").
|
|
57
|
+
* @param {object} options.analysis - { hasDefault, hasNamed, defaultExportType }.
|
|
58
|
+
* @param {object} [options.file=null] - File descriptor for AddApi detection via file.name / file.fullName.
|
|
59
|
+
* @param {string} [options.collisionContext="initial"] - Collision context ("initial" | "api").
|
|
60
|
+
* @param {string} [options.apiPathPrefix=""] - API path prefix for collision error messages.
|
|
61
|
+
* @param {string|null} [options.collisionModeOverride=null] - Caller's per-call override (e.g.
|
|
62
|
+
* `api.add({ forceOverwrite: true })`), preferred over `collisionContext`'s config default for
|
|
63
|
+
* the function-default-vs-named-export merge decision below.
|
|
64
|
+
* @returns {{ moduleContent: object|Function }} Built module content ready for wrapping/assignment.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
public processModuleForAPI(options: {
|
|
68
|
+
mod: object;
|
|
69
|
+
decision: object;
|
|
70
|
+
moduleName: string;
|
|
71
|
+
propertyName: string;
|
|
72
|
+
moduleKeys: string[];
|
|
73
|
+
analysis: object;
|
|
74
|
+
file?: object | undefined;
|
|
75
|
+
collisionContext?: string | undefined;
|
|
76
|
+
apiPathPrefix?: string | undefined;
|
|
77
|
+
collisionModeOverride?: string | null | undefined;
|
|
78
|
+
}): {
|
|
79
|
+
moduleContent: object | Function;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Build category-level flattening decisions.
|
|
83
|
+
* Implements conditions C10-C33 from buildCategoryDecisions().
|
|
84
|
+
* @param {object} options - Category options
|
|
85
|
+
* @param {string} options.categoryName - Category name
|
|
86
|
+
* @param {object} options.mod - Module exports
|
|
87
|
+
* @param {string} options.moduleName - Module name
|
|
88
|
+
* @param {string} options.fileBaseName - File base name
|
|
89
|
+
* @param {object} options.analysis - Export analysis
|
|
90
|
+
* @param {string[]} options.moduleKeys - Module keys
|
|
91
|
+
* @param {number} options.currentDepth - Current depth
|
|
92
|
+
* @param {unknown[]} options.moduleFiles - Files in category
|
|
93
|
+
* @param {function} options.t - Translation function
|
|
94
|
+
* @returns {Promise<object>} Category decision
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
public buildCategoryDecisions(options: {
|
|
98
|
+
categoryName: string;
|
|
99
|
+
mod: object;
|
|
100
|
+
moduleName: string;
|
|
101
|
+
fileBaseName: string;
|
|
102
|
+
analysis: object;
|
|
103
|
+
moduleKeys: string[];
|
|
104
|
+
currentDepth: number;
|
|
105
|
+
moduleFiles: unknown[];
|
|
106
|
+
t: Function;
|
|
107
|
+
}): Promise<object>;
|
|
108
|
+
/**
|
|
109
|
+
* Decide whether a named export should be attached to a callable default export.
|
|
110
|
+
*
|
|
111
|
+
* Returns false when the named export is the same reference as the default (re-export
|
|
112
|
+
* pattern), or when the export key matches the function name (self-referential export).
|
|
113
|
+
*
|
|
114
|
+
* @param {string} key - Named export key.
|
|
115
|
+
* @param {unknown} value - Named export value.
|
|
116
|
+
* @param {Function} defaultFunc - Wrapped callable default export.
|
|
117
|
+
* @param {Function} originalDefault - Original default export.
|
|
118
|
+
* @returns {boolean} True if the export should be attached.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
public shouldAttachNamedExport(key: string, value: unknown, defaultFunc: Function, originalDefault: Function): boolean;
|
|
122
|
+
#private;
|
|
123
|
+
}
|
|
124
|
+
import { ComponentBase } from "#factories/component-base";
|
|
@@ -1,3 +1,84 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Warns when a coverage run will silently misattribute the consumer's leaf coverage (#235).
|
|
5
|
+
*
|
|
6
|
+
* @param {object} config - The instance's transformed config.
|
|
7
|
+
* @param {object} [overrides] - Environment inputs, injectable for tests.
|
|
8
|
+
* @param {object|undefined} [overrides.worker] - The vitest worker global, when present.
|
|
9
|
+
* @param {boolean} [overrides.externalized] - Whether this slothlet copy is outside the runner's
|
|
10
|
+
* module graph.
|
|
11
|
+
* @returns {boolean} True when the warning was emitted.
|
|
12
|
+
* @package
|
|
13
|
+
*
|
|
14
|
+
* @description
|
|
15
|
+
* Fires only when every condition of the misattribution scenario holds: a vitest COVERAGE run is
|
|
16
|
+
* active (`__vitest_worker__.config.coverage.enabled` — a plain test run stays silent), this
|
|
17
|
+
* slothlet copy is EXTERNALIZED (an inlined copy attributes fine), no `import` importer is
|
|
18
|
+
* configured (the fix), and the instance is not `silent`. The worker global is vitest-internal,
|
|
19
|
+
* so it is read defensively — its absence or a shape change simply means no hint, never a wrong
|
|
20
|
+
* one. Detection cannot DO the fix: the importer must be a closure authored in the consumer's own
|
|
21
|
+
* transformed code, which is why this is a pointer to docs/TESTING.md rather than an auto-enable.
|
|
22
|
+
*/
|
|
23
|
+
export function warnIfCoverageWithoutImporter(config: object, { worker, externalized }?: {
|
|
24
|
+
worker?: object | undefined;
|
|
25
|
+
externalized?: boolean | undefined;
|
|
26
|
+
}): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Loader component for module loading, directory scanning, and API merging
|
|
29
|
+
* @class Loader
|
|
30
|
+
* @extends ComponentBase
|
|
31
|
+
* @package
|
|
32
|
+
*/
|
|
33
|
+
export class Loader extends ComponentBase {
|
|
34
|
+
static slothletProperty: string;
|
|
35
|
+
/**
|
|
36
|
+
* Create a Loader instance.
|
|
37
|
+
* @param {object} slothlet - Slothlet class instance.
|
|
38
|
+
* @package
|
|
39
|
+
*/
|
|
40
|
+
constructor(slothlet: object);
|
|
41
|
+
/**
|
|
42
|
+
* Load a single module
|
|
43
|
+
* @param {string} filePath - Path to module file
|
|
44
|
+
* @param {string} [instanceID] - Slothlet instance ID for cache busting
|
|
45
|
+
* @param {string} [moduleID] - Module ID for additional cache busting (used in api.slothlet.api.add)
|
|
46
|
+
* @param {number|null} [cacheBust=null] - Timestamp for reload cache busting (forces fresh import)
|
|
47
|
+
* @returns {Promise<Object>} Loaded module
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
public loadModule(filePath: string, instanceID?: string, moduleID?: string, cacheBust?: number | null): Promise<Object>;
|
|
51
|
+
/**
|
|
52
|
+
* Scan directory for module files
|
|
53
|
+
* @param {string} dir - Directory to scan
|
|
54
|
+
* @param {Object} [options={}] - Scan options
|
|
55
|
+
* @param {boolean} [options.isRootScan=true] - Whether this is the root directory scan (shows empty dir warning)
|
|
56
|
+
* @param {number} [options.currentDepth=0] - Current traversal depth
|
|
57
|
+
* @param {number} [options.maxDepth=DEFAULT_API_DEPTH] - Maximum traversal depth ({@link DEFAULT_API_DEPTH})
|
|
58
|
+
* @param {Function|null} [options.fileFilter=null] - Optional filter function (fileName) => boolean to load specific files only
|
|
59
|
+
* @param {string|string[]|Function|null} [options.hidden=null] - Glob(s) hiding files/folders, matched against each entry's
|
|
60
|
+
* path relative to the API root (extension-stripped for files). Internal recursion passes the compiled matcher function.
|
|
61
|
+
* @param {boolean} [options.scanHiddenFolders=false] - Deprecated: restore the pre-v3.11 scanning of `.`/`__`-prefixed folders.
|
|
62
|
+
* @param {string} [options.rootDir] - API root the relative hidden-glob paths are computed from (defaults to the scanned dir).
|
|
63
|
+
* @returns {Promise<Object>} Directory structure
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
public scanDirectory(dir: string, options?: {
|
|
67
|
+
isRootScan?: boolean | undefined;
|
|
68
|
+
currentDepth?: number | undefined;
|
|
69
|
+
maxDepth?: number | undefined;
|
|
70
|
+
fileFilter?: Function | null | undefined;
|
|
71
|
+
hidden?: string | Function | string[] | null | undefined;
|
|
72
|
+
scanHiddenFolders?: boolean | undefined;
|
|
73
|
+
rootDir?: string | undefined;
|
|
74
|
+
}): Promise<Object>;
|
|
75
|
+
/**
|
|
76
|
+
* Extract exports from module
|
|
77
|
+
* @param {Object} module - Loaded module
|
|
78
|
+
* @returns {Object} Extracted exports
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
public extractExports(module: Object): Object;
|
|
82
|
+
#private;
|
|
83
|
+
}
|
|
84
|
+
import { ComponentBase } from "#factories/component-base";
|
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Generate TypeScript declaration file for a Slothlet API
|
|
5
|
+
* @param {object} api - The loaded Slothlet API
|
|
6
|
+
* @param {object} options - Generation options
|
|
7
|
+
* @param {string} options.output - Output file path for .d.ts
|
|
8
|
+
* @param {string} options.interfaceName - Name of the interface to generate
|
|
9
|
+
* @param {boolean} [options.includeDocumentation=true] - Include JSDoc comments
|
|
10
|
+
* @returns {Promise<{output: string, filePath: string}>} Generated declaration and output path
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function generateTypes(api: object, options: {
|
|
14
|
+
output: string;
|
|
15
|
+
interfaceName: string;
|
|
16
|
+
includeDocumentation?: boolean | undefined;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
output: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
}>;
|
|
@@ -1,3 +1,175 @@
|
|
|
1
1
|
// AUTO-GENERATED by tools/build/build-typestubs.mjs — do not edit.
|
|
2
|
-
//
|
|
3
|
-
|
|
2
|
+
// Self-contained copy: this subpath is internal and not published by @cldmv/slothlet-types.
|
|
3
|
+
/**
|
|
4
|
+
* Transform TypeScript code to JavaScript using esbuild
|
|
5
|
+
* @param {string} filePath - Path to the TypeScript file
|
|
6
|
+
* @param {object} [options={}] - esbuild transform options
|
|
7
|
+
* @param {string} [options.target] - ECMAScript target version (default: "es2020")
|
|
8
|
+
* @param {string} [options.format] - Module format (default: "esm")
|
|
9
|
+
* @param {boolean} [options.sourcemap] - Generate source maps (default: false)
|
|
10
|
+
* @returns {Promise<string>} Transformed JavaScript code
|
|
11
|
+
* @throws {SlothletError} If transformation fails
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function transformTypeScript(filePath: string, options?: {
|
|
15
|
+
target?: string | undefined;
|
|
16
|
+
format?: string | undefined;
|
|
17
|
+
sourcemap?: boolean | undefined;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a data URL for dynamic import with cache busting
|
|
21
|
+
* @param {string} code - JavaScript code to encode
|
|
22
|
+
* @returns {string} Data URL suitable for dynamic import
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export function createDataUrl(code: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the on-disk file a relative specifier targets and classify it as a
|
|
28
|
+
* TypeScript source or not.
|
|
29
|
+
*
|
|
30
|
+
* Besides the literal path, this probes the TypeScript source-extension
|
|
31
|
+
* convention: a specifier may name a `.mjs` / `.js` file (or omit the
|
|
32
|
+
* extension) while the file on disk is the corresponding `.mts` / `.ts`
|
|
33
|
+
* source. Whichever form exists wins.
|
|
34
|
+
* @param {string} absoluteTarget - Absolute path the specifier resolves to, as written
|
|
35
|
+
* @returns {{ path: string, isTS: boolean }} The resolved file and whether it is a `.ts`/`.mts` source
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
export function resolveModuleFile(absoluteTarget: string): {
|
|
39
|
+
path: string;
|
|
40
|
+
isTS: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Mark every character index that falls inside a string literal, template
|
|
44
|
+
* literal, comment, or regular-expression literal, so the specifier rewrite can
|
|
45
|
+
* skip `import`/`from` text that is not actually part of an import statement
|
|
46
|
+
* (e.g. `const s = "import('./x')"`).
|
|
47
|
+
*
|
|
48
|
+
* Template literals are masked whole — opening backtick to closing backtick,
|
|
49
|
+
* including any `${…}` interpolations — so a relative dynamic `import()` inside
|
|
50
|
+
* a template interpolation is left un-rewritten rather than risk a false
|
|
51
|
+
* rewrite; nested template literals are not deeply parsed.
|
|
52
|
+
*
|
|
53
|
+
* Regex literals are masked whole as well: their bodies can contain text shaped
|
|
54
|
+
* like a line- or block-comment delimiter (`/\/\//`), and without regex
|
|
55
|
+
* awareness the scanner would mis-read that as a comment and mask the rest of
|
|
56
|
+
* the line — silently suppressing a real `import()` later on the same line. A
|
|
57
|
+
* `/` is read as a regex when the previous significant token expects an
|
|
58
|
+
* expression (start of input, an operator, `(`/`{`/`}`/`,`/`;`/`:`, or a
|
|
59
|
+
* {@link REGEX_PRECEDING_KEYWORDS} keyword) and as division otherwise. The one
|
|
60
|
+
* imperfect case is a `/` directly after the `)` of an `if`/`for`/`while`
|
|
61
|
+
* header — treated as division — an accepted limit of this lightweight scan.
|
|
62
|
+
* @param {string} code - JavaScript source to scan
|
|
63
|
+
* @returns {Uint8Array} `1` at indices inside a string/template/comment/regex, `0` elsewhere
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
export function maskStringsAndComments(code: string): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Rewrite relative `import`/`export` specifiers in transformed TS output.
|
|
69
|
+
*
|
|
70
|
+
* Transformed TS modules are written to (and imported from) a cache file under
|
|
71
|
+
* `.slothlet-cache/…`, which is not co-located with the original source.
|
|
72
|
+
* esbuild and tsc transform the code but never rewrite specifiers, so a
|
|
73
|
+
* relative specifier (`./sibling.mjs`, `../shared/util.mjs`) left as-is would
|
|
74
|
+
* resolve against the cache directory and fail with `Cannot find module`.
|
|
75
|
+
*
|
|
76
|
+
* Each relative specifier is resolved against the original source directory
|
|
77
|
+
* and handed to `resolve`, which returns its replacement. The default `resolve`
|
|
78
|
+
* emits an absolute `file://` URL at the source location — correct for plain
|
|
79
|
+
* `.mjs`/`.cjs`/`.js` targets. {@link writeTransformedToCache} passes a `resolve`
|
|
80
|
+
* that additionally points relative `.ts`/`.mts` targets at their transpiled
|
|
81
|
+
* cache files. Bare specifiers (`@cldmv/slothlet/runtime`, npm packages) and
|
|
82
|
+
* absolute URLs are never touched.
|
|
83
|
+
*
|
|
84
|
+
* Matches inside a string literal or comment are skipped via
|
|
85
|
+
* {@link maskStringsAndComments}, so import-shaped text in string data or
|
|
86
|
+
* comments is never mutated.
|
|
87
|
+
*
|
|
88
|
+
* Covered statement forms: static `import`/`export … from` declarations
|
|
89
|
+
* (including multi-line binding lists and `export *`), bare side-effect
|
|
90
|
+
* `import "…"`, and dynamic `import("…")` with a static string literal.
|
|
91
|
+
* Whitespace and comments between the tokens of these forms — including
|
|
92
|
+
* between `from`/`import` and the module string — are tolerated.
|
|
93
|
+
* @param {string} code - Transformed JavaScript (ESM) code
|
|
94
|
+
* @param {string} sourcePath - Absolute path to the original .ts/.mts source
|
|
95
|
+
* @param {(absoluteTarget: string, suffix: string, specifier: string) => string} [resolve]
|
|
96
|
+
* - Maps a relative specifier to its replacement. Receives the absolute path the
|
|
97
|
+
* specifier resolves to, any `?query`/`#hash` suffix, and the original specifier
|
|
98
|
+
* text. Defaults to an absolute `file://` URL anchored at the source directory.
|
|
99
|
+
* @returns {string} Code with relative specifiers rewritten
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
export function rewriteRelativeSpecifiers(code: string, sourcePath: string, resolve?: (absoluteTarget: string, suffix: string, specifier: string) => string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Write transformed TS output — and the transitive graph of `.ts`/`.mts` files
|
|
105
|
+
* it relatively imports — to content-hashed cache files inside the project,
|
|
106
|
+
* returning the entry module's `file://` URL.
|
|
107
|
+
*
|
|
108
|
+
* The cache file is not co-located with the source, so every relative specifier
|
|
109
|
+
* is rewritten by {@link rewriteRelativeSpecifiers}:
|
|
110
|
+
*
|
|
111
|
+
* - **Bare specifiers** (`@cldmv/slothlet/runtime`, npm packages) resolve
|
|
112
|
+
* normally — the cache lives inside the project tree, so Node walks up to
|
|
113
|
+
* `node_modules` as usual. They are left untouched.
|
|
114
|
+
* - **Relative imports of plain `.mjs`/`.cjs`/`.js` files** are rewritten to an
|
|
115
|
+
* absolute `file://` URL at the original source location.
|
|
116
|
+
* - **Relative imports of other `.ts`/`.mts` files** are followed: when a
|
|
117
|
+
* `transform` callback is supplied, each dependency is transpiled and cached
|
|
118
|
+
* too, and the importing specifier is rewritten to the dependency's cache
|
|
119
|
+
* file. Import cycles are handled. Without `transform`, a relative `.ts`/`.mts`
|
|
120
|
+
* target is left at its source path (and will not load).
|
|
121
|
+
*
|
|
122
|
+
* Each cache file is named by a hash over the absolute source paths and
|
|
123
|
+
* transpiled code of its whole relative-`.ts`/`.mts` closure, so editing any
|
|
124
|
+
* file in the graph produces fresh URLs for every importer — a reload never
|
|
125
|
+
* serves stale linked output.
|
|
126
|
+
*
|
|
127
|
+
* Cache lives at `<projectRoot>/.slothlet-cache/<pid>-<instanceID>/<hash>.mjs` —
|
|
128
|
+
* deliberately OUTSIDE `node_modules/` because Node's `READ_PACKAGE_SCOPE` halts
|
|
129
|
+
* at a `node_modules` segment and would otherwise break self-reference resolution
|
|
130
|
+
* (needed when slothlet runs inside its own repo / monorepo workspace, where no
|
|
131
|
+
* `node_modules/@cldmv/slothlet` exists). The `<pid>-` prefix lets the startup
|
|
132
|
+
* sweep detect orphaned dirs (owner PID gone) without touching live ones.
|
|
133
|
+
* @param {string} originalPath - Path to the original .ts/.mts source (relative or absolute; normalized internally)
|
|
134
|
+
* @param {string} code - Transformed JavaScript code for `originalPath`
|
|
135
|
+
* @param {string} instanceID - Slothlet instance ID (used as cache namespace)
|
|
136
|
+
* @param {(filePath: string) => Promise<string>} [transform] - Transpiles a `.ts`/`.mts`
|
|
137
|
+
* file to JavaScript; enables following relative `.ts`/`.mts` imports.
|
|
138
|
+
* @returns {Promise<{url: string, cacheDir: string}>} Entry file URL and the cache directory for this instance
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export function writeTransformedToCache(originalPath: string, code: string, instanceID: string, transform?: (filePath: string) => Promise<string>): Promise<{
|
|
142
|
+
url: string;
|
|
143
|
+
cacheDir: string;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Transform TypeScript code to JavaScript using tsc with type checking
|
|
147
|
+
* @param {string} filePath - Path to the TypeScript file
|
|
148
|
+
* @param {object} [options={}] - TypeScript compiler options
|
|
149
|
+
* @param {string} [options.target] - ECMAScript target version (default: "ES2020")
|
|
150
|
+
* @param {string} [options.module] - Module format (default: "ESNext")
|
|
151
|
+
* @param {boolean} [options.strict] - Enable strict type checking (default: true)
|
|
152
|
+
* @param {boolean} [options.skipTypeCheck] - Skip type checking and only transform (default: false)
|
|
153
|
+
* @param {string} [options.typeDefinitionPath] - Path to .d.ts file for type checking
|
|
154
|
+
* @returns {Promise<{code: string, diagnostics: object[]}>} Transformed code and type diagnostics
|
|
155
|
+
* @throws {SlothletError} If transformation fails
|
|
156
|
+
* @public
|
|
157
|
+
*/
|
|
158
|
+
export function transformTypeScriptStrict(filePath: string, options?: {
|
|
159
|
+
target?: string | undefined;
|
|
160
|
+
module?: string | undefined;
|
|
161
|
+
strict?: boolean | undefined;
|
|
162
|
+
skipTypeCheck?: boolean | undefined;
|
|
163
|
+
typeDefinitionPath?: string | undefined;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
code: string;
|
|
166
|
+
diagnostics: object[];
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Format TypeScript diagnostics into readable error messages
|
|
170
|
+
* @param {object[]} diagnostics - TypeScript diagnostic objects
|
|
171
|
+
* @param {object} ts - TypeScript module instance
|
|
172
|
+
* @returns {string[]} Array of formatted error messages
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export function formatDiagnostics(diagnostics: object[], ts: object): string[];
|