@cldmv/slothlet-types 3.15.3 → 3.16.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 (58) hide show
  1. package/lib/builders/api-assignment.d.mts +125 -4
  2. package/lib/builders/api_builder.d.mts +104 -7
  3. package/lib/builders/builder.d.mts +82 -1
  4. package/lib/builders/modes-processor.d.mts +66 -3
  5. package/lib/errors.d.mts +114 -19
  6. package/lib/factories/component-base.d.mts +171 -8
  7. package/lib/factories/context.d.mts +22 -4
  8. package/lib/handlers/api-cache-manager.d.mts +209 -20
  9. package/lib/handlers/api-manager.d.mts +539 -38
  10. package/lib/handlers/context-async.d.mts +92 -25
  11. package/lib/handlers/context-live.d.mts +117 -30
  12. package/lib/handlers/framework-internals.d.mts +33 -2
  13. package/lib/handlers/hook-manager.d.mts +306 -73
  14. package/lib/handlers/lifecycle-token.d.mts +48 -3
  15. package/lib/handlers/lifecycle.d.mts +86 -5
  16. package/lib/handlers/materialize-manager.d.mts +76 -8
  17. package/lib/handlers/metadata.d.mts +238 -18
  18. package/lib/handlers/module-manager.d.mts +169 -21
  19. package/lib/handlers/ownership.d.mts +376 -45
  20. package/lib/handlers/permission-manager.d.mts +283 -46
  21. package/lib/handlers/routine-manager.d.mts +425 -0
  22. package/lib/handlers/trusted-root.d.mts +45 -4
  23. package/lib/handlers/unified-wrapper.d.mts +287 -26
  24. package/lib/handlers/version-manager.d.mts +236 -29
  25. package/lib/helpers/caller-pinning.d.mts +21 -2
  26. package/lib/helpers/class-instance-wrapper.d.mts +56 -2
  27. package/lib/helpers/config.d.mts +311 -161
  28. package/lib/helpers/defaults.d.mts +39 -0
  29. package/lib/helpers/eventemitter-context.d.mts +29 -3
  30. package/lib/helpers/eventtarget-context.d.mts +19 -1
  31. package/lib/helpers/eventtarget-property-context.d.mts +21 -0
  32. package/lib/helpers/generate-manifest.d.mts +174 -7
  33. package/lib/helpers/hint-detector.d.mts +22 -2
  34. package/lib/helpers/manifest-resolver.d.mts +100 -1
  35. package/lib/helpers/modes-utils.d.mts +30 -3
  36. package/lib/helpers/module-discovery.d.mts +80 -7
  37. package/lib/helpers/module-manifest-validator.d.mts +36 -13
  38. package/lib/helpers/module-sort.d.mts +64 -1
  39. package/lib/helpers/observer-context.d.mts +21 -0
  40. package/lib/helpers/pattern-matcher.d.mts +43 -3
  41. package/lib/helpers/platform.d.mts +109 -10
  42. package/lib/helpers/resolve-from-caller.d.mts +27 -3
  43. package/lib/helpers/sanitize.d.mts +92 -4
  44. package/lib/helpers/scheduler-context.d.mts +21 -1
  45. package/lib/helpers/utilities.d.mts +52 -4
  46. package/lib/i18n/translations.d.mts +50 -5
  47. package/lib/modes/eager.d.mts +46 -8
  48. package/lib/modes/lazy.d.mts +57 -10
  49. package/lib/processors/flatten.d.mts +116 -56
  50. package/lib/processors/loader.d.mts +77 -10
  51. package/lib/processors/type-generator.d.mts +16 -2
  52. package/lib/processors/typescript.d.mts +169 -13
  53. package/lib/runtime/runtime-asynclocalstorage.d.mts +71 -3
  54. package/lib/runtime/runtime-livebindings.d.mts +37 -2
  55. package/lib/runtime/runtime.d.mts +39 -3
  56. package/lib/typegen/typegen.d.mts +34 -2
  57. package/package.json +5 -23
  58. package/slothlet.d.mts +428 -3
@@ -1,62 +1,122 @@
1
+ /**
2
+ * Flattening decision processor
3
+ * @class Flatten
4
+ * @extends ComponentBase
5
+ * @package
6
+ */
1
7
  export class Flatten extends ComponentBase {
2
8
  static slothletProperty: string;
3
- getFlatteningDecision(options: any): Promise<{
4
- preserveAsNamespace: boolean;
5
- reason: any;
6
- flattenToRoot?: undefined;
7
- } | {
8
- flattenToRoot: boolean;
9
- reason: any;
10
- preserveAsNamespace?: undefined;
11
- } | {
12
- flattenToCategory: boolean;
13
- flattenType: string;
14
- reason: any;
15
- useAutoFlattening?: undefined;
16
- preserveAsNamespace?: undefined;
17
- preferredName?: undefined;
18
- } | {
19
- useAutoFlattening: boolean;
20
- reason: any;
21
- flattenToCategory?: undefined;
22
- flattenType?: undefined;
23
- preserveAsNamespace?: undefined;
24
- preferredName?: undefined;
25
- } | {
26
- flattenToCategory: boolean;
27
- reason: any;
28
- flattenType?: undefined;
29
- useAutoFlattening?: undefined;
30
- preserveAsNamespace?: undefined;
31
- preferredName?: undefined;
32
- } | {
33
- preserveAsNamespace: boolean;
34
- preferredName: any;
35
- reason: any;
36
- flattenToCategory?: undefined;
37
- flattenType?: undefined;
38
- useAutoFlattening?: undefined;
39
- }>;
40
- processModuleForAPI(options: any): {
41
- moduleContent: any;
9
+ /**
10
+ * Create a Flatten instance
11
+ * @param {Object} slothlet - Slothlet instance
12
+ */
13
+ constructor(slothlet: Object);
14
+ /**
15
+ * Core flattening decision function.
16
+ * Implements conditions C01-C07 from getFlatteningDecision().
17
+ * @param {object} options - Decision options
18
+ * @param {object} options.mod - Module exports
19
+ * @param {string} options.moduleName - Sanitized module name
20
+ * @param {string} options.categoryName - Category/folder name
21
+ * @param {object} options.analysis - Export analysis
22
+ * @param {boolean} options.hasMultipleDefaults - Multiple defaults in folder
23
+ * @param {string[]} options.moduleKeys - Keys from module
24
+ * @param {function} options.t - Translation function
25
+ * @returns {Promise<object>} Flattening decision
26
+ * @public
27
+ */
28
+ public getFlatteningDecision(options: {
29
+ mod: object;
30
+ moduleName: string;
31
+ categoryName: string;
32
+ analysis: object;
33
+ hasMultipleDefaults: boolean;
34
+ moduleKeys: string[];
35
+ t: Function;
36
+ }): Promise<object>;
37
+ /**
38
+ * Build module content for API assignment.
39
+ *
40
+ * Canonical implementation of the C08-C09b content-building rules, including
41
+ * AddApi detection and collision handling. Previously this logic was inlined
42
+ * inside modes-processor.mjs; it now lives here so the processor stays focused
43
+ * on wrapping and assignment concerns only.
44
+ *
45
+ * Collision config, modesUtils helpers, and SlothletWarning are accessed
46
+ * directly through {@link this.slothlet} / {@link this.slothlet.config} — no caller
47
+ * plumbing required.
48
+ *
49
+ * @param {object} options - Processing options.
50
+ * @param {object} options.mod - Module exports.
51
+ * @param {object} options.decision - Flattening decision from getFlatteningDecision.
52
+ * @param {string} options.moduleName - Sanitized module name (used for C08 auto-flatten key lookup).
53
+ * @param {string} options.propertyName - Resolved preferred name (decision.preferredName || moduleName).
54
+ * @param {string[]} options.moduleKeys - Named export keys (excluding "default").
55
+ * @param {object} options.analysis - { hasDefault, hasNamed, defaultExportType }.
56
+ * @param {object} [options.file=null] - File descriptor for AddApi detection via file.name / file.fullName.
57
+ * @param {string} [options.collisionContext="initial"] - Collision context ("initial" | "api").
58
+ * @param {string} [options.apiPathPrefix=""] - API path prefix for collision error messages.
59
+ * @param {string|null} [options.collisionModeOverride=null] - Caller's per-call override (e.g.
60
+ * `api.add({ forceOverwrite: true })`), preferred over `collisionContext`'s config default for
61
+ * the function-default-vs-named-export merge decision below.
62
+ * @returns {{ moduleContent: object|Function }} Built module content ready for wrapping/assignment.
63
+ * @public
64
+ */
65
+ public processModuleForAPI(options: {
66
+ mod: object;
67
+ decision: object;
68
+ moduleName: string;
69
+ propertyName: string;
70
+ moduleKeys: string[];
71
+ analysis: object;
72
+ file?: object | undefined;
73
+ collisionContext?: string | undefined;
74
+ apiPathPrefix?: string | undefined;
75
+ collisionModeOverride?: string | null | undefined;
76
+ }): {
77
+ moduleContent: object | Function;
42
78
  };
43
- buildCategoryDecisions(options: any): Promise<{
44
- shouldFlatten: boolean;
45
- flattenType: string;
46
- reason: any;
47
- preferredName?: undefined;
48
- } | {
49
- shouldFlatten: boolean;
50
- flattenType: string;
51
- preferredName: any;
52
- reason: any;
53
- } | {
54
- shouldFlatten: boolean;
55
- preferredName: any;
56
- reason: any;
57
- flattenType?: undefined;
58
- }>;
59
- shouldAttachNamedExport(key: any, value: any, defaultFunc: any, originalDefault: any): boolean;
79
+ /**
80
+ * Build category-level flattening decisions.
81
+ * Implements conditions C10-C33 from buildCategoryDecisions().
82
+ * @param {object} options - Category options
83
+ * @param {string} options.categoryName - Category name
84
+ * @param {object} options.mod - Module exports
85
+ * @param {string} options.moduleName - Module name
86
+ * @param {string} options.fileBaseName - File base name
87
+ * @param {object} options.analysis - Export analysis
88
+ * @param {string[]} options.moduleKeys - Module keys
89
+ * @param {number} options.currentDepth - Current depth
90
+ * @param {unknown[]} options.moduleFiles - Files in category
91
+ * @param {function} options.t - Translation function
92
+ * @returns {Promise<object>} Category decision
93
+ * @public
94
+ */
95
+ public buildCategoryDecisions(options: {
96
+ categoryName: string;
97
+ mod: object;
98
+ moduleName: string;
99
+ fileBaseName: string;
100
+ analysis: object;
101
+ moduleKeys: string[];
102
+ currentDepth: number;
103
+ moduleFiles: unknown[];
104
+ t: Function;
105
+ }): Promise<object>;
106
+ /**
107
+ * Decide whether a named export should be attached to a callable default export.
108
+ *
109
+ * Returns false when the named export is the same reference as the default (re-export
110
+ * pattern), or when the export key matches the function name (self-referential export).
111
+ *
112
+ * @param {string} key - Named export key.
113
+ * @param {unknown} value - Named export value.
114
+ * @param {Function} defaultFunc - Wrapped callable default export.
115
+ * @param {Function} originalDefault - Original default export.
116
+ * @returns {boolean} True if the export should be attached.
117
+ * @public
118
+ */
119
+ public shouldAttachNamedExport(key: string, value: unknown, defaultFunc: Function, originalDefault: Function): boolean;
60
120
  #private;
61
121
  }
62
122
  import { ComponentBase } from "#factories/component-base";
@@ -1,15 +1,82 @@
1
+ /**
2
+ * Warns when a coverage run will silently misattribute the consumer's leaf coverage (#235).
3
+ *
4
+ * @param {object} config - The instance's transformed config.
5
+ * @param {object} [overrides] - Environment inputs, injectable for tests.
6
+ * @param {object|undefined} [overrides.worker] - The vitest worker global, when present.
7
+ * @param {boolean} [overrides.externalized] - Whether this slothlet copy is outside the runner's
8
+ * module graph.
9
+ * @returns {boolean} True when the warning was emitted.
10
+ * @package
11
+ *
12
+ * @description
13
+ * Fires only when every condition of the misattribution scenario holds: a vitest COVERAGE run is
14
+ * active (`__vitest_worker__.config.coverage.enabled` — a plain test run stays silent), this
15
+ * slothlet copy is EXTERNALIZED (an inlined copy attributes fine), no `import` importer is
16
+ * configured (the fix), and the instance is not `silent`. The worker global is vitest-internal,
17
+ * so it is read defensively — its absence or a shape change simply means no hint, never a wrong
18
+ * one. Detection cannot DO the fix: the importer must be a closure authored in the consumer's own
19
+ * transformed code, which is why this is a pointer to docs/TESTING.md rather than an auto-enable.
20
+ */
21
+ export function warnIfCoverageWithoutImporter(config: object, { worker, externalized }?: {
22
+ worker?: object | undefined;
23
+ externalized?: boolean | undefined;
24
+ }): boolean;
25
+ /**
26
+ * Loader component for module loading, directory scanning, and API merging
27
+ * @class Loader
28
+ * @extends ComponentBase
29
+ * @package
30
+ */
1
31
  export class Loader extends ComponentBase {
2
32
  static slothletProperty: string;
3
- loadModule(filePath: any, instanceID: any, moduleID: any, cacheBust?: null): Promise<any>;
4
- scanDirectory(dir: any, options?: {}): Promise<{
5
- files: never[];
6
- directories: never[];
7
- }>;
8
- extractExports(module: any): {};
33
+ /**
34
+ * Create a Loader instance.
35
+ * @param {object} slothlet - Slothlet class instance.
36
+ * @package
37
+ */
38
+ constructor(slothlet: object);
39
+ /**
40
+ * Load a single module
41
+ * @param {string} filePath - Path to module file
42
+ * @param {string} [instanceID] - Slothlet instance ID for cache busting
43
+ * @param {string} [moduleID] - Module ID for additional cache busting (used in api.slothlet.api.add)
44
+ * @param {number|null} [cacheBust=null] - Timestamp for reload cache busting (forces fresh import)
45
+ * @returns {Promise<Object>} Loaded module
46
+ * @public
47
+ */
48
+ public loadModule(filePath: string, instanceID?: string, moduleID?: string, cacheBust?: number | null): Promise<Object>;
49
+ /**
50
+ * Scan directory for module files
51
+ * @param {string} dir - Directory to scan
52
+ * @param {Object} [options={}] - Scan options
53
+ * @param {boolean} [options.isRootScan=true] - Whether this is the root directory scan (shows empty dir warning)
54
+ * @param {number} [options.currentDepth=0] - Current traversal depth
55
+ * @param {number} [options.maxDepth=DEFAULT_API_DEPTH] - Maximum traversal depth ({@link DEFAULT_API_DEPTH})
56
+ * @param {Function|null} [options.fileFilter=null] - Optional filter function (fileName) => boolean to load specific files only
57
+ * @param {string|string[]|Function|null} [options.hidden=null] - Glob(s) hiding files/folders, matched against each entry's
58
+ * path relative to the API root (extension-stripped for files). Internal recursion passes the compiled matcher function.
59
+ * @param {boolean} [options.scanHiddenFolders=false] - Deprecated: restore the pre-v3.11 scanning of `.`/`__`-prefixed folders.
60
+ * @param {string} [options.rootDir] - API root the relative hidden-glob paths are computed from (defaults to the scanned dir).
61
+ * @returns {Promise<Object>} Directory structure
62
+ * @public
63
+ */
64
+ public scanDirectory(dir: string, options?: {
65
+ isRootScan?: boolean | undefined;
66
+ currentDepth?: number | undefined;
67
+ maxDepth?: number | undefined;
68
+ fileFilter?: Function | null | undefined;
69
+ hidden?: string | Function | string[] | null | undefined;
70
+ scanHiddenFolders?: boolean | undefined;
71
+ rootDir?: string | undefined;
72
+ }): Promise<Object>;
73
+ /**
74
+ * Extract exports from module
75
+ * @param {Object} module - Loaded module
76
+ * @returns {Object} Extracted exports
77
+ * @public
78
+ */
79
+ public extractExports(module: Object): Object;
9
80
  #private;
10
81
  }
11
- export function warnIfCoverageWithoutImporter(config: any, { worker, externalized }?: {
12
- worker?: any;
13
- externalized?: boolean | undefined;
14
- }): boolean;
15
82
  import { ComponentBase } from "#factories/component-base";
@@ -1,4 +1,18 @@
1
- export function generateTypes(api: any, options: any): Promise<{
1
+ /**
2
+ * Generate TypeScript declaration file for a Slothlet API
3
+ * @param {object} api - The loaded Slothlet API
4
+ * @param {object} options - Generation options
5
+ * @param {string} options.output - Output file path for .d.ts
6
+ * @param {string} options.interfaceName - Name of the interface to generate
7
+ * @param {boolean} [options.includeDocumentation=true] - Include JSDoc comments
8
+ * @returns {Promise<{output: string, filePath: string}>} Generated declaration and output path
9
+ * @public
10
+ */
11
+ export function generateTypes(api: object, options: {
2
12
  output: string;
3
- filePath: any;
13
+ interfaceName: string;
14
+ includeDocumentation?: boolean | undefined;
15
+ }): Promise<{
16
+ output: string;
17
+ filePath: string;
4
18
  }>;
@@ -1,17 +1,173 @@
1
- export function createDataUrl(code: any): string;
2
- export function formatDiagnostics(diagnostics: any, ts: any): any;
3
- export function maskStringsAndComments(code: any): Uint8Array<any>;
4
- export function resolveModuleFile(absoluteTarget: any): {
5
- path: any;
1
+ /**
2
+ * Transform TypeScript code to JavaScript using esbuild
3
+ * @param {string} filePath - Path to the TypeScript file
4
+ * @param {object} [options={}] - esbuild transform options
5
+ * @param {string} [options.target] - ECMAScript target version (default: "es2020")
6
+ * @param {string} [options.format] - Module format (default: "esm")
7
+ * @param {boolean} [options.sourcemap] - Generate source maps (default: false)
8
+ * @returns {Promise<string>} Transformed JavaScript code
9
+ * @throws {SlothletError} If transformation fails
10
+ * @public
11
+ */
12
+ export function transformTypeScript(filePath: string, options?: {
13
+ target?: string | undefined;
14
+ format?: string | undefined;
15
+ sourcemap?: boolean | undefined;
16
+ }): Promise<string>;
17
+ /**
18
+ * Create a data URL for dynamic import with cache busting
19
+ * @param {string} code - JavaScript code to encode
20
+ * @returns {string} Data URL suitable for dynamic import
21
+ * @public
22
+ */
23
+ export function createDataUrl(code: string): string;
24
+ /**
25
+ * Resolve the on-disk file a relative specifier targets and classify it as a
26
+ * TypeScript source or not.
27
+ *
28
+ * Besides the literal path, this probes the TypeScript source-extension
29
+ * convention: a specifier may name a `.mjs` / `.js` file (or omit the
30
+ * extension) while the file on disk is the corresponding `.mts` / `.ts`
31
+ * source. Whichever form exists wins.
32
+ * @param {string} absoluteTarget - Absolute path the specifier resolves to, as written
33
+ * @returns {{ path: string, isTS: boolean }} The resolved file and whether it is a `.ts`/`.mts` source
34
+ * @private
35
+ */
36
+ export function resolveModuleFile(absoluteTarget: string): {
37
+ path: string;
6
38
  isTS: boolean;
7
39
  };
8
- export function rewriteRelativeSpecifiers(code: any, sourcePath: any, resolve: any): any;
9
- export function transformTypeScript(filePath: any, options?: {}): Promise<any>;
10
- export function transformTypeScriptStrict(filePath: any, options?: {}): Promise<{
11
- code: any;
12
- diagnostics: any[];
40
+ /**
41
+ * Mark every character index that falls inside a string literal, template
42
+ * literal, comment, or regular-expression literal, so the specifier rewrite can
43
+ * skip `import`/`from` text that is not actually part of an import statement
44
+ * (e.g. `const s = "import('./x')"`).
45
+ *
46
+ * Template literals are masked whole — opening backtick to closing backtick,
47
+ * including any `${…}` interpolations — so a relative dynamic `import()` inside
48
+ * a template interpolation is left un-rewritten rather than risk a false
49
+ * rewrite; nested template literals are not deeply parsed.
50
+ *
51
+ * Regex literals are masked whole as well: their bodies can contain text shaped
52
+ * like a line- or block-comment delimiter (`/\/\//`), and without regex
53
+ * awareness the scanner would mis-read that as a comment and mask the rest of
54
+ * the line — silently suppressing a real `import()` later on the same line. A
55
+ * `/` is read as a regex when the previous significant token expects an
56
+ * expression (start of input, an operator, `(`/`{`/`}`/`,`/`;`/`:`, or a
57
+ * {@link REGEX_PRECEDING_KEYWORDS} keyword) and as division otherwise. The one
58
+ * imperfect case is a `/` directly after the `)` of an `if`/`for`/`while`
59
+ * header — treated as division — an accepted limit of this lightweight scan.
60
+ * @param {string} code - JavaScript source to scan
61
+ * @returns {Uint8Array} `1` at indices inside a string/template/comment/regex, `0` elsewhere
62
+ * @private
63
+ */
64
+ export function maskStringsAndComments(code: string): Uint8Array;
65
+ /**
66
+ * Rewrite relative `import`/`export` specifiers in transformed TS output.
67
+ *
68
+ * Transformed TS modules are written to (and imported from) a cache file under
69
+ * `.slothlet-cache/…`, which is not co-located with the original source.
70
+ * esbuild and tsc transform the code but never rewrite specifiers, so a
71
+ * relative specifier (`./sibling.mjs`, `../shared/util.mjs`) left as-is would
72
+ * resolve against the cache directory and fail with `Cannot find module`.
73
+ *
74
+ * Each relative specifier is resolved against the original source directory
75
+ * and handed to `resolve`, which returns its replacement. The default `resolve`
76
+ * emits an absolute `file://` URL at the source location — correct for plain
77
+ * `.mjs`/`.cjs`/`.js` targets. {@link writeTransformedToCache} passes a `resolve`
78
+ * that additionally points relative `.ts`/`.mts` targets at their transpiled
79
+ * cache files. Bare specifiers (`@cldmv/slothlet/runtime`, npm packages) and
80
+ * absolute URLs are never touched.
81
+ *
82
+ * Matches inside a string literal or comment are skipped via
83
+ * {@link maskStringsAndComments}, so import-shaped text in string data or
84
+ * comments is never mutated.
85
+ *
86
+ * Covered statement forms: static `import`/`export … from` declarations
87
+ * (including multi-line binding lists and `export *`), bare side-effect
88
+ * `import "…"`, and dynamic `import("…")` with a static string literal.
89
+ * Whitespace and comments between the tokens of these forms — including
90
+ * between `from`/`import` and the module string — are tolerated.
91
+ * @param {string} code - Transformed JavaScript (ESM) code
92
+ * @param {string} sourcePath - Absolute path to the original .ts/.mts source
93
+ * @param {(absoluteTarget: string, suffix: string, specifier: string) => string} [resolve]
94
+ * - Maps a relative specifier to its replacement. Receives the absolute path the
95
+ * specifier resolves to, any `?query`/`#hash` suffix, and the original specifier
96
+ * text. Defaults to an absolute `file://` URL anchored at the source directory.
97
+ * @returns {string} Code with relative specifiers rewritten
98
+ * @private
99
+ */
100
+ export function rewriteRelativeSpecifiers(code: string, sourcePath: string, resolve?: (absoluteTarget: string, suffix: string, specifier: string) => string): string;
101
+ /**
102
+ * Write transformed TS output — and the transitive graph of `.ts`/`.mts` files
103
+ * it relatively imports — to content-hashed cache files inside the project,
104
+ * returning the entry module's `file://` URL.
105
+ *
106
+ * The cache file is not co-located with the source, so every relative specifier
107
+ * is rewritten by {@link rewriteRelativeSpecifiers}:
108
+ *
109
+ * - **Bare specifiers** (`@cldmv/slothlet/runtime`, npm packages) resolve
110
+ * normally — the cache lives inside the project tree, so Node walks up to
111
+ * `node_modules` as usual. They are left untouched.
112
+ * - **Relative imports of plain `.mjs`/`.cjs`/`.js` files** are rewritten to an
113
+ * absolute `file://` URL at the original source location.
114
+ * - **Relative imports of other `.ts`/`.mts` files** are followed: when a
115
+ * `transform` callback is supplied, each dependency is transpiled and cached
116
+ * too, and the importing specifier is rewritten to the dependency's cache
117
+ * file. Import cycles are handled. Without `transform`, a relative `.ts`/`.mts`
118
+ * target is left at its source path (and will not load).
119
+ *
120
+ * Each cache file is named by a hash over the absolute source paths and
121
+ * transpiled code of its whole relative-`.ts`/`.mts` closure, so editing any
122
+ * file in the graph produces fresh URLs for every importer — a reload never
123
+ * serves stale linked output.
124
+ *
125
+ * Cache lives at `<projectRoot>/.slothlet-cache/<pid>-<instanceID>/<hash>.mjs` —
126
+ * deliberately OUTSIDE `node_modules/` because Node's `READ_PACKAGE_SCOPE` halts
127
+ * at a `node_modules` segment and would otherwise break self-reference resolution
128
+ * (needed when slothlet runs inside its own repo / monorepo workspace, where no
129
+ * `node_modules/@cldmv/slothlet` exists). The `<pid>-` prefix lets the startup
130
+ * sweep detect orphaned dirs (owner PID gone) without touching live ones.
131
+ * @param {string} originalPath - Path to the original .ts/.mts source (relative or absolute; normalized internally)
132
+ * @param {string} code - Transformed JavaScript code for `originalPath`
133
+ * @param {string} instanceID - Slothlet instance ID (used as cache namespace)
134
+ * @param {(filePath: string) => Promise<string>} [transform] - Transpiles a `.ts`/`.mts`
135
+ * file to JavaScript; enables following relative `.ts`/`.mts` imports.
136
+ * @returns {Promise<{url: string, cacheDir: string}>} Entry file URL and the cache directory for this instance
137
+ * @public
138
+ */
139
+ export function writeTransformedToCache(originalPath: string, code: string, instanceID: string, transform?: (filePath: string) => Promise<string>): Promise<{
140
+ url: string;
141
+ cacheDir: string;
13
142
  }>;
14
- export function writeTransformedToCache(originalPath: any, code: any, instanceID: any, transform: any): Promise<{
15
- url: any;
16
- cacheDir: any;
143
+ /**
144
+ * Transform TypeScript code to JavaScript using tsc with type checking
145
+ * @param {string} filePath - Path to the TypeScript file
146
+ * @param {object} [options={}] - TypeScript compiler options
147
+ * @param {string} [options.target] - ECMAScript target version (default: "ES2020")
148
+ * @param {string} [options.module] - Module format (default: "ESNext")
149
+ * @param {boolean} [options.strict] - Enable strict type checking (default: true)
150
+ * @param {boolean} [options.skipTypeCheck] - Skip type checking and only transform (default: false)
151
+ * @param {string} [options.typeDefinitionPath] - Path to .d.ts file for type checking
152
+ * @returns {Promise<{code: string, diagnostics: object[]}>} Transformed code and type diagnostics
153
+ * @throws {SlothletError} If transformation fails
154
+ * @public
155
+ */
156
+ export function transformTypeScriptStrict(filePath: string, options?: {
157
+ target?: string | undefined;
158
+ module?: string | undefined;
159
+ strict?: boolean | undefined;
160
+ skipTypeCheck?: boolean | undefined;
161
+ typeDefinitionPath?: string | undefined;
162
+ }): Promise<{
163
+ code: string;
164
+ diagnostics: object[];
17
165
  }>;
166
+ /**
167
+ * Format TypeScript diagnostics into readable error messages
168
+ * @param {object[]} diagnostics - TypeScript diagnostic objects
169
+ * @param {object} ts - TypeScript module instance
170
+ * @returns {string[]} Array of formatted error messages
171
+ * @public
172
+ */
173
+ export function formatDiagnostics(diagnostics: object[], ts: object): string[];
@@ -1,3 +1,71 @@
1
- export const context: {};
2
- export const instanceID: {};
3
- export const self: {};
1
+ /**
2
+ * Live binding to the current API (self-reference)
3
+ * @type {Proxy}
4
+ * @public
5
+ *
6
+ * @description
7
+ * A proxy that provides access to the full API object within the current context.
8
+ * Automatically resolves to the correct instance's API in AsyncLocalStorage context.
9
+ *
10
+ * @example
11
+ * import { self } from "@cldmv/slothlet/runtime/async";
12
+ *
13
+ * export function callOtherFunction() {
14
+ * // Call another function in the same API
15
+ * return self.otherFunction();
16
+ * }
17
+ */
18
+ export const self: ProxyConstructor;
19
+ /**
20
+ * User-provided context object
21
+ * @type {Proxy}
22
+ * @public
23
+ *
24
+ * @description
25
+ * A proxy that provides access to user-provided context data (e.g., request data, user info).
26
+ * Can be set via `slothlet.run()` or `slothlet.scope()`.
27
+ *
28
+ * @example
29
+ * import { context } from "@cldmv/slothlet/runtime/async";
30
+ *
31
+ * export function getUserInfo() {
32
+ * // Access user-provided context
33
+ * return {
34
+ * userId: context.userId,
35
+ * userName: context.userName
36
+ * };
37
+ * }
38
+ */
39
+ export const context: ProxyConstructor;
40
+ /**
41
+ * Reference to initialization reference object
42
+ * @type {Proxy}
43
+ * @public
44
+ *
45
+ * @description
46
+ * The reference object is merged directly into the API at initialization using the add API system.
47
+ * It is NOT available as a runtime export. Access it directly from the API or via api.slothlet.diag.reference().
48
+ *
49
+ * @example
50
+ * // Reference merged into API - access directly:
51
+ * export function useReferenceData() {
52
+ * return self.myData; // if reference had myData property
53
+ * }
54
+ */
55
+ /**
56
+ * Current instance ID
57
+ * @type {Proxy}
58
+ * @public
59
+ *
60
+ * @description
61
+ * A proxy that provides access to the current slothlet instance ID.
62
+ * Useful for debugging and tracking which instance is handling a request.
63
+ *
64
+ * @example
65
+ * import { instanceID } from "@cldmv/slothlet/runtime/async";
66
+ *
67
+ * export function getInstanceInfo() {
68
+ * return { instanceID };
69
+ * }
70
+ */
71
+ export const instanceID: ProxyConstructor;
@@ -1,2 +1,37 @@
1
- export const context: {};
2
- export const self: {};
1
+ /**
2
+ * Live binding to the current API (self-reference)
3
+ * @type {Proxy}
4
+ * @public
5
+ *
6
+ * @description
7
+ * A proxy that provides direct access to the current instance's API.
8
+ * In live mode, this directly references the active instance without AsyncLocalStorage.
9
+ *
10
+ * @example
11
+ * import { self } from "@cldmv/slothlet/runtime/live";
12
+ *
13
+ * export function callOtherFunction() {
14
+ * return self.otherFunction();
15
+ * }
16
+ */
17
+ export const self: ProxyConstructor;
18
+ /**
19
+ * User-provided context object
20
+ * @type {Proxy}
21
+ * @public
22
+ *
23
+ * @description
24
+ * A proxy that provides access to user-provided context data.
25
+ * In live mode, this directly accesses the current instance's context.
26
+ *
27
+ * @example
28
+ * import { context } from "@cldmv/slothlet/runtime/live";
29
+ *
30
+ * export function getUserInfo() {
31
+ * return {
32
+ * userId: context.userId,
33
+ * userName: context.userName
34
+ * };
35
+ * }
36
+ */
37
+ export const context: ProxyConstructor;
@@ -1,3 +1,39 @@
1
- export const context: {};
2
- export const instanceID: {};
3
- export const self: {};
1
+ /**
2
+ * Live binding to the current API instance. Resolves to the running Slothlet proxy,
3
+ * giving API modules access to all other API methods without import cycles.
4
+ *
5
+ * @memberof module:@cldmv/slothlet/runtime
6
+ * @type {object}
7
+ * @example
8
+ * import { self } from "@cldmv/slothlet/runtime";
9
+ * // Inside an API function:
10
+ * const result = await self.math.add(1, 2);
11
+ */
12
+ export const self: object;
13
+ /**
14
+ * The current ambient context object. Seeded at instance startup via `config.context` and
15
+ * persists for the lifetime of the instance. `api.slothlet.context.run()` and `.scope()` can
16
+ * temporarily override it for the duration of a single call, after which the previous context
17
+ * is restored. Readable and writable.
18
+ *
19
+ * @memberof module:@cldmv/slothlet/runtime
20
+ * @type {object}
21
+ * @example
22
+ * import { context } from "@cldmv/slothlet/runtime";
23
+ * // Read the ambient context set via config.context or written by a previous call:
24
+ * const userId = context.userId;
25
+ * // context.run() overrides it only for the duration of that one call:
26
+ * await api.slothlet.context.run({ userId: 42 }, myFn);
27
+ */
28
+ export const context: object;
29
+ /**
30
+ * Current Slothlet instance identifier. Unique per `slothlet()` call; useful when
31
+ * multiple Slothlet instances coexist and you need to identify which one is active.
32
+ *
33
+ * @memberof module:@cldmv/slothlet/runtime
34
+ * @type {string}
35
+ * @example
36
+ * import { instanceID } from "@cldmv/slothlet/runtime";
37
+ * console.log(instanceID); // e.g. "slothlet-1"
38
+ */
39
+ export const instanceID: string;